worker: Support GoToSocial posting
This commit is contained in:
parent
d0bd30d401
commit
51c346bc4b
|
@ -137,6 +137,7 @@ async function newSnapshot(request, env, ctx) {
|
||||||
await env.WEBHOOKS_QUEUE.send({
|
await env.WEBHOOKS_QUEUE.send({
|
||||||
type: webhook.type,
|
type: webhook.type,
|
||||||
url: webhook.url,
|
url: webhook.url,
|
||||||
|
auth: webhook.auth ?? "",
|
||||||
hash: hash,
|
hash: hash,
|
||||||
date: date,
|
date: date,
|
||||||
file: `https://daily-servo-r2.gmem.ca/${hash}.png`
|
file: `https://daily-servo-r2.gmem.ca/${hash}.png`
|
||||||
|
@ -180,6 +181,7 @@ ROUTER
|
||||||
.get("/latest.json", withCache, snapshot)
|
.get("/latest.json", withCache, snapshot)
|
||||||
.get("/list.json", withCache, snapshotList)
|
.get("/list.json", withCache, snapshotList)
|
||||||
.post("/new", withAuth, newSnapshot)
|
.post("/new", withAuth, newSnapshot)
|
||||||
|
.get("/favicon.ico", favicon)
|
||||||
// .get("/migrate", withAuth, migrateKeys)
|
// .get("/migrate", withAuth, migrateKeys)
|
||||||
.get("*", withCache, specificSnapshot)
|
.get("*", withCache, specificSnapshot)
|
||||||
|
|
||||||
|
@ -190,6 +192,8 @@ export default {
|
||||||
.then(json)
|
.then(json)
|
||||||
.catch(error),
|
.catch(error),
|
||||||
async queue(batch, env) {
|
async queue(batch, env) {
|
||||||
|
const { versionId, versionTag, versionTimestamp } = env.CF_VERSION_METADATA;
|
||||||
|
|
||||||
for (const msg of batch.messages) {
|
for (const msg of batch.messages) {
|
||||||
let content = msg.body;
|
let content = msg.body;
|
||||||
let payload = "Daily Servo image hash changed!";
|
let payload = "Daily Servo image hash changed!";
|
||||||
|
@ -202,12 +206,21 @@ export default {
|
||||||
};
|
};
|
||||||
content_type = "application/json";
|
content_type = "application/json";
|
||||||
}
|
}
|
||||||
|
if (content.type == "gotosocial") {
|
||||||
|
payload = {
|
||||||
|
status: `[Daily Servo](<https://servo.gmem.ca>) update ${content.date} (${content.hash})\n\n${content.file}`,
|
||||||
|
content_type: 'text/markdown',
|
||||||
|
};
|
||||||
|
content_type = "application/json";
|
||||||
|
}
|
||||||
let response = await fetch(`${content.url}`, {
|
let response = await fetch(`${content.url}`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify(payload),
|
body: JSON.stringify(payload),
|
||||||
headers: {
|
headers: {
|
||||||
"X-Source": "Cloudflare-Workers",
|
"X-Source": "Cloudflare-Workers",
|
||||||
|
"User-Agent": `DAILY-SERVO ${versionId}`,
|
||||||
"Content-Type": content_type,
|
"Content-Type": content_type,
|
||||||
|
...(content.auth != "" && { "Authorization": env[content.auth] })
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
|
|
|
@ -4,6 +4,9 @@ main = "src/index.js"
|
||||||
compatibility_date = "2024-07-25"
|
compatibility_date = "2024-07-25"
|
||||||
compatibility_flags = ["nodejs_compat"]
|
compatibility_flags = ["nodejs_compat"]
|
||||||
|
|
||||||
|
[version_metadata]
|
||||||
|
binding = "CF_VERSION_METADATA"
|
||||||
|
|
||||||
[[kv_namespaces]]
|
[[kv_namespaces]]
|
||||||
binding = "KV_STORE"
|
binding = "KV_STORE"
|
||||||
id = "eddd851b2439407a877c0c2c6e503da2"
|
id = "eddd851b2439407a877c0c2c6e503da2"
|
||||||
|
|
Loading…
Reference in a new issue