Fiddled with saving and loading so that admin users can push and pull to parent apps.

git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3806 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
2022-01-30 14:51:09 +00:00
parent ec5d7c1a01
commit 0278aceb62
4 changed files with 163 additions and 117 deletions

View File

@ -479,22 +479,25 @@ async function blobHandler(request, response, blobId, uri) {
var user = match[1];
var app = match[2];
var credentials = auth.query(request.headers);
if (!credentials || !credentials.session || credentials.session.name != user) {
if (credentials && credentials.session &&
(credentials.session.name == user ||
(credentials.permissions.administration && user == 'core'))) {
var database = new Database(user);
var apps = new Set();
try {
apps = new Set(JSON.parse(database.get('apps')));
} catch {
}
if (!apps.has(app)) {
apps.add(app);
database.set('apps', JSON.stringify([...apps]));
}
database.set('path:' + app, newBlobId);
} else {
response.writeHead(401, {"Content-Type": "text/plain; charset=utf-8"});
response.end("401 Unauthorized");
return;
}
var database = new Database(user);
var apps = new Set();
try {
apps = new Set(JSON.parse(database.get('apps')));
} catch {
}
if (!apps.has(app)) {
apps.add(app);
database.set('apps', JSON.stringify([...apps]));
}
database.set('path:' + app, newBlobId);
}
response.writeHead(200, {"Content-Type": "text/plain; charset=utf-8"});
@ -594,7 +597,7 @@ loadSettings().then(function() {
return staticFileHandler(request, response, null, match[1]);
} else if (match = /^\/perfetto\/([\.\w-/]*)$/.exec(request.uri)) {
return perfettoHandler(request, response, match[1]);
} else if (match = /^(.*)(\/save)$/.exec(request.uri)) {
} else if (match = /^(.*)(\/save?)$/.exec(request.uri)) {
return blobHandler(request, response, match[1], match[2]);
} else if (match = /^\/trace$/.exec(request.uri)) {
var data = trace();