forked from cory/tildefriends
ssb: Bring back the date. Whoops.
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
async function query(sql, params) {
|
||||
let results = [];
|
||||
await ssb.sqlAsync(sql, params, function(row) {
|
||||
await ssb.sqlAsync(sql, params, function (row) {
|
||||
results.push(row);
|
||||
});
|
||||
return results;
|
||||
@ -19,17 +19,22 @@ function guess_content_type(name) {
|
||||
}
|
||||
|
||||
async function main() {
|
||||
let path = request.path.replaceAll(/(%[0-9a-fA-F]{2})/g, x => String.fromCharCode(parseInt(x.substring(1), 16)));
|
||||
let path = request.path.replaceAll(/(%[0-9a-fA-F]{2})/g, (x) =>
|
||||
String.fromCharCode(parseInt(x.substring(1), 16))
|
||||
);
|
||||
let match = path.match(/^(%.{44}\.sha256)(?:\/)?(.*)$/);
|
||||
|
||||
let content_type = guess_content_type(request.path);
|
||||
let root = await query(`
|
||||
let root = await query(
|
||||
`
|
||||
SELECT root.content ->> 'root' AS root
|
||||
FROM messages site
|
||||
JOIN messages root
|
||||
ON site.id = ? AND root.author = site.author AND root.content ->> 'site' = site.id
|
||||
ORDER BY root.sequence DESC LIMIT 1
|
||||
`, [match[1]]);
|
||||
`,
|
||||
[match[1]]
|
||||
);
|
||||
let root_id = root[0]['root'];
|
||||
let last_id = root_id;
|
||||
let blob = await ssb.blobGet(root_id);
|
||||
@ -40,8 +45,7 @@ async function main() {
|
||||
blob = await ssb.blobGet(dir?.links[part]);
|
||||
content_type = guess_content_type(part);
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
} catch {}
|
||||
|
||||
respond({
|
||||
status_code: 200,
|
||||
@ -50,10 +54,10 @@ async function main() {
|
||||
});
|
||||
}
|
||||
|
||||
main().catch(function(e) {
|
||||
main().catch(function (e) {
|
||||
respond({
|
||||
status_code: 200,
|
||||
data: `${e.message}\n${e.stack}`,
|
||||
content_type: 'text/plain',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user