Fix POST to AP
This commit is contained in:
parent
757d71af2e
commit
25a9ddab7c
27
index.js
27
index.js
|
@ -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 () => {
|
||||||
method: "POST",
|
let response = fetch(`https://bird.gmem.ca/api/v1/statuses`, {
|
||||||
body: JSON.stringify(payload),
|
method: "POST",
|
||||||
headers: {
|
body: JSON.stringify(payload),
|
||||||
"X-Source": "Cloudflare-Workers",
|
headers: {
|
||||||
"User-Agent": `THIRDRULE ${versionTag}`,
|
"X-Source": "Cloudflare-Workers",
|
||||||
"Content-Type": content_type,
|
"User-Agent": `THIRDRULE ${tag}`,
|
||||||
"Authorization": env.GTS_AUTH
|
"Content-Type": "application/json",
|
||||||
},
|
"Authorization": `Bearer ${env.GTS_AUTH}`
|
||||||
}));
|
},
|
||||||
|
});
|
||||||
|
console.log(JSON.stringify(await response.json()));
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
async fetch(request, env, ctx) {
|
async fetch(request, env, ctx) {
|
||||||
|
|
|
@ -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"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue