-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for a serverside tiddler file store
Preparatory to implementing saving changes to the server
- Loading branch information
Jeremy Ruston
committed
Apr 3, 2012
1 parent
f8595c5
commit 0cfef8a
Showing
47 changed files
with
127 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/*\ | ||
title: js/FileStore.js | ||
\*/ | ||
(function(){ | ||
|
||
/*jslint node: true */ | ||
"use strict"; | ||
|
||
var retrieveFile = require("./FileRetriever.js").retrieveFile, | ||
fs = require("fs"), | ||
path = require("path"), | ||
url = require("url"), | ||
util = require("util"), | ||
async = require("async"); | ||
|
||
function FileStore(dirpath,store,callback) { | ||
this.dirpath = dirpath; | ||
this.store = store; | ||
this.callback = callback; | ||
var self = this; | ||
// Set up a queue for loading tiddler files | ||
this.loadQueue = async.queue(function(task,callback) { | ||
retrieveFile(task.filepath,self.dirpath,function(err,data) { | ||
if(err) { | ||
callback(err); | ||
} else { | ||
// Use the filepath as the default title and src for the tiddler | ||
var fields = { | ||
title: data.path, | ||
src: data.path | ||
}; | ||
var tiddlers = self.store.deserializeTiddlers(data.extname,data.text,fields); | ||
// Check for the .meta file | ||
if(data.extname !== ".json" && tiddlers.length === 1) { | ||
var metafile = task.filepath + ".meta"; | ||
retrieveFile(metafile,self.dirpath,function(err,data) { | ||
if(err && err.code !== "ENOENT" && err.code !== "404") { | ||
callback(err); | ||
} else { | ||
var fields = tiddlers[0]; | ||
if(!err) { | ||
var text = data.text.split("\n\n")[0]; | ||
if(text) { | ||
fields = self.store.deserializeTiddlers("application/x-tiddler",text,fields)[0]; | ||
} | ||
} | ||
self.store.addTiddler(fields); | ||
callback(null); | ||
} | ||
}); | ||
} else { | ||
self.store.addTiddlers(tiddlers); | ||
callback(null); | ||
} | ||
} | ||
}); | ||
},10); | ||
// Call the callback when all the files are loaded | ||
this.loadQueue.drain = function() { | ||
callback(null); | ||
}; | ||
// Query the folder content to get all the tiddlers | ||
fs.readdir(this.dirpath,function(err,files) { | ||
if(err) { | ||
callback(err); | ||
} else { | ||
for(var t=0; t<files.length; t++) { | ||
var f = files[t]; | ||
if(f !== ".." && f !== "." && f.indexOf(".meta") !== f.length-5) { | ||
self.loadQueue.push({ | ||
filepath: path.resolve(self.dirpath,f) | ||
}); | ||
} | ||
} | ||
} | ||
}); | ||
} | ||
|
||
exports.FileStore = FileStore; | ||
|
||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
mkdir tmp\tw5 | ||
|
||
node tiddlywiki.js --recipe tiddlywiki5\tiddlywiki5.recipe --savewiki tmp\tw5 --savetiddler ReadMe readme.md | ||
node tiddlywiki.js --recipe tiddlywiki5\tiddlywiki5.recipe --store tiddlywiki5\store --savewiki tmp\tw5 --savetiddler ReadMe readme.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
node tiddlywiki.js --recipe tiddlywiki5\tiddlywiki5.recipe --servewiki 8080 | ||
node tiddlywiki.js --recipe tiddlywiki5\tiddlywiki5.recipe --store tiddlywiki5\store --servewiki 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters