From bcb1730f16a1c6ac67f3ddd198364be7cf4744ea Mon Sep 17 00:00:00 2001 From: Steve Date: Thu, 26 Feb 2026 19:59:54 -0500 Subject: [PATCH] chore: applied formatting --- docs/src/index.ts | 23 ++++++---- docs/src/lib/path-redirect.ts | 5 +-- docs/src/routes/subscribe.ts | 80 ++++++++++++++++++++++++++++------- 3 files changed, 80 insertions(+), 28 deletions(-) diff --git a/docs/src/index.ts b/docs/src/index.ts index 2a38133..13dac9e 100644 --- a/docs/src/index.ts +++ b/docs/src/index.ts @@ -12,16 +12,23 @@ type Bindings = { const app = new Hono<{ Bindings: Bindings }>(); +app.use( + "/subscribe", + cors({ + origin: (origin) => origin, + credentials: true, + }), +); +app.use( + "/subscribe/*", + cors({ + origin: (origin) => origin, + credentials: true, + }), +); + app.route("/oauth", auth); app.route("/subscribe", subscribe); -app.use("/subscribe", cors({ - origin: (origin) => origin, - credentials: true, -})); -app.use("/subscribe/*", cors({ - origin: (origin) => origin, - credentials: true, -})); app.get("/api/health", (c) => { return c.json({ status: "ok" }); diff --git a/docs/src/lib/path-redirect.ts b/docs/src/lib/path-redirect.ts index cf6a05c..c40bd94 100644 --- a/docs/src/lib/path-redirect.ts +++ b/docs/src/lib/path-redirect.ts @@ -19,10 +19,7 @@ const errorRedirectRequests = new WeakSet(); const OriginalRequest = globalThis.Request; globalThis.Request = class extends OriginalRequest { - constructor( - input: RequestInfo | URL, - init?: RequestInit, - ) { + constructor(input: RequestInfo | URL, init?: RequestInit) { super(input, sanitizeInit(init)); if (init?.redirect === "error") { errorRedirectRequests.add(this); diff --git a/docs/src/routes/subscribe.ts b/docs/src/routes/subscribe.ts index aca9124..ce30a08 100644 --- a/docs/src/routes/subscribe.ts +++ b/docs/src/routes/subscribe.ts @@ -12,7 +12,10 @@ interface Env { // Cache the vocs-generated stylesheet href across requests (changes on rebuild). let _vocsStyleHref: string | null = null; -async function getVocsStyleHref(assets: Fetcher, baseUrl: string): Promise { +async function getVocsStyleHref( + assets: Fetcher, + baseUrl: string, +): Promise { if (_vocsStyleHref) return _vocsStyleHref; try { const indexUrl = new URL("/", baseUrl).toString(); @@ -105,9 +108,17 @@ subscribe.post("/", async (c) => { const session = await client.restore(did); const agent = new Agent(session); - const existingUri = await findExistingSubscription(agent, did, publicationUri); + const existingUri = await findExistingSubscription( + agent, + did, + publicationUri, + ); if (existingUri) { - return c.json({ subscribed: true, existing: true, recordUri: existingUri }); + return c.json({ + subscribed: true, + existing: true, + recordUri: existingUri, + }); } const result = await agent.com.atproto.repo.createRecord({ @@ -119,7 +130,11 @@ subscribe.post("/", async (c) => { }, }); - return c.json({ subscribed: true, existing: false, recordUri: result.data.uri }); + return c.json({ + subscribed: true, + existing: false, + recordUri: result.data.uri, + }); } catch (error) { console.error("Subscribe POST error:", error); // Treat expired/missing session as unauthenticated @@ -141,7 +156,10 @@ subscribe.get("/", async (c) => { const styleHref = await getVocsStyleHref(c.env.ASSETS, c.req.url); if (!publicationUri || !publicationUri.startsWith("at://")) { - return c.html(renderError("Missing or invalid publication URI.", styleHref), 400); + return c.html( + renderError("Missing or invalid publication URI.", styleHref), + 400, + ); } const did = getSessionDid(c); @@ -154,9 +172,15 @@ subscribe.get("/", async (c) => { const session = await client.restore(did); const agent = new Agent(session); - const existingUri = await findExistingSubscription(agent, did, publicationUri); + const existingUri = await findExistingSubscription( + agent, + did, + publicationUri, + ); if (existingUri) { - return c.html(renderSuccess(publicationUri, existingUri, true, styleHref)); + return c.html( + renderSuccess(publicationUri, existingUri, true, styleHref), + ); } const result = await agent.com.atproto.repo.createRecord({ @@ -168,11 +192,19 @@ subscribe.get("/", async (c) => { }, }); - return c.html(renderSuccess(publicationUri, result.data.uri, false, styleHref)); + return c.html( + renderSuccess(publicationUri, result.data.uri, false, styleHref), + ); } catch (error) { console.error("Subscribe GET error:", error); // Session expired - ask the user to sign in again - return c.html(renderHandleForm(publicationUri, styleHref, "Session expired. Please sign in again.")); + return c.html( + renderHandleForm( + publicationUri, + styleHref, + "Session expired. Please sign in again.", + ), + ); } }); @@ -190,7 +222,10 @@ subscribe.post("/login", async (c) => { if (!handle || !publicationUri) { const styleHref = await getVocsStyleHref(c.env.ASSETS, c.req.url); - return c.html(renderError("Missing handle or publication URI.", styleHref), 400); + return c.html( + renderError("Missing handle or publication URI.", styleHref), + 400, + ); } const returnTo = `${c.env.CLIENT_URL}/subscribe?publicationUri=${encodeURIComponent(publicationUri)}`; @@ -205,12 +240,17 @@ subscribe.post("/login", async (c) => { // HTML rendering // ============================================================================ -function renderHandleForm(publicationUri: string, styleHref: string, error?: string): string { +function renderHandleForm( + publicationUri: string, + styleHref: string, + error?: string, +): string { const errorHtml = error ? `

${escapeHtml(error)}

` : ""; - return page(` + return page( + `

Subscribe on Bluesky

Enter your Bluesky handle to subscribe to this publication.

${errorHtml} @@ -226,7 +266,9 @@ function renderHandleForm(publicationUri: string, styleHref: string, error?: str /> - `, styleHref); + `, + styleHref, + ); } function renderSuccess( @@ -240,16 +282,22 @@ function renderSuccess( : "You've successfully subscribed!"; const escapedPublicationUri = escapeHtml(publicationUri); const escapedRecordUri = escapeHtml(recordUri); - return page(` + return page( + `

Subscribed ✓

${msg}

Publication: ${escapedPublicationUri}

Record: ${escapedRecordUri}

- `, styleHref); + `, + styleHref, + ); } function renderError(message: string, styleHref: string): string { - return page(`

Error

${escapeHtml(message)}

`, styleHref); + return page( + `

Error

${escapeHtml(message)}

`, + styleHref, + ); } function page(body: string, styleHref: string): string { -- 2.51.2