add webhook to blurbs

This commit is contained in:
MeowcaTheoRange 2024-09-03 15:04:31 -05:00
parent 303a09d18e
commit 313126b6b1
2 changed files with 40 additions and 14 deletions

View file

@ -242,11 +242,13 @@ app.post('/mininq/mbox/r', async (req, res) => {
{
"description": mininq_pub.msg,
"color": 12298956,
// TODO: make this smaller
"author": mininq_pub.url != '' ? {
"name": `${mininq_pub.name} @ ${new URL(mininq_pub.url).host} sent:`,
"url": mininq_pub.url
"url": `https://abtmtr.link/mininq/#${mininq.id}`
} : {
"name": `${mininq_pub.name} sent:`
"name": `${mininq_pub.name} sent:`,
"url": `https://abtmtr.link/mininq/#${mininq.id}`
},
"timestamp": new Date(mininq_pub.time).toISOString()
}
@ -294,7 +296,7 @@ app.post('/mininq/mbox/r', async (req, res) => {
"color": 12298956,
"author": mininq.url != '' ? {
"name": `${mininq.name} @ ${new URL(mininq.url).host} sent:`,
"url": mininq.url
"url": `https://abtmtr.link/mininq/#${mininq.id}`
} : {
"name": `${mininq.name} sent:`
},
@ -304,8 +306,7 @@ app.post('/mininq/mbox/r', async (req, res) => {
"description": body.msg,
"color": 13421772,
"author": {
"name": "sysadmin reply:",
"url": `https://abtmtr.link/mininq/#${mininq.id}`
"name": "sysadmin reply:"
}
}
],
@ -567,6 +568,7 @@ app.get('/blurbs/send', async (req, res) => {
}
const postId = nanoid(32);
const timestamp = Date.now();
try {
await db.insertInto('blurbs')
@ -575,7 +577,7 @@ app.get('/blurbs/send', async (req, res) => {
site: body.site,
blurb: body.text,
verified: 0,
time: Date.now()
time: timestamp
})
.executeTakeFirstOrThrow();
} catch (err) {
@ -603,14 +605,37 @@ app.get('/blurbs/check', async (req, res) => {
const relationLink = dom.window.document.querySelector(
`[rel=me][href="https://abtmtr.link/blurbs/#${blurbFromId.id}"]`
);
if (relationLink != null) await db
if (relationLink != null) {
await db
.updateTable('blurbs')
.set({
verified: 1
})
.where('id', '=', body.id)
.executeTakeFirst();
else {
if (process.env.BLURBS_WEBHOOK != null) {
await fetch(process.env.BLURBS_WEBHOOK, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"content": "New blurb:",
"embeds": [
{
"description": blurbFromId.blurb,
"color": 12298956,
"author": {
"name": `${new URL(blurbFromId.site).host}`,
"url": `https://abtmtr.link/blurbs/#${blurbFromId.id}`
},
"timestamp": new Date(blurbFromId.time).toISOString()
}
],
"attachments": []
})
});
}
} else {
await db
.updateTable('blurbs')
.set({

View file

@ -7,6 +7,7 @@
<link rel="stylesheet" href="/assets/style.css" />
<link rel="me" href="https://abtmtr.link/about">
<link rel="me" href="https://abtmtr.link/blurbs/#Hx7CuB4_zIWMAsOZlyyqsUm2upXEEYEl">
<link rel="me" href="https://abtmtr.link/blurbs/#aQArHxCaViG-Qw0aFkBRhQWbRsoxUqsB">
<link rel="alternate" type="application/rss+xml" href="https://abtmtr.link/rss.xml" title="RSS Feed">
<link rel="alternate" type="application/rss+xml" href="https://abtmtr.link/rss" title="RSS Feed">
</head>