mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-30 13:29:56 +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.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");
|
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(tiddlerFields),"utf8");
|
||||||
} else {
|
} else {
|
||||||
// This is not a JSON API request, we should return the raw tiddler content
|
// 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.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");
|
state.sendResponse(200,{"Content-Type": "application/json"},JSON.stringify(tiddlerFields),"utf8");
|
||||||
} else {
|
} else {
|
||||||
// This is not a JSON API request, we should return the raw tiddler content
|
// 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));
|
response.write(template.substring(0,markerPos + marker.length));
|
||||||
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
|
$tw.utils.each(recipeTiddlers,function(recipeTiddlerInfo) {
|
||||||
response.write(JSON.stringify($tw.sqlTiddlerStore.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name).tiddler).replace(/</g,"\\u003c"));
|
var result = $tw.sqlTiddlerStore.getRecipeTiddler(recipeTiddlerInfo.title,recipe_name);
|
||||||
response.write(",\n")
|
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(JSON.stringify({title: "$:/config/tiddlyweb/host",text: "$protocol$//$host$$pathname$/"}));
|
||||||
response.write(",\n")
|
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:
|
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 tiddler_id as the revision field
|
||||||
- Apply the bag_name as the bag 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) {
|
if((tiddlerFields.text || "").length > 10 * 1024 * 1024) {
|
||||||
return Object.assign({},tiddlerFields,{
|
return Object.assign({},tiddlerFields,{
|
||||||
revision: "" + tiddler_id,
|
|
||||||
bag: bag_name,
|
|
||||||
text: undefined,
|
text: undefined,
|
||||||
_canonical_uri: recipe_name
|
_canonical_uri: recipe_name
|
||||||
? `/wiki/${recipe_name}/recipes/${recipe_name}/tiddlers/${tiddlerFields.title}`
|
? `/wiki/${recipe_name}/recipes/${recipe_name}/tiddlers/${tiddlerFields.title}`
|
||||||
: `/wiki/${bag_name}/bags/${bag_name}/tiddlers/${tiddlerFields.title}`
|
: `/wiki/${bag_name}/bags/${bag_name}/tiddlers/${tiddlerFields.title}`
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return Object.assign({},tiddlerFields,{
|
return tiddlerFields;
|
||||||
revision: "" + tiddler_id,
|
|
||||||
bag: bag_name
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -229,7 +234,7 @@ SqlTiddlerStore.prototype.getBagTiddler = function(title,bagname) {
|
|||||||
{},
|
{},
|
||||||
tiddlerInfo,
|
tiddlerInfo,
|
||||||
{
|
{
|
||||||
tiddler: this.processOutgoingTiddler(tiddlerInfo.tiddler,tiddlerInfo.tiddler_id,bagname,null)
|
tiddler: this.processOutgoingTiddler(tiddlerInfo.tiddler,tiddlerInfo.tiddler_id,bagname)
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
@ -246,7 +251,7 @@ SqlTiddlerStore.prototype.getRecipeTiddler = function(title,recipename) {
|
|||||||
{},
|
{},
|
||||||
tiddlerInfo,
|
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 {
|
} else {
|
||||||
return null;
|
return null;
|
||||||
|
Loading…
Reference in New Issue
Block a user