1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-11-23 18:17:20 +00:00

Allow browser-based file reading to use deserializers for binary files

This commit is contained in:
Jermolene 2016-08-20 17:09:22 +01:00
parent 3a2ea9b98b
commit 05b32728bc

View File

@ -1118,29 +1118,24 @@ exports.readFile = function(file,callback) {
var reader = new FileReader();
// Onload
reader.onload = function(event) {
// Deserialise the file contents
var text = event.target.result,
tiddlerFields = {title: file.name || "Untitled", type: type};
// Are we binary?
if(isBinary) {
// The base64 section starts after the first comma in the data URI
var commaPos = text.indexOf(",");
if(commaPos !== -1) {
tiddlerFields.text = text.substr(commaPos+1);
callback([tiddlerFields]);
text = text.substr(commaPos + 1);
}
}
// Check whether this is an encrypted TiddlyWiki file
var encryptedJson = $tw.utils.extractEncryptedStoreArea(text);
if(encryptedJson) {
// If so, attempt to decrypt it with the current password
$tw.utils.decryptStoreAreaInteractive(encryptedJson,function(tiddlers) {
callback(tiddlers);
});
} else {
// Check whether this is an encrypted TiddlyWiki file
var encryptedJson = $tw.utils.extractEncryptedStoreArea(text);
if(encryptedJson) {
// If so, attempt to decrypt it with the current password
$tw.utils.decryptStoreAreaInteractive(encryptedJson,function(tiddlers) {
callback(tiddlers);
});
} else {
// Otherwise, just try to deserialise any tiddlers in the file
callback(self.deserializeTiddlers(type,text,tiddlerFields));
}
// Otherwise, just try to deserialise any tiddlers in the file
callback(self.deserializeTiddlers(type,text,tiddlerFields));
}
};
// Kick off the read
@ -1218,4 +1213,13 @@ exports.invokeUpgraders = function(titles,tiddlers) {
return messages;
};
})();
t++) {
var upgrader = this.upgraderModules[t],
upgraderMessages = upgrader.upgrade(this,titles,tiddlers);
$tw.utils.extend(messages,upgraderMessages);
}
return messages;
};
})();