28 lines
756 B
TypeScript
28 lines
756 B
TypeScript
|
import { Router } from "express";
|
||
|
import { Database } from "sqlite3";
|
||
|
|
||
|
const domain = process.env.DOMAIN;
|
||
|
|
||
|
export default function conversation(router: Router) {
|
||
|
router.get("/ap/conversation/:id", (req, res) => {
|
||
|
const db = req.app.get("db") as Database;
|
||
|
db.all("SELECT * FROM notes WHERE conversation = $conversation", {
|
||
|
$conversation: `https://${domain}/ap/conversation/${req.params.id}`
|
||
|
}, (err, rows) => {
|
||
|
if (err) {
|
||
|
res.status(500).end(err);
|
||
|
} else {
|
||
|
const notes = rows.map(row => {
|
||
|
return {
|
||
|
attributedTo: row.attributed_to,
|
||
|
content: row.content,
|
||
|
published: row.published,
|
||
|
inReplyTo: row.in_reply_to,
|
||
|
conversation: row.conversation
|
||
|
};
|
||
|
});
|
||
|
res.json(notes).end();
|
||
|
}
|
||
|
});
|
||
|
});
|
||
|
}
|