Add ActivityPub gateway posting

This commit is contained in:
Gabriel Simmer 2024-08-19 16:35:37 +01:00
parent 1c1f645972
commit 757d71af2e
Signed by: arch
SSH key fingerprint: SHA256:m3OEcdtrnBpMX+2BDGh/byv3hrCekCLzDYMdvGEKPPQ
2 changed files with 19 additions and 1 deletions

View file

@ -147,7 +147,8 @@
</div>
<footer>
made by <a href="https://arch.dog" target="_blank">arch</a>
made by <a href="https://arch.dog" target="_blank">arch</a> |
<a href="https://bird.gmem.ca/@thirdrule" rel="me">activitypub</a>
</footer>
</main>

View file

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