Schedule posts to Bluesky with Cloudflare workers.
skyscheduler.work
cf
tool
bsky-tool
cloudflare
bluesky
schedule
bsky
service
social-media
cloudflare-workers
1import { Context } from "hono";
2import has from "just-has";
3import { doesAdminExist } from "./db/userinfo";
4
5export const setupAccounts = async(c: Context) => {
6 if (await doesAdminExist(c))
7 return c.html("already created", 501);
8
9 const settingsToCheck: string[] =
10 ["DEFAULT_ADMIN_USER", "DEFAULT_ADMIN_PASS", "DEFAULT_ADMIN_BSKY_PASS"];
11
12 // Loop through and check all of the settings that are easy to miss
13 for (const setting of settingsToCheck) {
14 if (!has(c.env, setting)) {
15 return c.text(`missing ${setting} setting!`);
16 }
17 }
18
19 const data = await c.get("auth").api.signUpEmail({
20 body: {
21 name: "admin",
22 email: `${c.env.DEFAULT_ADMIN_USER}@skyscheduler.tld`,
23 // @ts-ignore: Property does not exist (it does via an extension)
24 username: c.env.DEFAULT_ADMIN_USER,
25 password: c.env.DEFAULT_ADMIN_PASS,
26 bskyAppPass: c.env.DEFAULT_ADMIN_BSKY_PASS
27 }
28 });
29 if (data.token !== null)
30 return c.redirect("/");
31 else
32 return c.html("failure", 401);
33}