add webhook to blurbs
This commit is contained in:
parent
303a09d18e
commit
313126b6b1
2 changed files with 40 additions and 14 deletions
53
index.js
53
index.js
|
@ -242,11 +242,13 @@ app.post('/mininq/mbox/r', async (req, res) => {
|
||||||
{
|
{
|
||||||
"description": mininq_pub.msg,
|
"description": mininq_pub.msg,
|
||||||
"color": 12298956,
|
"color": 12298956,
|
||||||
|
// TODO: make this smaller
|
||||||
"author": mininq_pub.url != '' ? {
|
"author": mininq_pub.url != '' ? {
|
||||||
"name": `${mininq_pub.name} @ ${new URL(mininq_pub.url).host} sent:`,
|
"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()
|
"timestamp": new Date(mininq_pub.time).toISOString()
|
||||||
}
|
}
|
||||||
|
@ -294,7 +296,7 @@ app.post('/mininq/mbox/r', async (req, res) => {
|
||||||
"color": 12298956,
|
"color": 12298956,
|
||||||
"author": mininq.url != '' ? {
|
"author": mininq.url != '' ? {
|
||||||
"name": `${mininq.name} @ ${new URL(mininq.url).host} sent:`,
|
"name": `${mininq.name} @ ${new URL(mininq.url).host} sent:`,
|
||||||
"url": mininq.url
|
"url": `https://abtmtr.link/mininq/#${mininq.id}`
|
||||||
} : {
|
} : {
|
||||||
"name": `${mininq.name} sent:`
|
"name": `${mininq.name} sent:`
|
||||||
},
|
},
|
||||||
|
@ -304,8 +306,7 @@ app.post('/mininq/mbox/r', async (req, res) => {
|
||||||
"description": body.msg,
|
"description": body.msg,
|
||||||
"color": 13421772,
|
"color": 13421772,
|
||||||
"author": {
|
"author": {
|
||||||
"name": "sysadmin reply:",
|
"name": "sysadmin reply:"
|
||||||
"url": `https://abtmtr.link/mininq/#${mininq.id}`
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
@ -567,6 +568,7 @@ app.get('/blurbs/send', async (req, res) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const postId = nanoid(32);
|
const postId = nanoid(32);
|
||||||
|
const timestamp = Date.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await db.insertInto('blurbs')
|
await db.insertInto('blurbs')
|
||||||
|
@ -575,7 +577,7 @@ app.get('/blurbs/send', async (req, res) => {
|
||||||
site: body.site,
|
site: body.site,
|
||||||
blurb: body.text,
|
blurb: body.text,
|
||||||
verified: 0,
|
verified: 0,
|
||||||
time: Date.now()
|
time: timestamp
|
||||||
})
|
})
|
||||||
.executeTakeFirstOrThrow();
|
.executeTakeFirstOrThrow();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -603,14 +605,37 @@ app.get('/blurbs/check', async (req, res) => {
|
||||||
const relationLink = dom.window.document.querySelector(
|
const relationLink = dom.window.document.querySelector(
|
||||||
`[rel=me][href="https://abtmtr.link/blurbs/#${blurbFromId.id}"]`
|
`[rel=me][href="https://abtmtr.link/blurbs/#${blurbFromId.id}"]`
|
||||||
);
|
);
|
||||||
if (relationLink != null) await db
|
if (relationLink != null) {
|
||||||
.updateTable('blurbs')
|
await db
|
||||||
.set({
|
.updateTable('blurbs')
|
||||||
verified: 1
|
.set({
|
||||||
})
|
verified: 1
|
||||||
.where('id', '=', body.id)
|
})
|
||||||
.executeTakeFirst();
|
.where('id', '=', body.id)
|
||||||
else {
|
.executeTakeFirst();
|
||||||
|
|
||||||
|
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
|
await db
|
||||||
.updateTable('blurbs')
|
.updateTable('blurbs')
|
||||||
.set({
|
.set({
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<link rel="stylesheet" href="/assets/style.css" />
|
<link rel="stylesheet" href="/assets/style.css" />
|
||||||
<link rel="me" href="https://abtmtr.link/about">
|
<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/#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.xml" title="RSS Feed">
|
||||||
<link rel="alternate" type="application/rss+xml" href="https://abtmtr.link/rss" title="RSS Feed">
|
<link rel="alternate" type="application/rss+xml" href="https://abtmtr.link/rss" title="RSS Feed">
|
||||||
</head>
|
</head>
|
Loading…
Reference in a new issue