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, '>') .replace(/"/g, '"') .replace(/'/g, '''); content = content.split(' '); for (let elem in content) { let e = content[elem]; if (e.startsWith('@')) { let f = e.slice(1); content[elem] = `${e}` } } content = content.join(' '); comment.content = content; } return { ...input, route, id, comments }; }); export default main;