mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 12:07:19 +00:00
Fix canonical URI handling
This commit is contained in:
parent
84c8a9be9b
commit
41a5bcc3a1
@ -40,6 +40,7 @@ exports.handler = function(request,response,state) {
|
||||
}
|
||||
});
|
||||
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
||||
tiddlerFields = $tw.sqlTiddlerStore.processCanonicalUriTiddler(tiddlerFields,bag_name,null);
|
||||
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(tiddlerFields),"utf8");
|
||||
} else {
|
||||
// This is not a JSON API request, we should return the raw tiddler content
|
||||
|
@ -40,6 +40,7 @@ exports.handler = function(request,response,state) {
|
||||
}
|
||||
});
|
||||
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
||||
tiddlerFields = $tw.sqlTiddlerStore.processCanonicalUriTiddler(tiddlerFields,null,recipe_name);
|
||||
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(tiddlerFields),"utf8");
|
||||
} else {
|
||||
// This is not a JSON API request, we should return the raw tiddler content
|
||||
|
@ -50,8 +50,13 @@ exports.handler = function(request,response,state) {
|
||||
}
|
||||
response.write(template.substring(0,markerPos + marker.length));
|
||||
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
|
||||
response.write(JSON.stringify($tw.sqlTiddlerStore.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name).tiddler).replace(/</g,"\\u003c"));
|
||||
response.write(",\n")
|
||||
var result = $tw.sqlTiddlerStore.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name);
|
||||
if(result) {
|
||||
var tiddlerFields = result.tiddler;
|
||||
tiddlerFields = $tw.sqlTiddlerStore.processCanonicalUriTiddler(tiddlerFields,null,recipe_name);
|
||||
response.write(JSON.stringify(tiddlerFields).replace(/</g,"\\u003c"));
|
||||
response.write(",\n")
|
||||
}
|
||||
});
|
||||
response.write(JSON.stringify({title: "$:/config/tiddlyweb/host",text: "$protocol$//$host$$pathname$/"}));
|
||||
response.write(",\n")
|
||||
|
@ -105,25 +105,30 @@ SqlTiddlerStore.prototype.updateAdminWiki = function() {
|
||||
|
||||
/*
|
||||
Given tiddler fields, tiddler_id and a bagname, return the tiddler fields after the following process:
|
||||
- If the text field is over a threshold, modify the tiddler to use _canonical_uri
|
||||
- Apply the tiddler_id as the revision field
|
||||
- Apply the bag_name as the bag field
|
||||
*/
|
||||
SqlTiddlerStore.prototype.processOutgoingTiddler = function(tiddlerFields,tiddler_id,bag_name,recipe_name) {
|
||||
SqlTiddlerStore.prototype.processOutgoingTiddler = function(tiddlerFields,tiddler_id,bag_name) {
|
||||
return Object.assign({},tiddlerFields,{
|
||||
revision: "" + tiddler_id,
|
||||
bag: bag_name
|
||||
});
|
||||
};
|
||||
|
||||
/*
|
||||
Given tiddler fields and a bagname or a recipename, if the text field is over a threshold, modify
|
||||
the tiddler to use _canonical_uri, otherwise return the tiddler unmodified
|
||||
*/
|
||||
SqlTiddlerStore.prototype.processCanonicalUriTiddler = function(tiddlerFields,bag_name,recipe_name) {
|
||||
if((tiddlerFields.text || "").length > 10 * 1024 * 1024) {
|
||||
return Object.assign({},tiddlerFields,{
|
||||
revision: "" + tiddler_id,
|
||||
bag: bag_name,
|
||||
text: undefined,
|
||||
_canonical_uri: recipe_name
|
||||
? `/wiki/${recipe_name}/recipes/${recipe_name}/tiddlers/${tiddlerFields.title}`
|
||||
: `/wiki/${bag_name}/bags/${bag_name}/tiddlers/${tiddlerFields.title}`
|
||||
});
|
||||
} else {
|
||||
return Object.assign({},tiddlerFields,{
|
||||
revision: "" + tiddler_id,
|
||||
bag: bag_name
|
||||
});
|
||||
return tiddlerFields;
|
||||
}
|
||||
};
|
||||
|
||||
@ -229,7 +234,7 @@ SqlTiddlerStore.prototype.getBagTiddler = function(title,bagname) {
|
||||
{},
|
||||
tiddlerInfo,
|
||||
{
|
||||
tiddler: this.processOutgoingTiddler(tiddlerInfo.tiddler,tiddlerInfo.tiddler_id,bagname,null)
|
||||
tiddler: this.processOutgoingTiddler(tiddlerInfo.tiddler,tiddlerInfo.tiddler_id,bagname)
|
||||
});
|
||||
} else {
|
||||
return null;
|
||||
@ -246,7 +251,7 @@ SqlTiddlerStore.prototype.getRecipeTiddler = function(title,recipename) {
|
||||
{},
|
||||
tiddlerInfo,
|
||||
{
|
||||
tiddler: this.processOutgoingTiddler(tiddlerInfo.tiddler,tiddlerInfo.tiddler_id,tiddlerInfo.bag_name,recipename)
|
||||
tiddler: this.processOutgoingTiddler(tiddlerInfo.tiddler,tiddlerInfo.tiddler_id,tiddlerInfo.bag_name)
|
||||
});
|
||||
} else {
|
||||
return null;
|
||||
|
Loading…
Reference in New Issue
Block a user