From 6302565942646495dcee7543e9592637116b40ea Mon Sep 17 00:00:00 2001 From: Cory McWilliams Date: Wed, 4 Oct 2023 22:57:39 +0000 Subject: [PATCH] Store app blob history. git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@4484 ed5197a5-7fde-0310-b194-c3ffbd925b24 --- core/core.js | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/core/core.js b/core/core.js index 47543c5a..2c4e5e02 100644 --- a/core/core.js +++ b/core/core.js @@ -735,7 +735,6 @@ async function blobHandler(request, response, blobId, uri) { } else if (uri == "/save") { let match; if (match = /^\/\~(\w+)\/(\w+)$/.exec(blobId)) { - let newBlobId = await ssb.blobStore(request.body); let user = match[1]; let appName = match[2]; let credentials = auth.query(request.headers); @@ -743,6 +742,25 @@ async function blobHandler(request, response, blobId, uri) { (credentials.session.name == user || (credentials.permissions.administration && user == 'core'))) { 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_original = database.get('apps'); try { @@ -757,14 +775,13 @@ async function blobHandler(request, response, blobId, uri) { database.set('apps', apps); } database.set('path:' + appName, newBlobId); + response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"}); + response.end("/" + newBlobId); } else { response.writeHead(401, {"Content-Type": "text/plain; charset=utf-8"}); response.end("401 Unauthorized"); return; } - - response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"}); - response.end("/" + newBlobId); } else if (blobId === '') { let newBlobId = await ssb.blobStore(request.body); response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});