Compare commits
8 Commits
81aa5a39ba
...
461838383b
Author | SHA1 | Date |
---|---|---|
Saq Imtiaz | 461838383b | |
Matt Lauber | a081e58273 | |
Joshua Fontany | 5f74f4c2fa | |
Joshua Fontany | 9167b190d2 | |
Cameron Fischer | df8731f760 | |
saqimtiaz | a38e0b883d | |
saqimtiaz | f7a54419a1 | |
saqimtiaz | 42ffa51daf |
|
@ -43,7 +43,9 @@ Saves individual tiddlers in their raw text or binary format to the specified fi
|
|||
directory: path.resolve(self.commander.outputPath),
|
||||
pathFilters: [filenameFilter],
|
||||
wiki: wiki,
|
||||
fileInfo: {}
|
||||
fileInfo: {
|
||||
overwrite: true
|
||||
}
|
||||
});
|
||||
if(self.commander.verbose) {
|
||||
console.log("Saving \"" + title + "\" to \"" + fileInfo.filepath + "\"");
|
||||
|
|
|
@ -113,6 +113,9 @@ function SaverHandler(options) {
|
|||
|
||||
SaverHandler.prototype.titleSyncFilter = "$:/config/SaverFilter";
|
||||
SaverHandler.prototype.titleAutoSave = "$:/config/AutoSave";
|
||||
SaverHandler.prototype.titleThrottleAutoSave = "$:/config/AutoSave/Throttle";
|
||||
SaverHandler.prototype.titleAutoSaveThrottleInterval = "$:/config/AutoSave/ThrottleInterval";
|
||||
SaverHandler.prototype.autoSaveThrottleInterval = 60000; //Defer saving for 60s after an AutoSave
|
||||
SaverHandler.prototype.titleSavedNotification = "$:/language/Notifications/Save/Done";
|
||||
|
||||
/*
|
||||
|
@ -142,6 +145,21 @@ SaverHandler.prototype.initSavers = function(moduleType) {
|
|||
});
|
||||
};
|
||||
|
||||
SaverHandler.prototype.getAutoSaveThrottleInterval = function() {
|
||||
return parseInt(this.wiki.getTiddlerText(this.titleAutoSaveThrottleInterval,this.autoSaveThrottleInterval),10);
|
||||
};
|
||||
|
||||
SaverHandler.prototype.queueAutoSave = function(options) {
|
||||
var self = this;
|
||||
if(this.autoSaveTimerId) {
|
||||
return;
|
||||
}
|
||||
this.autoSaveTimerId = setTimeout(function() {
|
||||
self.autoSaveTimerId = null;
|
||||
self.saveWiki(options);
|
||||
},self.getAutoSaveThrottleInterval());
|
||||
};
|
||||
|
||||
/*
|
||||
Save the wiki contents. Options are:
|
||||
method: "save", "autosave" or "download"
|
||||
|
@ -151,14 +169,29 @@ Save the wiki contents. Options are:
|
|||
SaverHandler.prototype.saveWiki = function(options) {
|
||||
options = options || {};
|
||||
var self = this,
|
||||
method = options.method || "save";
|
||||
method = options.method || "save",
|
||||
now = new Date().getTime();
|
||||
// Ignore autosave if disabled
|
||||
if(method === "autosave" && ($tw.config.disableAutoSave || this.wiki.getTiddlerText(this.titleAutoSave,"yes") !== "yes")) {
|
||||
return false;
|
||||
if(method === "autosave") {
|
||||
if($tw.config.disableAutoSave || this.wiki.getTiddlerText(this.titleAutoSave,"yes") !== "yes") {
|
||||
return false;
|
||||
}
|
||||
if(this.wiki.getTiddlerText(this.titleThrottleAutoSave,"no") === "yes" && (now - this.autoSaveThrottleInterval <= this.timestampLastAutoSave)) {
|
||||
this.logger.log("Queueing autosave");
|
||||
this.queueAutoSave(options);
|
||||
return false;
|
||||
} else {
|
||||
this.timestampLastAutoSave = now;
|
||||
}
|
||||
} else if(method === "save" && this.autoSaveTimerId) {
|
||||
// Clear the queue of any pending autosave
|
||||
// TODO: brittle if save fails, but resetting in the save callback risks clearing an AutoSave that was queued after the save was initiated
|
||||
this.logger.log("Clearing autosave queue");
|
||||
clearTimeout(this.autoSaveTimerId);
|
||||
}
|
||||
var variables = options.variables || {},
|
||||
template = (options.template ||
|
||||
this.wiki.getTiddlerText("$:/config/SaveWikiButton/Template","$:/core/save/all")).trim(),
|
||||
this.wiki.getTiddlerText("$:/config/SaveWikiButton/Template","$:/core/save/all")).trim(),
|
||||
downloadType = options.downloadType || "text/plain",
|
||||
text = this.wiki.renderTiddler(downloadType,template,options),
|
||||
callback = function(err) {
|
||||
|
@ -209,4 +242,4 @@ SaverHandler.prototype.updateDirtyStatus = function() {
|
|||
|
||||
exports.SaverHandler = SaverHandler;
|
||||
|
||||
})();
|
||||
})();
|
|
@ -140,6 +140,11 @@ function sendResponse(request,response,statusCode,headers,data,encoding) {
|
|||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// RFC 7231, 6.1. Overview of Status Codes:
|
||||
// Browser clients may cache 200, 203, 204, 206, 300, 301,
|
||||
// 404, 405, 410, 414, and 501 unless given explicit cache controls
|
||||
headers["Cache-Control"] = headers["Cache-Control"] || "no-store";
|
||||
}
|
||||
/*
|
||||
If the gzip=yes is set, check if the user agent permits compression. If so,
|
||||
|
|
|
@ -283,7 +283,7 @@ exports.httpRequest = function(options) {
|
|||
// Set up the state change handler
|
||||
request.onreadystatechange = function() {
|
||||
if(this.readyState === 4) {
|
||||
if(this.status === 200 || this.status === 201 || this.status === 204) {
|
||||
if(this.status >= 200 && this.status < 300) {
|
||||
// Success!
|
||||
options.callback(null,this[returnProp],this);
|
||||
return;
|
||||
|
|
|
@ -316,11 +316,13 @@ Options include:
|
|||
pathFilters: optional array of filters to be used to generate the base path
|
||||
wiki: optional wiki for evaluating the pathFilters
|
||||
fileInfo: an existing fileInfo object to check against
|
||||
fileInfo.overwrite: if true, turns off filename clash numbers (defaults to false)
|
||||
*/
|
||||
exports.generateTiddlerFilepath = function(title,options) {
|
||||
var directory = options.directory || "",
|
||||
extension = options.extension || "",
|
||||
originalpath = (options.fileInfo && options.fileInfo.originalpath) ? options.fileInfo.originalpath : "",
|
||||
overwrite = options.fileInfo && options.fileInfo.overwrite || false,
|
||||
filepath;
|
||||
// Check if any of the pathFilters applies
|
||||
if(options.pathFilters && options.wiki) {
|
||||
|
@ -381,19 +383,20 @@ exports.generateTiddlerFilepath = function(title,options) {
|
|||
filepath += char.charCodeAt(0).toString();
|
||||
});
|
||||
}
|
||||
// Add a uniquifier if the file already exists
|
||||
var fullPath, oldPath = (options.fileInfo) ? options.fileInfo.filepath : undefined,
|
||||
// Add a uniquifier if the file already exists (default)
|
||||
var fullPath = path.resolve(directory, filepath + extension);
|
||||
if (!overwrite) {
|
||||
var oldPath = (options.fileInfo) ? options.fileInfo.filepath : undefined,
|
||||
count = 0;
|
||||
do {
|
||||
fullPath = path.resolve(directory,filepath + (count ? "_" + count : "") + extension);
|
||||
if(oldPath && oldPath == fullPath) {
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
} while(fs.existsSync(fullPath));
|
||||
do {
|
||||
fullPath = path.resolve(directory,filepath + (count ? "_" + count : "") + extension);
|
||||
if(oldPath && oldPath == fullPath) break;
|
||||
count++;
|
||||
} while(fs.existsSync(fullPath));
|
||||
}
|
||||
// If the last write failed with an error, or if path does not start with:
|
||||
// the resolved options.directory, the resolved wikiPath directory, the wikiTiddlersPath directory,
|
||||
// or the 'originalpath' directory, then $tw.utils.encodeURIComponentExtended() and resolve to tiddler directory.
|
||||
// or the 'originalpath' directory, then $tw.utils.encodeURIComponentExtended() and resolve to options.directory.
|
||||
var writePath = $tw.hooks.invokeHook("th-make-tiddler-path",fullPath,fullPath),
|
||||
encode = (options.fileInfo || {writeError: false}).writeError == true;
|
||||
if(!encode) {
|
||||
|
|
|
@ -3,7 +3,7 @@ title: $:/core/save/all-external-js
|
|||
\whitespace trim
|
||||
\import [subfilter{$:/core/config/GlobalImportFilter}]
|
||||
\define saveTiddlerFilter()
|
||||
[is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[[$:/core]] -[[$:/boot/boot.css]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$
|
||||
[is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[[$:/core]] -[[$:/boot/boot.css]] -[is[system]type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$
|
||||
\end
|
||||
|
||||
<!-- Important: core library is provided by serving URI encoded $:/core/templates/tiddlywiki5.js -->
|
||||
|
|
|
@ -3,7 +3,7 @@ title: $:/core/save/offline-external-js
|
|||
\whitespace trim
|
||||
\import [subfilter{$:/core/config/GlobalImportFilter}]
|
||||
\define saveTiddlerFilter()
|
||||
[is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[[$:/core]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/tiddlywiki/tiddlyweb]] -[[$:/boot/boot.css]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$
|
||||
[is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[[$:/core]] -[[$:/plugins/tiddlywiki/filesystem]] -[[$:/plugins/tiddlywiki/tiddlyweb]] -[[$:/boot/boot.css]] -[is[system]type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$
|
||||
\end
|
||||
\define defaultCoreURL() tiddlywikicore-$(version)$.js
|
||||
<$let coreURL={{{ [[coreURL]is[variable]then<coreURL>else<defaultCoreURL>] }}}>
|
||||
|
|
|
@ -2,6 +2,6 @@ title: $:/core/save/all
|
|||
|
||||
\import [subfilter{$:/core/config/GlobalImportFilter}]
|
||||
\define saveTiddlerFilter()
|
||||
[is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[[$:/boot/boot.css]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$
|
||||
[is[tiddler]] -[prefix[$:/state/popup/]] -[prefix[$:/temp/]] -[prefix[$:/HistoryList]] -[status[pending]plugin-type[import]] -[[$:/boot/boot.css]] -[is[system]type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]] $(publishFilter)$
|
||||
\end
|
||||
{{$:/core/templates/tiddlywiki5.html}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
title: $:/core/save/empty
|
||||
|
||||
\define saveTiddlerFilter()
|
||||
[is[system]] -[prefix[$:/state/popup/]] -[[$:/boot/boot.css]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]]
|
||||
[is[system]] -[prefix[$:/state/popup/]] -[[$:/boot/boot.css]] -[is[system]type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] +[sort[title]]
|
||||
\end
|
||||
{{$:/core/templates/tiddlywiki5.html}}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
title: $:/core/save/lazy-all
|
||||
|
||||
\define saveTiddlerFilter()
|
||||
[is[system]] -[prefix[$:/state/popup/]] -[[$:/HistoryList]] -[[$:/boot/boot.css]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] [is[tiddler]type[application/javascript]] +[sort[title]]
|
||||
[is[system]] -[prefix[$:/state/popup/]] -[[$:/HistoryList]] -[[$:/boot/boot.css]] -[is[system]type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] [is[tiddler]type[application/javascript]] +[sort[title]]
|
||||
\end
|
||||
\define skinnySaveTiddlerFilter()
|
||||
[!is[system]] -[type[application/javascript]]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
title: $:/core/save/lazy-images
|
||||
|
||||
\define saveTiddlerFilter()
|
||||
[is[tiddler]] -[prefix[$:/state/popup/]] -[[$:/HistoryList]] -[[$:/boot/boot.css]] -[type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] -[!is[system]is[image]] +[sort[title]]
|
||||
[is[tiddler]] -[prefix[$:/state/popup/]] -[[$:/HistoryList]] -[[$:/boot/boot.css]] -[is[system]type[application/javascript]library[yes]] -[[$:/boot/boot.js]] -[[$:/boot/bootprefix.js]] -[!is[system]is[image]] +[sort[title]]
|
||||
\end
|
||||
\define skinnySaveTiddlerFilter()
|
||||
[!is[system]is[image]]
|
||||
|
|
Loading…
Reference in New Issue