Added support for binary ingredients over HTTP

print-window-tiddler
Jeremy Ruston 2012-01-13 15:37:58 +00:00
rodzic ecfbaaa564
commit f5c56c066e
4 zmienionych plików z 17 dodań i 4 usunięć

Wyświetl plik

@ -35,6 +35,7 @@ var App = function() {
this.store.registerParser("image/jpg",bitmapParser);
this.store.registerParser("image/jpeg",bitmapParser);
this.store.registerParser("image/png",bitmapParser);
this.store.registerParser("image/gif",bitmapParser);
// Register the standard tiddler serializers and deserializers
tiddlerInput.register(this.store);
tiddlerOutput.register(this.store);

Wyświetl plik

@ -18,12 +18,14 @@ var fs = require("fs"),
var FileRetriever = exports;
FileRetriever.binaryFileExtensions = [".jpg",".jpeg",".png",".gif"];
var fileRequest = function fileRequest(filepath,callback) {
fs.readFile(filepath, function (err,data) {
if(err) {
callback(err);
} else {
if([".jpg",".jpeg",".png"].indexOf(path.extname(filepath)) !== -1) {
if(FileRetriever.binaryFileExtensions.indexOf(path.extname(filepath)) !== -1) {
callback(err,data.toString("base64"));
} else {
callback(err,data.toString("utf8"));
@ -33,8 +35,9 @@ var fileRequest = function fileRequest(filepath,callback) {
};
var httpRequest = function(fileurl,callback) {
var opts = url.parse(fileurl);
var httpLib = opts.protocol === "http:" ? http : https;
var opts = url.parse(fileurl),
httpLib = opts.protocol === "http:" ? http : https,
encoding = (FileRetriever.binaryFileExtensions.indexOf(path.extname(fileurl)) !== -1) ? "binary" : "utf8";
var request = httpLib.get(opts,function(res) {
if(res.statusCode != 200) {
var err = new Error("HTTP error");
@ -42,11 +45,16 @@ var httpRequest = function(fileurl,callback) {
callback(err);
} else {
var data = [];
res.setEncoding(encoding);
res.on("data", function(chunk) {
data.push(chunk);
});
res.on("end", function() {
callback(null,data.join(""));
if(encoding === "binary") {
callback(null,(new Buffer(data.join(""),"binary")).toString("base64"));
} else {
callback(null,data.join(""));
}
});
}
});

Wyświetl plik

@ -3,6 +3,8 @@ modifier: JeremyRuston
Welcome to TiddlyWiki5, an [[in-progress|ThisIsAlpha]] reboot of TiddlyWiki, the reusable non-linear personal web notebook first released in 2004.
<<tiddler [[Motovun Jack.jpg]]>>
Over the years, TiddlyWiki has earned an enduring role as a tool that people [[love using|Raves]] for its rich, interactive interface to [[manipulate complex data|TiddlyWikiConcepts]] with structure that doesn't easily fit into conventional tools like spreadsheets and wordprocessors. Because people can use it without needing any complicated server infrastructure, and because it is [[open source|OpenSourceLicense]], it has bought unprecedented freedom to people to keep their precious information under their own control. TiddlyWiki was originally created by JeremyRuston and is now a thriving [[open source|OpenSourceLicense]] project with a busy [[Community]] of independent developers.
TiddlyWiki5 gains new capabilities through a [[completely rebuilt architecture|TiddlyWikiArchitecture]] using the latest features of HTML5 and node.js. It runs natively under node.js, and can also use its own components to construct a version of itself that works entirely within the browser, just as TiddlyWiki has always done.

Wyświetl plik

@ -5,6 +5,8 @@ style: styles.css
recipe: tiddlers/split.recipe
recipe: ../parsers/split.recipe
tiddler: ../docs/High Level Architecture.svg
tiddler: http://wikitext.tiddlyspace.com/fractalveg.jpg
type: image/jpg
jslib: ../test/tiddlywiki.2.6.5/source/tiddlywiki/jquery/jquery.js