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