Something went wrong. Try again.
Schedule posts and reposts to Bluesky (and other PDSes) with Cloudflare workers. skyscheduler.work
scheduling social-media cloudflare bsky service cloudflare-workers bsky-tool bluesky
Something went wrong. Try again.
1.3 kB · 42 lines
TypeScript
at main
12345678910111213141516171819202122232425262728293031323334353637383940414243import type { BaseContext } from "../types";import { getUserDID, getUserPDS } from "./bsky/bskyUser";import { doesAdminExist } from "./db/userinfo";import { has } from "./helpers";
export const setupAccounts = async (c: BaseContext) => { if (await doesAdminExist(c)) return c.html("already created", 500);
const settingsToCheck: string[] = ["DEFAULT_ADMIN_USER", "DEFAULT_ADMIN_PASS"];
// Loop through and check all of the settings that are easy to miss for (const setting of settingsToCheck) { if (!has(c.env, setting)) { return c.text(`missing ${setting} setting!`); } } const adminName = c.env.DEFAULT_ADMIN_USER;
const profileDID: string|null = await getUserDID(adminName); if (profileDID === null) { return c.text(`admin user ${adminName} has an invalid DID`) } const userPDS: string = await getUserPDS(profileDID);
const data = await c.get("auth").api.signUpEmail({ body: { name: "admin", email: `${adminName}@skyscheduler.tld`, // @ts-ignore: Property does not exist (it does via an extension) username: adminName, password: c.env.DEFAULT_ADMIN_PASS, bskyAppPass: c.env.DEFAULT_ADMIN_BSKY_PASS, did: profileDID, pds: userPDS }, }); if (data.token !== null) return c.redirect("/"); else return c.html("failure", 403);}