derv-net/lib.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

2025-02-25 16:35:22 -05:00
async function importRouters(app, routers) {
for (let router in routers) {
await app.use(router, (await import(routers[router])).default)
}
}
2025-02-25 19:47:28 -05:00
function apiStat(res, next, message, success = false, redirect = '/') {
res.api = { success, message, redirect };
next();
}
2025-02-26 20:17:33 -05:00
function splitUp(content) {
let out = content.split('\n').map(x => x.split('::'));
return out;
}
2025-02-26 19:50:37 -05:00
async function replyIterator(replies, db) {
for (let reply of replies) {
if (reply.childType == 'hub') {
reply.comment = { type: reply.childType, id: reply.childId, content: `The ${reply.childId} hub.`, username: false, date: undefined };
continue;
} else if (reply.childType == 'users') {
reply.comment = { type: reply.childType, id: reply.childId, content: `User ${reply.childId}'s wall.`, username: false, date: undefined };
continue;
}
let dat = await db.all('SELECT * FROM comment WHERE id = ?', [
reply.childId
]);
if (reply.childType != 'comment' || dat.length < 1) {
reply.comment = 'fail';
continue;
}
reply.comment = dat[0];
reply.comment.type = reply.childType;
//reply.comment.id = reply.childId;
}
2025-02-26 20:17:33 -05:00
for (let reply of replies) {
reply.comment.content = splitUp(reply.comment.content)
}
2025-02-26 19:50:37 -05:00
return replies;
}
export { importRouters, apiStat, replyIterator };