mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-06-06 08:34:08 +00:00
Fix crash loading large files
Attempts to load large files are neutered with a warning message Is 100MB the right limit?
This commit is contained in:
parent
0b3efc2771
commit
55dbce10f4
12
boot/boot.js
12
boot/boot.js
@ -1902,8 +1902,16 @@ $tw.loadTiddlersFromFile = function(filepath,fields) {
|
|||||||
extensionInfo = $tw.utils.getFileExtensionInfo(ext),
|
extensionInfo = $tw.utils.getFileExtensionInfo(ext),
|
||||||
type = extensionInfo ? extensionInfo.type : null,
|
type = extensionInfo ? extensionInfo.type : null,
|
||||||
typeInfo = type ? $tw.config.contentTypeInfo[type] : null,
|
typeInfo = type ? $tw.config.contentTypeInfo[type] : null,
|
||||||
data = fs.readFileSync(filepath,typeInfo ? typeInfo.encoding : "utf8"),
|
fileSize = fs.statSync(filepath).size,
|
||||||
tiddlers = $tw.wiki.deserializeTiddlers(ext,data,fields),
|
data;
|
||||||
|
if(fileSize > $tw.config.maxEditFileSize) {
|
||||||
|
data = "File " + filepath + "not loaded because it is too large";
|
||||||
|
console.log("Warning: " + data);
|
||||||
|
ext = ".txt";
|
||||||
|
} else {
|
||||||
|
data = fs.readFileSync(filepath,typeInfo ? typeInfo.encoding : "utf8");
|
||||||
|
}
|
||||||
|
var tiddlers = $tw.wiki.deserializeTiddlers(ext,data,fields),
|
||||||
metadata = $tw.loadMetadataForFile(filepath);
|
metadata = $tw.loadMetadataForFile(filepath);
|
||||||
if(metadata) {
|
if(metadata) {
|
||||||
if(type === "application/json") {
|
if(type === "application/json") {
|
||||||
|
@ -19,6 +19,10 @@ var _bootprefix = (function($tw) {
|
|||||||
$tw = $tw || Object.create(null);
|
$tw = $tw || Object.create(null);
|
||||||
$tw.boot = $tw.boot || Object.create(null);
|
$tw.boot = $tw.boot || Object.create(null);
|
||||||
|
|
||||||
|
// Config
|
||||||
|
$tw.config = $tw.config || Object.create(null);
|
||||||
|
$tw.config.maxEditFileSize = 100 * 1024 * 1024; // 100MB
|
||||||
|
|
||||||
// Detect platforms
|
// Detect platforms
|
||||||
if(!("browser" in $tw)) {
|
if(!("browser" in $tw)) {
|
||||||
$tw.browser = typeof(window) !== "undefined" && typeof(document) !== "undefined" ? {} : null;
|
$tw.browser = typeof(window) !== "undefined" && typeof(document) !== "undefined" ? {} : null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user