mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-27 03:57:21 +00:00
Include bagname in tiddler Etags
This commit is contained in:
parent
808b94468e
commit
eaebeb87c9
@ -316,7 +316,7 @@ MultiWikiClientAdaptor.prototype.convertTiddlerFromTiddlyWebFormat = function(ti
|
||||
Split an MWS Etag into its constituent parts. For example:
|
||||
|
||||
```
|
||||
"tiddler_id:946151"
|
||||
"tiddler:mybag/946151"
|
||||
```
|
||||
|
||||
Note that the value includes the opening and closing double quotes.
|
||||
@ -324,16 +324,25 @@ Note that the value includes the opening and closing double quotes.
|
||||
The parts are:
|
||||
|
||||
```
|
||||
tiddler_id:<revision>
|
||||
"tiddler:<bag>/<revision>"
|
||||
```
|
||||
*/
|
||||
MultiWikiClientAdaptor.prototype.parseEtag = function(etag) {
|
||||
const PREFIX = "\"tiddler_id:";
|
||||
if(!etag.startsWith(PREFIX)) {
|
||||
return null;
|
||||
const PREFIX = "\"tiddler:";
|
||||
if(etag.startsWith(PREFIX)) {
|
||||
const slashPos = etag.indexOf("/");
|
||||
if(slashPos !== -1) {
|
||||
const bag_name = etag.slice(PREFIX.length,slashPos),
|
||||
revision = parseInt(etag.slice(slashPos + 1),10);
|
||||
if(!isNaN(revision)) {
|
||||
return {
|
||||
bag_name: bag_name,
|
||||
revision: revision
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
const revision = parseInt(etag.slice(PREFIX.length),10);
|
||||
return isNaN(revision) ? null : revision;
|
||||
return null;
|
||||
};
|
||||
|
||||
if($tw.browser && document.location.protocol.substr(0,4) === "http" ) {
|
||||
|
@ -264,6 +264,19 @@ function streamMultipartData(request,options) {
|
||||
});
|
||||
}
|
||||
|
||||
/*
|
||||
Make an etag. Options include:
|
||||
bag_name:
|
||||
tiddler_id:
|
||||
*/
|
||||
function makeTiddlerEtag(options) {
|
||||
if(options.bag_name || options.tiddler_id) {
|
||||
return "\"tiddler:" + options.bag_name + "/" + options.tiddler_id + "\"";
|
||||
} else {
|
||||
throw "Missing bag_name or tiddler_id";
|
||||
}
|
||||
}
|
||||
|
||||
Server.prototype.defaultVariables = {
|
||||
port: "8080",
|
||||
host: "127.0.0.1",
|
||||
@ -360,6 +373,7 @@ Server.prototype.requestHandler = function(request,response,options) {
|
||||
state.sendResponse = sendResponse.bind(self,request,response);
|
||||
state.redirect = redirect.bind(self,request,response);
|
||||
state.streamMultipartData = streamMultipartData.bind(self,request);
|
||||
state.makeTiddlerEtag = makeTiddlerEtag.bind(self);
|
||||
// Get the principals authorized to access this resource
|
||||
state.authorizationType = options.authorizationType || this.methodMappings[request.method] || "readers";
|
||||
// Check whether anonymous access is granted
|
||||
|
@ -23,7 +23,7 @@ exports.handler = function(request,response,state) {
|
||||
if(bag_name) {
|
||||
var result = $tw.mws.store.deleteTiddler(title,bag_name);
|
||||
response.writeHead(204, "OK", {
|
||||
Etag: "\"tiddler_id:" + result.tiddler_id + "\"",
|
||||
Etag: state.makeTiddlerEtag(result),
|
||||
"Content-Type": "text/plain"
|
||||
});
|
||||
response.end();
|
||||
|
@ -24,7 +24,7 @@ exports.handler = function(request,response,state) {
|
||||
const result = $tw.mws.store.getBagTiddlerStream(title,bag_name);
|
||||
if(result) {
|
||||
response.writeHead(200, "OK",{
|
||||
Etag: "\"tiddler_id:" + result.tiddler_id + "\"",
|
||||
Etag: state.makeTiddlerEtag(result),
|
||||
"Content-Type": result.type,
|
||||
});
|
||||
result.stream.pipe(response);
|
||||
|
@ -42,7 +42,7 @@ exports.handler = function(request,response,state) {
|
||||
});
|
||||
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
||||
state.sendResponse(200,{
|
||||
Etag: "\"tiddler_id:" + tiddlerInfo.tiddler_id + "\"",
|
||||
Etag: state.makeTiddlerEtag(tiddlerInfo),
|
||||
"Content-Type": "application/json"
|
||||
},JSON.stringify(tiddlerFields),"utf8");
|
||||
return;
|
||||
@ -51,7 +51,7 @@ exports.handler = function(request,response,state) {
|
||||
const result = $tw.mws.store.getBagTiddlerStream(title,bag_name);
|
||||
if(result) {
|
||||
response.writeHead(200, "OK",{
|
||||
Etag: "\"tiddler_id:" + result.tiddler_id + "\"",
|
||||
Etag: state.makeTiddlerEtag(result),
|
||||
"Content-Type": result.type
|
||||
});
|
||||
result.stream.pipe(response);
|
||||
|
@ -42,7 +42,7 @@ exports.handler = function(request,response,state) {
|
||||
});
|
||||
tiddlerFields.type = tiddlerFields.type || "text/vnd.tiddlywiki";
|
||||
state.sendResponse(200,{
|
||||
Etag: "\"tiddler_id:" + tiddlerInfo.tiddler_id + "\"",
|
||||
Etag: state.makeTiddlerEtag(tiddlerInfo),
|
||||
"Content-Type": "application/json"
|
||||
},JSON.stringify(tiddlerFields),"utf8");
|
||||
return;
|
||||
@ -50,7 +50,7 @@ exports.handler = function(request,response,state) {
|
||||
// This is not a JSON API request, we should return the raw tiddler content
|
||||
var type = tiddlerInfo.tiddler.type || "text/plain";
|
||||
response.writeHead(200, "OK",{
|
||||
Etag: "\"tiddler_id:" + tiddlerInfo.tiddler_id + "\"",
|
||||
Etag: state.makeTiddlerEtag(tiddlerInfo),
|
||||
"Content-Type": type
|
||||
});
|
||||
response.write(tiddlerInfo.tiddler.text || "",($tw.config.contentTypeInfo[type] ||{encoding: "utf8"}).encoding);
|
||||
|
@ -38,7 +38,7 @@ exports.handler = function(request,response,state) {
|
||||
var result = $tw.mws.store.saveRecipeTiddler(fields,recipe_name);
|
||||
if(result) {
|
||||
response.writeHead(204, "OK",{
|
||||
Etag: "\"tiddler_id:" + result.tiddler_id + "\"",
|
||||
Etag: state.makeTiddlerEtag(result),
|
||||
"Content-Type": "text/plain"
|
||||
});
|
||||
} else {
|
||||
|
@ -244,7 +244,7 @@ Get an attachment ready to stream. Returns null if there is an error or:
|
||||
tiddler_id: revision of tiddler
|
||||
stream: stream of file
|
||||
type: type of file
|
||||
Returns {tiddler_id:}
|
||||
Returns {tiddler_id:,bag_name:}
|
||||
*/
|
||||
SqlTiddlerStore.prototype.getBagTiddlerStream = function(title,bag_name) {
|
||||
const tiddlerInfo = this.sqlTiddlerDatabase.getBagTiddler(title,bag_name);
|
||||
@ -253,7 +253,10 @@ SqlTiddlerStore.prototype.getBagTiddlerStream = function(title,bag_name) {
|
||||
return $tw.utils.extend(
|
||||
{},
|
||||
this.attachmentStore.getAttachmentStream(tiddlerInfo.attachment_blob),
|
||||
{tiddler_id: tiddlerInfo.tiddler_id});
|
||||
{
|
||||
tiddler_id: tiddlerInfo.tiddler_id
|
||||
}
|
||||
);
|
||||
} else {
|
||||
const { Readable } = require('stream');
|
||||
const stream = new Readable();
|
||||
@ -266,6 +269,7 @@ SqlTiddlerStore.prototype.getBagTiddlerStream = function(title,bag_name) {
|
||||
};
|
||||
return {
|
||||
tiddler_id: tiddlerInfo.tiddler_id,
|
||||
bag_name: bag_name,
|
||||
stream: stream,
|
||||
type: tiddlerInfo.tiddler.type || "text/plain"
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user