forked from cory/tildefriends
Store app blob history.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4484 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
parent
cda724b2da
commit
6302565942
25
core/core.js
25
core/core.js
@ -735,7 +735,6 @@ async function blobHandler(request, response, blobId, uri) {
|
|||||||
} else if (uri == "/save") {
|
} else if (uri == "/save") {
|
||||||
let match;
|
let match;
|
||||||
if (match = /^\/\~(\w+)\/(\w+)$/.exec(blobId)) {
|
if (match = /^\/\~(\w+)\/(\w+)$/.exec(blobId)) {
|
||||||
let newBlobId = await ssb.blobStore(request.body);
|
|
||||||
let user = match[1];
|
let user = match[1];
|
||||||
let appName = match[2];
|
let appName = match[2];
|
||||||
let credentials = auth.query(request.headers);
|
let credentials = auth.query(request.headers);
|
||||||
@ -743,6 +742,25 @@ async function blobHandler(request, response, blobId, uri) {
|
|||||||
(credentials.session.name == user ||
|
(credentials.session.name == user ||
|
||||||
(credentials.permissions.administration && user == 'core'))) {
|
(credentials.permissions.administration && user == 'core'))) {
|
||||||
let database = new Database(user);
|
let database = new Database(user);
|
||||||
|
|
||||||
|
let app_object = JSON.parse(utf8Decode(request.body));
|
||||||
|
let previous_id = database.get('path:' + appName);
|
||||||
|
if (previous_id) {
|
||||||
|
try {
|
||||||
|
let previous_object = JSON.parse(utf8Decode(await ssb.blobGet(previous_id)));
|
||||||
|
delete previous_object.previous;
|
||||||
|
delete app_object.previous;
|
||||||
|
if (JSON.stringify(previous_object) == JSON.stringify(app_object)) {
|
||||||
|
response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});
|
||||||
|
response.end("/" + previous_id);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app_object.previous = previous_id;
|
||||||
|
let newBlobId = await ssb.blobStore(JSON.stringify(app_object));
|
||||||
|
|
||||||
let apps = new Set();
|
let apps = new Set();
|
||||||
let apps_original = database.get('apps');
|
let apps_original = database.get('apps');
|
||||||
try {
|
try {
|
||||||
@ -757,14 +775,13 @@ async function blobHandler(request, response, blobId, uri) {
|
|||||||
database.set('apps', apps);
|
database.set('apps', apps);
|
||||||
}
|
}
|
||||||
database.set('path:' + appName, newBlobId);
|
database.set('path:' + appName, newBlobId);
|
||||||
|
response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});
|
||||||
|
response.end("/" + newBlobId);
|
||||||
} else {
|
} else {
|
||||||
response.writeHead(401, {"Content-Type": "text/plain; charset=utf-8"});
|
response.writeHead(401, {"Content-Type": "text/plain; charset=utf-8"});
|
||||||
response.end("401 Unauthorized");
|
response.end("401 Unauthorized");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});
|
|
||||||
response.end("/" + newBlobId);
|
|
||||||
} else if (blobId === '') {
|
} else if (blobId === '') {
|
||||||
let newBlobId = await ssb.blobStore(request.body);
|
let newBlobId = await ssb.blobStore(request.body);
|
||||||
response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});
|
response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});
|
||||||
|
Loading…
Reference in New Issue
Block a user