forked from cory/tildefriends
Allow visiting/viewing an app message by id.
git-svn-id: https://www.unprompted.com/svn/projects/tildefriends/trunk@3635 ed5197a5-7fde-0310-b194-c3ffbd925b24
This commit is contained in:
@ -52,7 +52,7 @@ function socket(request, response, client) {
|
||||
var packageName;
|
||||
var blobId;
|
||||
var match;
|
||||
if (match = /^\/(&[^\.]*\.\w+)(\/?.*)/.exec(message.path)) {
|
||||
if (match = /^\/([&%][^\.]{44}(?:\.\w+)?)(\/?.*)/.exec(message.path)) {
|
||||
blobId = match[1];
|
||||
} else if (match = /^\/\~([^\/]+)\/([^\/]+)\/$/.exec(message.path)) {
|
||||
var user = match[1];
|
||||
|
34
core/core.js
34
core/core.js
@ -267,16 +267,16 @@ async function getProcessBlob(blobId, key, options) {
|
||||
}
|
||||
process.task.setImports(imports);
|
||||
process.task.activate();
|
||||
let source = await ssb.blobGet(blobId);
|
||||
let source = await getBlobOrContent(blobId);
|
||||
var appSource = utf8Decode(source);
|
||||
try {
|
||||
var app = JSON.parse(appSource);
|
||||
if (app.type == "tildefriends-app") {
|
||||
var id = app.files["app.js"];
|
||||
var blob = await ssb.blobGet(id);
|
||||
var blob = await getBlobOrContent(id);
|
||||
appSource = utf8Decode(blob);
|
||||
await Promise.all(Object.keys(app.files).map(async function(f) {
|
||||
await process.task.loadFile([f, await ssb.blobGet(app.files[f])]);
|
||||
await process.task.loadFile([f, await getBlobOrContent(app.files[f])]);
|
||||
}));
|
||||
}
|
||||
} catch (e) {
|
||||
@ -387,6 +387,16 @@ function sendData(response, data) {
|
||||
}
|
||||
}
|
||||
|
||||
async function getBlobOrContent(id) {
|
||||
if (!id) {
|
||||
return;
|
||||
} else if (id.startsWith('&')) {
|
||||
return ssb.blobGet(id);
|
||||
} else if (id.startsWith('%')) {
|
||||
return ssb.messageContentGet(id);
|
||||
}
|
||||
}
|
||||
|
||||
async function blobHandler(request, response, blobId, uri) {
|
||||
var found = false;
|
||||
if (!found) {
|
||||
@ -402,7 +412,7 @@ async function blobHandler(request, response, blobId, uri) {
|
||||
}
|
||||
|
||||
if (!uri) {
|
||||
response.writeHead(301, {"Location": blobId + "/"});
|
||||
response.writeHead(301, {"Location": "/" + blobId + "/"});
|
||||
response.end(data);
|
||||
return;
|
||||
}
|
||||
@ -414,14 +424,14 @@ async function blobHandler(request, response, blobId, uri) {
|
||||
if (match = /^\/\~(\w+)\/(\w+)$/.exec(blobId)) {
|
||||
var id = await new Database(match[1]).get('path:' + match[2]);
|
||||
if (id) {
|
||||
data = await ssb.blobGet(id);
|
||||
data = await getBlobOrContent(id);
|
||||
if (match[3]) {
|
||||
var app = JSON.parse(data);
|
||||
data = app.files[match[3]];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
data = await ssb.blobGet(blobId);
|
||||
data = await getBlobOrContent(blobId);
|
||||
}
|
||||
sendData(response, data);
|
||||
} else if (uri == "/save") {
|
||||
@ -449,12 +459,16 @@ async function blobHandler(request, response, blobId, uri) {
|
||||
var db = new Database(match[1]);
|
||||
var id = await db.get('path:' + match[2]);
|
||||
if (id) {
|
||||
data = utf8Decode(await ssb.blobGet(id));
|
||||
data = utf8Decode(await getBlobOrContent(id));
|
||||
var app = JSON.parse(data);
|
||||
print(JSON.stringify(app));
|
||||
data = app.files[uri.substring(1)];
|
||||
data = await ssb.blobGet(data);
|
||||
data = await getBlobOrContent(data);
|
||||
}
|
||||
} else {
|
||||
data = utf8Decode(await getBlobOrContent(blobId));
|
||||
var app = JSON.parse(data);
|
||||
data = app.files[uri.substring(1)];
|
||||
data = await getBlobOrContent(data);
|
||||
}
|
||||
sendData(response, data);
|
||||
}
|
||||
@ -479,7 +493,7 @@ httpd.all("", function(request, response) {
|
||||
return response.end();
|
||||
} else if (match = /^(\/~[^\/]+\/[^\/]+)(\/?.*)$/.exec(request.uri)) {
|
||||
return blobHandler(request, response, match[1], match[2]);
|
||||
} else if (match = /^\/(&[^\.]*\.\w+)(\/?.*)/.exec(request.uri)) {
|
||||
} else if (match = /^\/([&\%][^\.]{44}(?:\.\w+)?)(\/?.*)/.exec(request.uri)) {
|
||||
return blobHandler(request, response, match[1], match[2]);
|
||||
} else if (match = /^\/static(\/.*)/.exec(request.uri)) {
|
||||
return staticFileHandler(request, response, null, match[1]);
|
||||
|
Reference in New Issue
Block a user