···1import root from "./routes/root.ts";
2import user from "./routes/user.ts";
3import backfill from "./backfill/index.ts";
4-import { PORT, ROOT_DOMAIN, SUBDOMAIN_REGEX, clearCookies } from "./utils.ts";
56const db = await backfill;
7···37 req,
38 isDidSubdomain
39 ? {
40- did: `did:${subdomain.at(-1) === "did-plc" ? "plc" : "web"}:${subdomain.slice(0, -1).join(".")}`,
41- }
0042 : {
43- handle: subdomain.join(".") as `${string}.${string}`,
44- }
45 );
46 return new Response(res.body, {
47 ...res,
···56 `Could not resolve domain "${subdomain.join(".")}.${ROOT_DOMAIN}"`,
57 {
58 status: 404,
59- }
60 );
61});
···1import root from "./routes/root.ts";
2import user from "./routes/user.ts";
3import backfill from "./backfill/index.ts";
4+import { clearCookies, PORT, ROOT_DOMAIN, SUBDOMAIN_REGEX } from "./utils.ts";
56const db = await backfill;
7···37 req,
38 isDidSubdomain
39 ? {
40+ did: `did:${subdomain.at(-1) === "did-plc" ? "plc" : "web"}:${
41+ subdomain.slice(0, -1).join(".")
42+ }`,
43+ }
44 : {
45+ handle: subdomain.join(".") as `${string}.${string}`,
46+ },
47 );
48 return new Response(res.body, {
49 ...res,
···58 `Could not resolve domain "${subdomain.join(".")}.${ROOT_DOMAIN}"`,
59 {
60 status: 404,
61+ },
62 );
63});
+1-1
server/src/routes/root.ts
···1import { ROOT_DOMAIN } from "../utils.ts";
2-import index from "../www/index.html#denoRawImport=text.ts" with { type: "text" };
3import ascii from "./ascii.txt" with { type: "text" };
45function route(
···1import { ROOT_DOMAIN } from "../utils.ts";
2+import index from "../www/index.html" with { type: "text" };
3import ascii from "./ascii.txt" with { type: "text" };
45function route(
+20-17
server/src/routes/user.ts
···6} from "@atcute/identity-resolver";
7import { and, eq } from "drizzle-orm";
8import { routes } from "../db/schema.ts";
9-import { ROOT_DOMAIN, type db } from "../utils.ts";
10import ascii from "./ascii.txt" with { type: "text" };
1112const handleResolver = new CompositeHandleResolver({
···24 req: Request,
25 user:
26 | { handle: `${string}.${string}` }
27- | { did: `did:plc:${string}` | `did:web:${string}` }
28): Promise<Response> {
29 // if handle: resolve did
30 let did: `did:${"plc" | "web"}:${string}`;
···41 {
42 status: 500,
43 statusText: "Internal Server Error",
44- }
45 );
46 }
47 } else did = user.did;
4849 // look up in db
50- const db_res =
51- (
52- await db
53- .select()
54- .from(routes)
55- .where(
56- and(
57- eq(routes.did, did),
58- eq(routes.url_route, new URL(req.url).pathname)
59- )
60- )
61- ).at(0) ??
62 (
63 await db
64 .select()
···72404: The user has no atcities site or is missing a 404 page.
7374If you're the owner of this account, head to https://atcities.dev/ for more information.
75-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}/
000076`);
77 }
78 try {
79 const file = await Deno.readFile(
80- `./blobs/${db_res.did}/${db_res.blob_cid}`
81 );
82 return new Response(file, {
83 headers: {
···6} from "@atcute/identity-resolver";
7import { and, eq } from "drizzle-orm";
8import { routes } from "../db/schema.ts";
9+import { type db, ROOT_DOMAIN } from "../utils.ts";
10import ascii from "./ascii.txt" with { type: "text" };
1112const handleResolver = new CompositeHandleResolver({
···24 req: Request,
25 user:
26 | { handle: `${string}.${string}` }
27+ | { did: `did:plc:${string}` | `did:web:${string}` },
28): Promise<Response> {
29 // if handle: resolve did
30 let did: `did:${"plc" | "web"}:${string}`;
···41 {
42 status: 500,
43 statusText: "Internal Server Error",
44+ },
45 );
46 }
47 } else did = user.did;
4849 // look up in db
50+ const db_res = (
51+ await db
52+ .select()
53+ .from(routes)
54+ .where(
55+ and(
56+ eq(routes.did, did),
57+ eq(routes.url_route, new URL(req.url).pathname),
58+ ),
59+ )
60+ ).at(0) ??
061 (
62 await db
63 .select()
···71404: The user has no atcities site or is missing a 404 page.
7273If you're the owner of this account, head to https://atcities.dev/ for more information.
74+The index of this account is at https://${
75+ "handle" in user
76+ ? user.handle
77+ : user.did.split(":").at(-1) + ".did-" + user.did.split(":").at(1)
78+ }.${ROOT_DOMAIN}/
79`);
80 }
81 try {
82 const file = await Deno.readFile(
83+ `./blobs/${db_res.did}/${db_res.blob_cid}`,
84 );
85 return new Response(file, {
86 headers: {
+2-1
server/src/utils.ts
···58 */
59export function urlToRkey(url: string): string | undefined {
60 // contains 0-9A-Za-z + special valid chars and / seperator. also can contain %XX with XX being hex
61- if (!url.match(/^([a-zA-Z0-9/\-._~!$&'()*+,;=:@]|(%[0-9a-fA-F]{2}))*$/gm))
62 return;
063 return (
64 url
65 // : replace is hoisted so it doesnt replace colons from elsewhere
···58 */
59export function urlToRkey(url: string): string | undefined {
60 // contains 0-9A-Za-z + special valid chars and / seperator. also can contain %XX with XX being hex
61+ if (!url.match(/^([a-zA-Z0-9/\-._~!$&'()*+,;=:@]|(%[0-9a-fA-F]{2}))*$/gm)) {
62 return;
63+ }
64 return (
65 url
66 // : replace is hoisted so it doesnt replace colons from elsewhere