diff --git a/server/src/index.ts b/server/src/index.ts index 5298064..d0c0b15 100644 --- a/server/src/index.ts +++ b/server/src/index.ts @@ -1,7 +1,7 @@ import root from "./routes/root.ts"; import user from "./routes/user.ts"; import backfill from "./backfill/index.ts"; -import { PORT, ROOT_DOMAIN, SUBDOMAIN_REGEX, clearCookies } from "./utils.ts"; +import { clearCookies, PORT, ROOT_DOMAIN, SUBDOMAIN_REGEX } from "./utils.ts"; const db = await backfill; @@ -37,11 +37,13 @@ Deno.serve({ port: PORT, hostname: ROOT_DOMAIN }, async (req) => { req, isDidSubdomain ? { - did: `did:${subdomain.at(-1) === "did-plc" ? "plc" : "web"}:${subdomain.slice(0, -1).join(".")}`, - } + did: `did:${subdomain.at(-1) === "did-plc" ? "plc" : "web"}:${ + subdomain.slice(0, -1).join(".") + }`, + } : { - handle: subdomain.join(".") as `${string}.${string}`, - } + handle: subdomain.join(".") as `${string}.${string}`, + }, ); return new Response(res.body, { ...res, @@ -56,6 +58,6 @@ Deno.serve({ port: PORT, hostname: ROOT_DOMAIN }, async (req) => { `Could not resolve domain "${subdomain.join(".")}.${ROOT_DOMAIN}"`, { status: 404, - } + }, ); }); diff --git a/server/src/routes/root.ts b/server/src/routes/root.ts index 521504d..73c68dd 100644 --- a/server/src/routes/root.ts +++ b/server/src/routes/root.ts @@ -1,5 +1,5 @@ import { ROOT_DOMAIN } from "../utils.ts"; -import index from "../www/index.html#denoRawImport=text.ts" with { type: "text" }; +import index from "../www/index.html" with { type: "text" }; import ascii from "./ascii.txt" with { type: "text" }; function route( diff --git a/server/src/routes/user.ts b/server/src/routes/user.ts index 788edd5..86607a0 100644 --- a/server/src/routes/user.ts +++ b/server/src/routes/user.ts @@ -6,7 +6,7 @@ import { } from "@atcute/identity-resolver"; import { and, eq } from "drizzle-orm"; import { routes } from "../db/schema.ts"; -import { ROOT_DOMAIN, type db } from "../utils.ts"; +import { type db, ROOT_DOMAIN } from "../utils.ts"; import ascii from "./ascii.txt" with { type: "text" }; const handleResolver = new CompositeHandleResolver({ @@ -24,7 +24,7 @@ export default async function ( req: Request, user: | { handle: `${string}.${string}` } - | { did: `did:plc:${string}` | `did:web:${string}` } + | { did: `did:plc:${string}` | `did:web:${string}` }, ): Promise { // if handle: resolve did let did: `did:${"plc" | "web"}:${string}`; @@ -41,24 +41,23 @@ This handle { status: 500, statusText: "Internal Server Error", - } + }, ); } } else did = user.did; // look up in db - const db_res = - ( - await db - .select() - .from(routes) - .where( - and( - eq(routes.did, did), - eq(routes.url_route, new URL(req.url).pathname) - ) - ) - ).at(0) ?? + const db_res = ( + await db + .select() + .from(routes) + .where( + and( + eq(routes.did, did), + eq(routes.url_route, new URL(req.url).pathname), + ), + ) + ).at(0) ?? ( await db .select() @@ -72,12 +71,16 @@ This handle 404: The user has no atcities site or is missing a 404 page. If you're the owner of this account, head to https://atcities.dev/ for more information. -The index of this account is at https://${"handle" in user ? user.handle : user.did.split(":").at(-1) + ".did-" + user.did.split(":").at(1)}.${ROOT_DOMAIN}/ +The index of this account is at https://${ + "handle" in user + ? user.handle + : user.did.split(":").at(-1) + ".did-" + user.did.split(":").at(1) + }.${ROOT_DOMAIN}/ `); } try { const file = await Deno.readFile( - `./blobs/${db_res.did}/${db_res.blob_cid}` + `./blobs/${db_res.did}/${db_res.blob_cid}`, ); return new Response(file, { headers: { diff --git a/server/src/utils.ts b/server/src/utils.ts index 198eccd..ff48ae9 100644 --- a/server/src/utils.ts +++ b/server/src/utils.ts @@ -58,8 +58,9 @@ export function clearCookies(req: Request): Headers { */ export function urlToRkey(url: string): string | undefined { // contains 0-9A-Za-z + special valid chars and / seperator. also can contain %XX with XX being hex - if (!url.match(/^([a-zA-Z0-9/\-._~!$&'()*+,;=:@]|(%[0-9a-fA-F]{2}))*$/gm)) + if (!url.match(/^([a-zA-Z0-9/\-._~!$&'()*+,;=:@]|(%[0-9a-fA-F]{2}))*$/gm)) { return; + } return ( url // : replace is hoisted so it doesnt replace colons from elsewhere diff --git a/server/src/www/index.html b/server/src/www/index.html index 1bcd373..f359c9a 100644 --- a/server/src/www/index.html +++ b/server/src/www/index.html @@ -1,4 +1,4 @@ - +