Fix POST to AP

This commit is contained in:
Gabriel Simmer 2024-08-20 11:26:56 +01:00
parent 757d71af2e
commit 25a9ddab7c
Signed by: arch
SSH key fingerprint: SHA256:m3OEcdtrnBpMX+2BDGh/byv3hrCekCLzDYMdvGEKPPQ
2 changed files with 18 additions and 12 deletions

View file

@ -10,27 +10,30 @@ async function generateRule(env) {
export default { export default {
async scheduled(event, env, ctx) { async scheduled(event, env, ctx) {
const { versionId, versionTag, versionTimestamp } = env.CF_VERSION_METADATA; const { tag } = env.CF_VERSION_METADATA;
const rule = await generateRule(env); const rule = await generateRule(env);
console.log(`generated rule ${JSON.stringify(rule)}`); console.log(`generated rule ${JSON.stringify(rule)}`);
ctx.waitUntil(env.LOG.put("LATEST", JSON.stringify(rule))); ctx.waitUntil(env.LOG.put("LATEST", JSON.stringify(rule)));
ctx.waitUntil(env.LOG.put(Date.now(), JSON.stringify(rule), { expirationTtl: 31_536_000 })); ctx.waitUntil(env.LOG.put(Date.now(), JSON.stringify(rule), { expirationTtl: 31_536_000 }));
payload = { const payload = {
status: `The secret third rule of the day is\n\n>${rule.response}`, status: `The secret third rule of the day is\n\n>${rule.response}`,
content_type: 'text/markdown', content_type: 'text/markdown',
}; };
ctx.waitUntil(await fetch(`https://bird.gmem.ca/api/v1/statuses`, { ctx.waitUntil(async () => {
let response = fetch(`https://bird.gmem.ca/api/v1/statuses`, {
method: "POST", method: "POST",
body: JSON.stringify(payload), body: JSON.stringify(payload),
headers: { headers: {
"X-Source": "Cloudflare-Workers", "X-Source": "Cloudflare-Workers",
"User-Agent": `THIRDRULE ${versionTag}`, "User-Agent": `THIRDRULE ${tag}`,
"Content-Type": content_type, "Content-Type": "application/json",
"Authorization": env.GTS_AUTH "Authorization": `Bearer ${env.GTS_AUTH}`
}, },
})); });
console.log(JSON.stringify(await response.json()));
});
}, },
async fetch(request, env, ctx) { async fetch(request, env, ctx) {

View file

@ -3,6 +3,9 @@ main = "index.js"
compatibility_date = "2023-08-23" compatibility_date = "2023-08-23"
account_id = "7dc420732ea679a530aee304ea49a63c" account_id = "7dc420732ea679a530aee304ea49a63c"
[version_metadata]
binding = "CF_VERSION_METADATA"
[ai] [ai]
binding = "AI" binding = "AI"