bigly-chat/client/comment.js
2024-11-25 14:12:44 -05:00

47 lines
No EOL
1.1 KiB
JavaScript

import Route from "../route.js";
import auth from "../form/auth.js";
import initDb from "../db.js";
let db = await initDb();
let main = new Route([auth], async function (req, res, input) {
let { route } = req.params;
let { id } = req.query;
let comments = await db.all('SELECT * FROM comment WHERE targetType = ? AND targetId = ? ORDER BY date DESC', [
route,
id
]);
for (let comment of comments) {
let { content } = comment;
content = content.replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;');
content = content.split(' ');
for (let elem in content) {
let e = content[elem];
if (e.startsWith('@')) {
let f = e.slice(1);
content[elem] = `<a class='link' href='/client/user?id=${f}'>${e}</a>`
}
}
content = content.join(' ');
comment.content = content;
}
return {
...input,
route,
id,
comments
};
});
export default main;