2021-01-02 13:10:00 -05:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
const k_posts_max = 20;
|
2021-01-19 21:20:40 -05:00
|
|
|
const k_votes_max = 20;
|
2021-01-02 13:10:00 -05:00
|
|
|
|
2022-01-08 15:54:02 -05:00
|
|
|
var g_ready = false;
|
2022-01-06 20:52:47 -05:00
|
|
|
var g_selected = null;
|
|
|
|
|
2021-12-31 13:42:37 -05:00
|
|
|
var g_following_cache = {};
|
|
|
|
var g_followers_cache = {};
|
|
|
|
var g_following_deep_cache = {};
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
async function following(db, id) {
|
2021-12-31 13:42:37 -05:00
|
|
|
if (g_following_cache[id]) {
|
|
|
|
return g_following_cache[id];
|
|
|
|
}
|
2021-01-02 13:10:00 -05:00
|
|
|
var o = await db.get(id + ":following");
|
2021-01-11 21:23:57 -05:00
|
|
|
const k_version = 5;
|
2021-01-02 13:10:00 -05:00
|
|
|
var f = o ? JSON.parse(o) : o;
|
|
|
|
if (!f || f.version != k_version) {
|
|
|
|
f = {users: [], sequence: 0, version: k_version};
|
|
|
|
}
|
|
|
|
f.users = new Set(f.users);
|
|
|
|
await ssb.sqlStream(
|
|
|
|
"SELECT "+
|
|
|
|
" sequence, "+
|
|
|
|
" json_extract(content, '$.contact') AS contact, "+
|
|
|
|
" json_extract(content, '$.following') AS following "+
|
|
|
|
"FROM messages "+
|
|
|
|
"WHERE "+
|
|
|
|
" author = ?1 AND "+
|
|
|
|
" sequence > ?2 AND "+
|
|
|
|
" json_extract(content, '$.type') = 'contact' "+
|
|
|
|
"UNION SELECT MAX(sequence) AS sequence, NULL, NULL FROM messages WHERE author = ?1 "+
|
|
|
|
"ORDER BY sequence",
|
|
|
|
[id, f.sequence],
|
2021-01-11 21:23:57 -05:00
|
|
|
function(row) {
|
2021-01-02 13:10:00 -05:00
|
|
|
if (row.following) {
|
|
|
|
f.users.add(row.contact);
|
|
|
|
} else {
|
|
|
|
f.users.delete(row.contact);
|
|
|
|
}
|
|
|
|
f.sequence = row.sequence;
|
|
|
|
});
|
2022-01-09 15:36:15 -05:00
|
|
|
var as_set = f.users;
|
|
|
|
f.users = Array.from(f.users).sort();
|
2021-01-02 13:10:00 -05:00
|
|
|
var j = JSON.stringify(f);
|
|
|
|
if (o != j) {
|
|
|
|
await db.set(id + ":following", j);
|
|
|
|
}
|
2022-01-09 15:36:15 -05:00
|
|
|
f.users = as_set;
|
2021-12-31 13:42:37 -05:00
|
|
|
g_following_cache[id] = f.users;
|
2021-01-02 13:10:00 -05:00
|
|
|
return f.users;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function followingDeep(db, seed_ids, depth) {
|
|
|
|
if (depth <= 0) {
|
|
|
|
return seed_ids;
|
|
|
|
}
|
2021-12-31 13:42:37 -05:00
|
|
|
var key = JSON.stringify([seed_ids, depth]);
|
|
|
|
if (g_following_deep_cache[key]) {
|
|
|
|
return g_following_deep_cache[key];
|
|
|
|
}
|
2022-01-09 15:36:15 -05:00
|
|
|
var f = await Promise.all(seed_ids.map(x => following(db, x).then(x => [...x])));
|
2021-01-02 13:10:00 -05:00
|
|
|
var ids = [].concat(...f);
|
|
|
|
var x = await followingDeep(db, [...new Set(ids)].sort(), depth - 1);
|
2022-01-07 19:08:01 -05:00
|
|
|
x = [...new Set([].concat(...x, ...seed_ids))].sort();
|
2021-12-31 13:42:37 -05:00
|
|
|
g_following_deep_cache[key] = x;
|
2021-01-02 13:10:00 -05:00
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getAbout(db, id) {
|
|
|
|
var o = await db.get(id + ":about");
|
2021-01-02 14:33:58 -05:00
|
|
|
const k_version = 4;
|
2021-01-02 13:10:00 -05:00
|
|
|
var f = o ? JSON.parse(o) : o;
|
|
|
|
if (!f || f.version != k_version) {
|
|
|
|
f = {about: {}, sequence: 0, version: k_version};
|
|
|
|
}
|
|
|
|
await ssb.sqlStream(
|
|
|
|
"SELECT "+
|
|
|
|
" sequence, "+
|
|
|
|
" content "+
|
|
|
|
"FROM messages "+
|
|
|
|
"WHERE "+
|
|
|
|
" sequence > ?1 AND "+
|
|
|
|
" author = ?2 AND "+
|
|
|
|
" json_extract(content, '$.type') = 'about' AND "+
|
|
|
|
" json_extract(content, '$.about') = author "+
|
|
|
|
"UNION SELECT MAX(sequence) as sequence, NULL FROM messages WHERE author = ?2 "+
|
|
|
|
"ORDER BY sequence",
|
|
|
|
[f.sequence, id],
|
2021-01-09 17:19:52 -05:00
|
|
|
function(row) {
|
2021-01-02 13:10:00 -05:00
|
|
|
f.sequence = row.sequence;
|
|
|
|
if (row.content) {
|
|
|
|
var about = {};
|
|
|
|
try {
|
|
|
|
about = JSON.parse(row.content);
|
|
|
|
} catch {
|
|
|
|
}
|
|
|
|
delete about.about;
|
|
|
|
delete about.type;
|
|
|
|
f.about = Object.assign(f.about, about);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var j = JSON.stringify(f);
|
|
|
|
if (o != j) {
|
|
|
|
await db.set(id + ":about", j);
|
|
|
|
}
|
|
|
|
return f.about;
|
|
|
|
}
|
|
|
|
|
|
|
|
function fnv32a(value)
|
|
|
|
{
|
|
|
|
var result = 0x811c9dc5;
|
|
|
|
for (var i = 0; i < value.length; i++) {
|
|
|
|
result ^= value.charCodeAt(i);
|
|
|
|
result += (result << 1) + (result << 4) + (result << 7) + (result << 8) + (result << 24);
|
|
|
|
}
|
|
|
|
return result >>> 0;
|
|
|
|
}
|
|
|
|
|
2022-01-08 16:12:36 -05:00
|
|
|
async function getRecentPostsSingleId(db, id, limit) {
|
|
|
|
var recent = [];
|
|
|
|
await ssb.sqlStream(
|
|
|
|
"SELECT "+
|
|
|
|
" rowid, "+
|
|
|
|
" id, "+
|
|
|
|
" timestamp "+
|
|
|
|
"FROM messages "+
|
|
|
|
"WHERE "+
|
|
|
|
" author = ? AND "+
|
|
|
|
" json_extract(content, '$.type') = 'post' "+
|
|
|
|
"ORDER BY sequence DESC LIMIT ?",
|
|
|
|
[id, limit],
|
|
|
|
function(row) {
|
|
|
|
if (row.id) {
|
|
|
|
recent.push({id: row.id, timestamp: row.timestamp});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
recent.sort((x, y) => y.timestamp - x.timestamp);
|
|
|
|
return recent.map(x => x.id);
|
|
|
|
}
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
async function getRecentPostIds(db, id, ids, limit) {
|
2022-01-08 16:12:36 -05:00
|
|
|
if (ids.length == 1) {
|
|
|
|
return await getRecentPostsSingleId(db, ids[0], limit);
|
|
|
|
}
|
2021-12-31 11:10:08 -05:00
|
|
|
const k_version = 11;
|
2021-12-31 13:42:37 -05:00
|
|
|
const k_batch_max = 16;
|
2021-01-02 13:10:00 -05:00
|
|
|
var o = await db.get(id + ':recent_posts');
|
|
|
|
var recent = [];
|
|
|
|
var f = o ? JSON.parse(o) : o;
|
|
|
|
var ids_hash = fnv32a(JSON.stringify(ids));
|
|
|
|
if (!f || f.version != k_version || f.ids_hash != ids_hash) {
|
|
|
|
f = {recent: [], rowid: 0, version: k_version, ids_hash: ids_hash};
|
|
|
|
}
|
2021-12-29 16:00:03 -05:00
|
|
|
var row_id_max = 0;
|
2021-01-02 13:10:00 -05:00
|
|
|
await ssb.sqlStream(
|
2021-12-29 16:20:24 -05:00
|
|
|
"SELECT MAX(rowid) as rowid FROM messages",
|
2021-12-29 16:00:03 -05:00
|
|
|
[],
|
2021-01-02 13:10:00 -05:00
|
|
|
function(row) {
|
2021-12-29 16:00:03 -05:00
|
|
|
row_id_max = row.rowid;
|
2021-01-02 13:10:00 -05:00
|
|
|
});
|
2021-12-29 16:00:03 -05:00
|
|
|
for (var i = 0; i < ids.length; i += k_batch_max) {
|
|
|
|
var ids_batch = ids.slice(i, Math.min(i + k_batch_max, ids.length));
|
|
|
|
await ssb.sqlStream(
|
|
|
|
"SELECT "+
|
|
|
|
" rowid, "+
|
|
|
|
" id, "+
|
|
|
|
" timestamp "+
|
|
|
|
"FROM messages "+
|
|
|
|
"WHERE "+
|
|
|
|
" rowid > ? AND "+
|
|
|
|
" rowid <= ? AND "+
|
|
|
|
" author IN (" + ids_batch.map(x => '?').join(", ") + ") AND "+
|
2021-12-31 13:42:37 -05:00
|
|
|
" json_extract(content, '$.type') = 'post' "+
|
2021-12-29 16:00:03 -05:00
|
|
|
"ORDER BY timestamp DESC LIMIT ?",
|
|
|
|
[].concat([f.rowid, row_id_max], ids_batch, [limit]),
|
|
|
|
function(row) {
|
|
|
|
if (row.id) {
|
2021-12-29 16:20:24 -05:00
|
|
|
recent.push({id: row.id, timestamp: row.timestamp});
|
2021-12-29 16:00:03 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-12-31 11:10:08 -05:00
|
|
|
f.rowid = row_id_max;
|
2021-12-29 16:20:24 -05:00
|
|
|
f.recent = [].concat(recent, f.recent);
|
2022-01-06 20:52:47 -05:00
|
|
|
var have = {};
|
|
|
|
f.recent = f.recent.filter(function(x) {
|
|
|
|
if (!have[x.id]) {
|
|
|
|
have[x.id] = true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
});
|
2021-12-29 16:20:24 -05:00
|
|
|
f.recent.sort((x, y) => y.timestamp - x.timestamp);
|
|
|
|
f.recent = f.recent.slice(0, limit);
|
2021-01-02 13:10:00 -05:00
|
|
|
var j = JSON.stringify(f);
|
|
|
|
if (o != j) {
|
|
|
|
await db.set(id + ":recent_posts", j);
|
|
|
|
}
|
2021-12-29 16:20:24 -05:00
|
|
|
return f.recent.map(x => x.id);
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
|
|
|
|
2022-01-11 21:55:29 -05:00
|
|
|
async function getRelatedPostIds(db, message, ids, limit) {
|
|
|
|
const k_batch_max = 16;
|
|
|
|
var recent = [];
|
|
|
|
var row_id_max = 0;
|
|
|
|
await ssb.sqlStream(
|
|
|
|
"SELECT MAX(rowid) as rowid FROM messages",
|
|
|
|
[],
|
|
|
|
function(row) {
|
|
|
|
row_id_max = row.rowid;
|
|
|
|
});
|
|
|
|
var id = message.id;
|
|
|
|
try {
|
|
|
|
id = JSON.parse(message.content).root || id;
|
|
|
|
} catch {
|
|
|
|
}
|
|
|
|
for (var i = 0; i < ids.length; i += k_batch_max) {
|
|
|
|
var ids_batch = ids.slice(i, Math.min(i + k_batch_max, ids.length));
|
|
|
|
await ssb.sqlStream(
|
|
|
|
"SELECT "+
|
|
|
|
" rowid, "+
|
|
|
|
" id, "+
|
|
|
|
" timestamp "+
|
|
|
|
"FROM messages "+
|
|
|
|
"WHERE "+
|
|
|
|
" timestamp >= ? AND "+
|
|
|
|
" rowid <= ? AND "+
|
|
|
|
" author IN (" + ids_batch.map(x => '?').join(", ") + ") AND "+
|
|
|
|
" json_extract(content, '$.type') = 'post' AND "+
|
2022-01-12 19:16:27 -05:00
|
|
|
" (id = ? OR json_extract(content, '$.root') = ?) "+
|
2022-01-11 21:55:29 -05:00
|
|
|
"ORDER BY timestamp DESC LIMIT ?",
|
2022-01-14 19:29:51 -05:00
|
|
|
[].concat([message.timestamp || 0, row_id_max], ids_batch, [message.id, id, limit]),
|
2022-01-11 21:55:29 -05:00
|
|
|
function(row) {
|
|
|
|
if (row.id) {
|
|
|
|
recent.push({id: row.id, timestamp: row.timestamp});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
recent.sort((x, y) => y.timestamp - x.timestamp);
|
|
|
|
recent = recent.slice(0, limit);
|
|
|
|
return recent.map(x => x.id);
|
|
|
|
}
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
async function getVotes(db, id) {
|
|
|
|
var o = await db.get(id + ":votes");
|
2022-01-08 16:12:36 -05:00
|
|
|
const k_version = 7;
|
2021-01-02 13:10:00 -05:00
|
|
|
var votes = [];
|
|
|
|
var f = o ? JSON.parse(o) : o;
|
|
|
|
if (!f || f.version != k_version) {
|
2022-01-08 16:12:36 -05:00
|
|
|
f = {votes: [], sequence: 0, version: k_version};
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
|
|
|
await ssb.sqlStream(
|
|
|
|
"SELECT "+
|
|
|
|
" author, "+
|
|
|
|
" id, "+
|
|
|
|
" sequence, "+
|
|
|
|
" timestamp, "+
|
|
|
|
" content "+
|
|
|
|
"FROM messages "+
|
|
|
|
"WHERE "+
|
|
|
|
" author = ? AND "+
|
2022-01-08 16:12:36 -05:00
|
|
|
" sequence > ? AND "+
|
2021-01-02 13:10:00 -05:00
|
|
|
" json_extract(content, '$.type') = 'vote' "+
|
2022-01-08 16:12:36 -05:00
|
|
|
"UNION SELECT NULL, NULL, MAX(sequence), NULL, NULL FROM messages WHERE author = ? "+
|
|
|
|
"ORDER BY sequence DESC LIMIT ?",
|
|
|
|
[f.sequence, id, id, k_votes_max],
|
2021-01-11 21:23:57 -05:00
|
|
|
function(row) {
|
2021-01-02 13:10:00 -05:00
|
|
|
if (row.id) {
|
|
|
|
votes.push(row);
|
|
|
|
}
|
2022-01-08 16:12:36 -05:00
|
|
|
f.sequence = Math.max(f.sequence, row.sequence);
|
2021-01-02 13:10:00 -05:00
|
|
|
});
|
2022-01-08 16:12:36 -05:00
|
|
|
f.votes = [].concat(votes, f.votes).slice(0, k_votes_max);
|
2021-01-02 13:10:00 -05:00
|
|
|
var j = JSON.stringify(f);
|
|
|
|
if (o != j) {
|
|
|
|
await db.set(id + ":votes", j);
|
|
|
|
}
|
|
|
|
return f.votes;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getPosts(db, ids) {
|
|
|
|
var posts = [];
|
|
|
|
if (ids.length) {
|
|
|
|
await ssb.sqlStream(
|
2021-11-03 19:23:20 -04:00
|
|
|
"SELECT rowid, * FROM messages WHERE id IN (" + ids.map(x => "?").join(", ") + ") ORDER BY timestamp DESC",
|
2021-01-02 13:10:00 -05:00
|
|
|
ids,
|
2021-01-19 21:20:40 -05:00
|
|
|
row => posts.push(row));
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
|
|
|
return posts;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function ready() {
|
2022-01-08 15:54:02 -05:00
|
|
|
g_ready = true;
|
2022-01-06 20:52:47 -05:00
|
|
|
return refresh(g_selected);
|
2021-01-02 13:35:12 -05:00
|
|
|
}
|
|
|
|
|
2021-12-28 15:21:23 -05:00
|
|
|
ssb.addEventListener('broadcasts', async function() {
|
2021-01-02 13:35:12 -05:00
|
|
|
await app.postMessage({broadcasts: await ssb.getBroadcasts()});
|
|
|
|
});
|
|
|
|
|
|
|
|
core.register('onConnectionsChanged', async function() {
|
|
|
|
var connections = await ssb.connections();
|
|
|
|
await app.postMessage({connections: connections});
|
|
|
|
});
|
|
|
|
|
2022-01-06 20:52:47 -05:00
|
|
|
async function refresh(selected) {
|
2021-12-31 13:42:37 -05:00
|
|
|
g_following_cache = {};
|
|
|
|
g_followers_cache = {};
|
|
|
|
g_following_deep_cache = {};
|
2021-01-02 13:35:12 -05:00
|
|
|
await app.postMessage({clear: true});
|
2021-01-02 13:10:00 -05:00
|
|
|
var whoami = await ssb.whoami();
|
|
|
|
var db = await database("ssb");
|
2022-01-06 20:52:47 -05:00
|
|
|
var all_followed = await followingDeep(db, [whoami], 2);
|
|
|
|
if (selected) {
|
|
|
|
g_selected = selected;
|
|
|
|
} else {
|
|
|
|
g_selected = all_followed;
|
|
|
|
}
|
2021-01-02 13:10:00 -05:00
|
|
|
await Promise.all([
|
|
|
|
app.postMessage({whoami: whoami}),
|
2022-01-08 15:54:02 -05:00
|
|
|
app.postMessage({hash: selected && selected.length == 1 ? selected[0] : null}),
|
2022-01-06 20:52:47 -05:00
|
|
|
ssb.getBroadcasts().then(broadcasts => app.postMessage({broadcasts: broadcasts})),
|
|
|
|
ssb.connections().then(connections => app.postMessage({connections: connections})),
|
|
|
|
core.apps().then(apps => app.postMessage({apps: apps})),
|
2021-01-02 13:10:00 -05:00
|
|
|
]);
|
2022-01-11 21:55:29 -05:00
|
|
|
var ids;
|
|
|
|
if (selected && selected.length == 1 && selected[0].startsWith('%')) {
|
|
|
|
var m = await getPosts(db, selected);
|
2022-01-14 19:29:51 -05:00
|
|
|
m = m.length ? m[0] : {id: selected[0]};
|
|
|
|
ids = await getRelatedPostIds(db, m, all_followed, k_posts_max);
|
2022-01-11 21:55:29 -05:00
|
|
|
} else {
|
|
|
|
ids = await getRecentPostIds(db, whoami, g_selected, k_posts_max);
|
|
|
|
}
|
2022-01-09 15:36:15 -05:00
|
|
|
var posts = await getPosts(db, ids);
|
|
|
|
var roots = posts.map(function(x) {
|
|
|
|
try {
|
|
|
|
return JSON.parse(x.content).root;
|
|
|
|
} catch {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
var have = new Set(posts.map(x => x.id));
|
|
|
|
roots = [...new Set(roots)].filter(x => x && !have.has(x));
|
|
|
|
var all_posts = [].concat(posts, await getPosts(db, roots));
|
|
|
|
await Promise.all(all_posts.map(x => app.postMessage({message: x})));
|
|
|
|
await Promise.all(all_followed.map(id => getAbout(db, id).then(results => app.postMessage({user: {user: id, about: results}}))));
|
2022-01-23 14:15:18 -05:00
|
|
|
await Promise.all(all_followed.map(id => getVotes(db, id).then(results => results.length ? app.postMessage({votes: results}) : null)));
|
2022-01-09 15:36:15 -05:00
|
|
|
await Promise.all(all_followed.map(id => following(db, id).then(results => app.postMessage({following: {id: id, users: [...results]}}))));
|
2022-01-08 15:54:02 -05:00
|
|
|
await app.postMessage({ready: true});
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
|
|
|
|
2021-12-27 15:24:14 -05:00
|
|
|
ssb.addEventListener('message', async function(id) {
|
|
|
|
var db = await database("ssb");
|
|
|
|
var posts = await getPosts(db, [id]);
|
|
|
|
for (let post of posts) {
|
2022-01-14 18:55:14 -05:00
|
|
|
if (post.author == await ssb.whoami() ||
|
|
|
|
JSON.parse(post.content).type != 'post') {
|
2021-12-29 09:57:10 -05:00
|
|
|
await app.postMessage({message: post});
|
|
|
|
} else {
|
|
|
|
await app.postMessage({unread: 1});
|
|
|
|
}
|
2021-12-27 15:24:14 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2022-01-14 20:34:11 -05:00
|
|
|
async function addAppSources(message) {
|
2022-01-15 13:02:05 -05:00
|
|
|
if (message.mentions) {
|
|
|
|
for (let mention of message.mentions) {
|
|
|
|
if (mention.type == 'application/tildefriends') {
|
|
|
|
var blob = await ssb.blobGet(mention.link);
|
|
|
|
var json = JSON.parse(utf8Decode(blob));
|
|
|
|
for (let file of Object.keys(json.files)) {
|
|
|
|
message.mentions.push({
|
|
|
|
name: file,
|
|
|
|
link: json.files[file],
|
|
|
|
});
|
|
|
|
}
|
2022-01-14 20:34:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-02 13:10:00 -05:00
|
|
|
core.register('message', async function(m) {
|
|
|
|
if (m.message == 'ready') {
|
|
|
|
await ready();
|
|
|
|
} else if (m.message) {
|
|
|
|
if (m.message.connect) {
|
|
|
|
await ssb.connect(m.message.connect);
|
|
|
|
} else if (m.message.appendMessage) {
|
2022-01-14 20:34:11 -05:00
|
|
|
await addAppSources(m.message.appendMessage);
|
2021-01-02 13:10:00 -05:00
|
|
|
await ssb.appendMessage(m.message.appendMessage);
|
|
|
|
} else if (m.message.refresh) {
|
2022-01-06 20:52:47 -05:00
|
|
|
await refresh(g_selected);
|
|
|
|
}
|
|
|
|
} else if (m.event == 'hashChange') {
|
|
|
|
if (m.hash.length > 1) {
|
2022-01-08 15:54:02 -05:00
|
|
|
g_selected = [m.hash.substring(1)];
|
2022-01-06 20:52:47 -05:00
|
|
|
} else {
|
2022-01-08 15:54:02 -05:00
|
|
|
g_selected = null;
|
|
|
|
}
|
|
|
|
if (g_ready) {
|
|
|
|
await refresh(g_selected);
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
2021-12-28 15:21:23 -05:00
|
|
|
} else if (m.event == 'focus' || m.event == 'blur') {
|
|
|
|
/* Shh. */
|
2021-01-02 13:10:00 -05:00
|
|
|
} else {
|
|
|
|
print(JSON.stringify(m));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
async function main() {
|
2021-01-03 15:31:00 -05:00
|
|
|
if (core.user &&
|
|
|
|
core.user.credentials &&
|
|
|
|
core.user.credentials.permissions &&
|
|
|
|
core.user.credentials.permissions.administration) {
|
|
|
|
await app.setDocument(utf8Decode(await getFile("index.html")));
|
|
|
|
} else {
|
|
|
|
await app.setDocument('<div style="color: #f00">Only the administrator can use this app at this time. Login at the top right.</div>');
|
|
|
|
}
|
2021-01-02 13:10:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
main();
|