diff --git a/index/spacedust.ts b/index/spacedust.ts index 86bbf09..88ca943 100644 --- a/index/spacedust.ts +++ b/index/spacedust.ts @@ -1,4 +1,4 @@ -import { handleIndex, spacedustManager } from "../main.ts"; +import { db, handleIndex, spacedustManager } from "../main.ts"; import { parseAtUri } from "../utils/aturi.ts"; import { resolveRecordFromURI } from "../utils/records.ts"; @@ -59,25 +59,45 @@ export async function handleSpacedust(msg: SpacedustLinkMessage) { console.log("Received Spacedust message: ", msg); const op = msg.link.operation; - // @ts-expect-error i really should enforce some smarter types for this - const doer = parseAtUri(msg.link.source_record).did; - if (!doer) return; - const rev = msg.link.source_rev; - const aturi = msg.link.source_record; - const value = await resolveRecordFromURI({uri: msg.link.source_record}); - + const srcdid = parseAtUri(msg.link.source_record)?.did; + const srccol = parseAtUri(msg.link.source_record)?.collection; + if (!srcdid || !srccol) return; const subject = msg.link.subject; + const subdid = parseAtUri(subject)?.did; + const subscol = parseAtUri(subject)?.collection; + if (!subdid || !subscol) return; + //const rev = msg.link.source_rev; + const aturi = msg.link.source_record; + //const value = await resolveRecordFromURI({uri: msg.link.source_record}); + db.exec(` + INSERT INTO backlink_skeleton ( + srcuri, + srcdid, + srcfield, + srccol, + suburi, + subdid, + subcol + ) VALUES ( + '${aturi}', + '${srcdid}', + '${srccol}', + '${msg.link.source}', + '${subject}', + '${subdid}', + '${subscol}' + ); + `); + //if (!value) return; - if (!value) return; - - handleIndex({ - op, - doer, - rev, - aturi, - value, - indexsrc: "spacedust", - }) + // handleIndex({ + // op, + // doer, + // rev, + // aturi, + // value, + // indexsrc: "spacedust", + // }) return; // switch (msg.link.source) { diff --git a/main.ts b/main.ts index dfe26c4..ce42886 100644 --- a/main.ts +++ b/main.ts @@ -5,10 +5,10 @@ import dbsetup from "./utils/dbsetup.ts"; import { handleSpacedust, startSpacedust } from "./index/spacedust.ts"; import { handleJetstream, startJetstream } from "./index/jetstream.ts"; import { Database } from "jsr:@db/sqlite@0.11"; -import express from "npm:express"; -import { createServer } from "./xrpc/index.ts"; +//import express from "npm:express"; +//import { createServer } from "./xrpc/index.ts"; import { indexHandlerContext } from "./index/types.ts"; -import * as XRPCTypes from "./utils/xrpc.ts" +import * as XRPCTypes from "./utils/xrpc.ts"; import { didDocument } from "./utils/diddoc.ts"; // ------------------------------------------ @@ -33,44 +33,571 @@ setupAuth({ //keyCacheTTL: 10 * 60 * 1000, }); -const app = express(); -const server = createServer(); -app.use(server.xrpc.router); -app.listen(3768); - -app.get('/.well-known/did.json', (req, res) => { - res.setHeader('Access-Control-Allow-Origin', '*'); - res.setHeader('Content-Type', 'application/did+json'); - res.json(didDocument); -}); - -app.get('/health', (req, res) => { - res.send('OK'); -}); - // ------------------------------------------ // XRPC Method Implementations // ------------------------------------------ -server.app.bsky.actor.getProfile({ - auth: authVerifier, - handler: async ({ auth, params }): Promise => { - console.log("xrpcbaby",auth,params) - return { - encoding: "application/json", - body: { - did: params.actor, - handle: "example.com", - displayName: "baby's first XRPC Method Implemented", - avatar: undefined, - description: `the auth is [${JSON.stringify(auth)}] and params are [${JSON.stringify(params)}]`, - // @ts-expect-error its safe, probably - "testudefinedfield": "wow youre are an idiotee", - }, - }; - }, +// begin the hell of implementing api requests and incoming records +//const seenStrings = new Set(); + +let preferences: any = undefined; +Deno.serve({ port: 3768 }, async (req: Request): Promise => { + const url = new URL(req.url); + const pathname = new URL(req.url).pathname; + let reqBody: undefined | string; + let jsonbody: undefined | Record; + if (req.body) { + const body = await req.json(); + jsonbody = body; + console.log( + `called at euh reqreqreqreq: ${pathname}\n\n${JSON.stringify(body)}` + ); + reqBody = JSON.stringify(body, null, 2); + } + if (pathname === "/.well-known/did.json") { + return new Response(JSON.stringify(didDocument), { + headers: withCors({ "Content-Type": "application/json" }), + }); + } + if (pathname === "/health") { + return new Response("OK", { + status: 200, + headers: withCors({ + "Content-Type": "text/plain", + }), + }); + } + + // if (seenStrings.has(url.hash)) { + // // The string has been seen before + // seenStrings.delete(url.hash); + // return new Response("OK", { + // status: 204, + // headers: withCors({ + // "Content-Type": "text/plain", + // }), + // }); + // } + // seenStrings.add(url.hash); + //const reqBody = req.body ? await req.text() : null; + + console.log("→ Path:", pathname); + console.log("→ Auth:", req.headers.get("authorization")); + console.log("→ Body:", reqBody); + + const bskyUrl = `https://api.bsky.app${pathname}${url.search}`; + const hasAuth = req.headers.has("authorization"); + const xrpcMethod = pathname.startsWith("/xrpc/") + ? pathname.slice("/xrpc/".length) + : null; + + //if (xrpcMethod !== 'app.bsky.actor.getPreferences' && xrpcMethod !== 'app.bsky.notification.listNotifications') { + if ( + (!hasAuth || + xrpcMethod === "app.bsky.labeler.getServices" || + xrpcMethod === "app.bsky.unspecced.getConfig") && + xrpcMethod !== "app.bsky.notification.putPreferences" + ) { + const proxyHeaders = new Headers(req.headers); + + // Remove Authorization and set browser-like User-Agent + proxyHeaders.delete("authorization"); + proxyHeaders.delete("Access-Control-Allow-Origin"), + proxyHeaders.set( + "user-agent", + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36" + ); + proxyHeaders.set("Access-Control-Allow-Origin", "*"); + + const proxyRes = await fetch(bskyUrl, { + method: req.method, + headers: proxyHeaders, + body: ["GET", "HEAD"].includes(req.method.toUpperCase()) + ? undefined + : reqBody, + }); + + const resBody = await proxyRes.text(); + + console.log( + "← Response:", + JSON.stringify(await JSON.parse(resBody), null, 2) + ); + + return new Response(resBody, { + status: proxyRes.status, + headers: proxyRes.headers, + }); + } + + const authDID = "did:plc:mn45tewwnse5btfftvd3powc"; //getAuthenticatedDid(req); + + const jsonUntyped = jsonbody; + + switch (xrpcMethod) { + case "app.bsky.actor.getPreferences": { + const jsonTyped = + jsonUntyped as XRPCTypes.AppBskyActorGetPreferences.QueryParams; + // if (!(await authDID)) + // return new Response("Unauthorized", { status: 401 }); + + const response: XRPCTypes.AppBskyActorGetPreferences.OutputSchema = { + preferences: [ + { + $type: "app.bsky.actor.defs#savedFeedsPrefV2", + items: [ + { + $type: "app.bsky.actor.defs#savedFeed", + id: "3l6wlykrwdk2w", + type: "feed", + value: + "at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot", + pinned: true, + }, + ], + }, + { + $type: "app.bsky.actor.defs#savedFeedsPref", + pinned: [ + "at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot", + ], + saved: [ + "at://did:plc:z72i7hdynmk6r22z27h6tvur/app.bsky.feed.generator/whats-hot", + ], + }, + { + $type: "app.bsky.actor.defs#bskyAppStatePref", + nuxs: [ + { + $type: "app.bsky.actor.defs#nux", + id: "TenMillionDialog", + completed: true, + }, + { id: "NeueTypography", completed: true }, + { id: "NeueChar", completed: true }, + { id: "InitialVerificationAnnouncement", completed: true }, + { id: "ActivitySubscriptions", completed: true }, + { id: "PolicyUpdate202508", completed: true }, + ], + }, + ], + }; + // { + // preferences: [ + // { + // $type: "app.bsky.actor.defs#savedFeedsPref", + // pinned: [""], + // saved: [""], + // }, + // ], + // }; + + if (preferences === undefined) { + preferences = response.preferences; + } + + const newprefswowowowow: XRPCTypes.AppBskyActorGetPreferences.OutputSchema = + { + preferences: preferences, + }; + + return new Response(JSON.stringify(newprefswowowowow), { + headers: withCors({ "Content-Type": "application/json" }), + }); + } + case "app.bsky.actor.getProfile": { + const jsonTyped = + jsonUntyped as XRPCTypes.AppBskyActorGetProfile.QueryParams; + + const response: XRPCTypes.AppBskyActorGetProfile.OutputSchema = { + $type: "app.bsky.actor.defs#profileViewDetailed", + did: "did:plc:mn45tewwnse5btfftvd3powc", + handle: "whey.party", + displayName: "Whey!?@??#?", + description: "idiot piece of shit", + avatar: + "https://cdn.bsky.app/img/feed_thumbnail/plain/did:plc:mn45tewwnse5btfftvd3powc/bafkreid4nhd5pdbzqshkcfxwwcpfz4a5xk2n4gk5truu6hyfk6abynpaze@jpeg", + associated: { + $type: "app.bsky.actor.defs#profileAssociated", + lists: 2, + feedgens: 4, + starterPacks: 6, + labeler: false, + chat: { + $type: "app.bsky.actor.defs#profileAssociatedChat", + allowIncoming: "all", + }, + activitySubscription: { + $type: "app.bsky.actor.defs#profileAssociatedActivitySubscription", + allowSubscriptions: "followers", + }, + }, + indexedAt: "2024-10-23T08:55:16.641Z", + createdAt: "2024-10-23T08:55:16.641Z", + banner: + "https://cdn.bsky.app/img/feed_thumbnail/plain/did:plc:mn45tewwnse5btfftvd3powc/bafkreibqkz2eq3wzpqh44vuicbezckeo6i4g6m66v5ifek5hc5frc6ihdq@jpeg", + followersCount: 69420, + followsCount: 69420, + postsCount: 69420, + //associated?: ProfileAssociated + //joinedViaStarterPack?: AppBskyGraphDefs.StarterPackViewBasic + //indexedAt?: string + //createdAt?: string + viewer: { + $type: "app.bsky.actor.defs#viewerState", + muted: false, + //mutedByList: AppBskyGraphDefs.ListViewBasic + blockedBy: false, + //blocking?: string + //blockingByList?: AppBskyGraphDefs.ListViewBasic + //following?: string + //followedBy?: string + //knownFollowers?: KnownFollowers + activitySubscription: { + $type: "app.bsky.notification.defs#activitySubscription", + post: true, + reply: true, + }, + }, + labels: [ + { + $type: "com.atproto.label.defs#label", + /** The AT Protocol version of the label object. */ + ver: 1, + /** DID of the actor who created this label. */ + src: "did:plc:ar7c4by46qjdydhdevvrndac", + /** AT URI of the record, repository (account), or other resource that this label applies to. */ + uri: "at://did:plc:ar7c4by46qjdydhdevvrndac", + /** Optionally, CID specifying the specific version of 'uri' resource this label applies to. */ + //cid?: string + /** The short string name of the value or type of this label. */ + val: "idiot", + /** If true, this is a negation label, overwriting a previous label. */ + //neg?: boolean + /** Timestamp when this label was created. */ + cts: "2024-10-23T08:55:16.641Z", + /** Timestamp at which this label expires (no longer applies). */ + //exp?: string + /** Signature of dag-cbor encoded label. */ + //sig?: Uint8Array + }, + ], + pinnedPost: { + $type: "com.atproto.repo.strongRef", + uri: "at://did:plc:mn45tewwnse5btfftvd3powc/app.bsky.feed.post/3lvybv7b6ic2h", + cid: "bafyreie44fqjarvwv3n3se6fhpf2mvodlguiwahqh7ugm3nyyujlmd36ce", + }, + verification: { + $type: "app.bsky.actor.defs#verificationState", + /** All verifications issued by trusted verifiers on behalf of this user. Verifications by untrusted verifiers are not included. */ + verifications: [ + { + $type: "app.bsky.actor.defs#verificationView", + /** The user who issued this verification. */ + issuer: "did:plc:ar7c4by46qjdydhdevvrndac", + /** The AT-URI of the verification record. */ + uri: "at://did:plc:mn45tewwnse5btfftvd3powc/app.bsky.feed.post/3lvybv7b6ic2h", + /** True if the verification passes validation, otherwise false. */ + isValid: true, + /** Timestamp when the verification was created. */ + createdAt: "2024-10-23T08:55:16.641Z", + }, + ], + /** The user's status as a verified account. */ + verifiedStatus: "valid", + /** The user's status as a trusted verifier. */ + trustedVerifierStatus: "valid", + }, + status: { + $type: "app.bsky.actor.defs#statusView", + /** The status for the account. */ + status: "app.bsky.actor.status#live", + record: { + $type: "app.bsky.graph.verification", + createdAt: "2025-05-02T18:12:17.199Z", + displayName: "teq (lowercase)", + handle: "quilling.dev", + subject: "did:plc:jrtgsidnmxaen4offglr5lsh", + }, + //embed?: $Typed | { $type: string } + /** The date when this status will expire. The application might choose to no longer return the status after expiration. */ + expiresAt: "2028-10-23T08:55:16.641Z", + /** True if the status is not expired, false if it is expired. Only present if expiration was set. */ + isActive: true, + }, + }; + + return new Response(JSON.stringify(response), { + headers: withCors({ "Content-Type": "application/json" }), + }); + } + case "app.bsky.actor.getProfiles": { + const jsonTyped = + jsonUntyped as XRPCTypes.AppBskyActorGetProfiles.QueryParams; + + const response: XRPCTypes.AppBskyActorGetProfiles.OutputSchema = { + profiles: [ + { + $type: "app.bsky.actor.defs#profileViewDetailed", + did: "did:plc:mn45tewwnse5btfftvd3powc", + handle: "whey.party", + displayName: "Whey!?@??#?", + description: "idiot piece of shit", + avatar: + "https://cdn.bsky.app/img/feed_thumbnail/plain/did:plc:mn45tewwnse5btfftvd3powc/bafkreid4nhd5pdbzqshkcfxwwcpfz4a5xk2n4gk5truu6hyfk6abynpaze@jpeg", + //associated?: ProfileAssociated + indexedAt: "2024-10-23T08:55:16.641Z", + createdAt: "2024-10-23T08:55:16.641Z", + //banner?: string + followersCount: 69420, + followsCount: 69420, + postsCount: 69420, + //associated?: ProfileAssociated + //joinedViaStarterPack?: AppBskyGraphDefs.StarterPackViewBasic + //indexedAt?: string + //createdAt?: string + //viewer?: ViewerState + //labels?: ComAtprotoLabelDefs.Label[] + //pinnedPost?: ComAtprotoRepoStrongRef.Main + //verification?: VerificationState + //status?: StatusView + }, + ], + }; + + return new Response(JSON.stringify(response), { + headers: withCors({ "Content-Type": "application/json" }), + }); + } + case "app.bsky.notification.listNotifications": { + const jsonTyped = + jsonUntyped as XRPCTypes.AppBskyNotificationListNotifications.QueryParams; + + const response: XRPCTypes.AppBskyNotificationListNotifications.OutputSchema = + { + notifications: [ + { + $type: "app.bsky.notification.listNotifications#notification", + uri: "at://did:plc:mn45tewwnse5btfftvd3powc/app.bsky.feed.post/3lvybv7b6ic2h", + cid: "bafyreie44fqjarvwv3n3se6fhpf2mvodlguiwahqh7ugm3nyyujlmd36ce", + author: { + $type: "app.bsky.actor.defs#profileView", + did: "did:plc:mn45tewwnse5btfftvd3powc", + handle: "whey.party", + displayName: "Whey!?@??#?", + description: "idiot piece of shit", + avatar: + "https://cdn.bsky.app/img/feed_thumbnail/plain/did:plc:mn45tewwnse5btfftvd3powc/bafkreid4nhd5pdbzqshkcfxwwcpfz4a5xk2n4gk5truu6hyfk6abynpaze@jpeg", + //associated?: ProfileAssociated + indexedAt: "2024-10-23T08:55:16.641Z", + createdAt: "2024-10-23T08:55:16.641Z", + viewer: { + $type: "app.bsky.actor.defs#viewerState", + muted: false, + //mutedByList?: AppBskyGraphDefs.ListViewBasic + //blockedBy?: boolean + //blocking?: string + //blockingByList?: AppBskyGraphDefs.ListViewBasic + //following?: string + //followedBy?: string + //knownFollowers?: KnownFollowers + //activitySubscription?: AppBskyNotificationDefs.ActivitySubscription + }, + //labels?: ComAtprotoLabelDefs.Label[] + //verification?: VerificationState + //status?: StatusView + }, + reason: "follow", + //reasonSubject?: string + record: { + $type: "app.bsky.graph.follow", + subject: "did:plc:lulmyldiq4sb2ikags5sfb25", + createdAt: "2025-08-12T04:58:14.657Z", + }, + isRead: false, + indexedAt: "2024-10-23T08:55:16.641Z", + //labels?: ComAtprotoLabelDefs.Label[] + }, + ], + }; + + return new Response(JSON.stringify(response), { + headers: withCors({ "Content-Type": "application/json" }), + }); + } + case "app.bsky.notification.putPreferences": { + if (jsonbody) { + const body = jsonbody; + //console.log("Body:", body); + preferences = body.preferences; + } + + const response: XRPCTypes.AppBskyUnspeccedGetConfig.OutputSchema = { + checkEmailConfirmed: true, + liveNow: [ + { + $type: "app.bsky.unspecced.getConfig#liveNowConfig", + did: "did:plc:mn45tewwnse5btfftvd3powc", + domains: ["local3768forumtest.whey.party"], + }, + ], + }; + + return new Response(JSON.stringify(response), { + headers: withCors({ "Content-Type": "application/json" }), + }); + + // const response: XRPCTypes.AppBskyActorPutPreferences.OutputSchema = + // undefined; + return new Response(`{"hello":"world"}`, { + status: 200, + headers: withCors(), + }); + } + case "app.bsky.actor.putPreferencesshittyholleeeheoeoelelllo": { + if (jsonbody) { + const body = jsonbody; + //console.log("Body:", body); + preferences = body.preferences; + } + + const response: XRPCTypes.AppBskyUnspeccedGetConfig.OutputSchema = { + checkEmailConfirmed: true, + liveNow: [ + { + $type: "app.bsky.unspecced.getConfig#liveNowConfig", + did: "did:plc:mn45tewwnse5btfftvd3powc", + domains: ["local3768forumtest.whey.party"], + }, + ], + }; + + return new Response(JSON.stringify(response), { + headers: withCors({ "Content-Type": "application/json" }), + }); + + // const response: XRPCTypes.AppBskyActorPutPreferences.OutputSchema = + // undefined; + return new Response(`{"hello":"world"}`, { + status: 200, + headers: withCors(), + }); + } + case "chat.bsky.convo.getLog": { + const jsonTyped = + jsonUntyped as XRPCTypes.ChatBskyConvoGetLog.QueryParams; + + const response: XRPCTypes.ChatBskyConvoGetLog.OutputSchema = { + logs: [], + }; + + return new Response(JSON.stringify(response), { + headers: withCors({ "Content-Type": "application/json" }), + }); + } + case "chat.bsky.convo.listConvos": { + const jsonTyped = + jsonUntyped as XRPCTypes.ChatBskyConvoListConvos.QueryParams; + + const response: XRPCTypes.ChatBskyConvoListConvos.OutputSchema = { + convos: [], + }; + + return new Response(JSON.stringify(response), { + headers: withCors({ "Content-Type": "application/json" }), + }); + } + case "app.bsky.unspecced.getConfig": { + const jsonTyped = + jsonUntyped as XRPCTypes.AppBskyUnspeccedGetConfig.QueryParams; + + const response: XRPCTypes.AppBskyUnspeccedGetConfig.OutputSchema = { + checkEmailConfirmed: true, + liveNow: [ + { + $type: "app.bsky.unspecced.getConfig#liveNowConfig", + did: "did:plc:mn45tewwnse5btfftvd3powc", + domains: ["local3768forumtest.whey.party"], + }, + ], + }; + + return new Response(JSON.stringify(response), { + headers: withCors({ "Content-Type": "application/json" }), + }); + } + case "app.bsky.graph.getLists": { + const jsonTyped = + jsonUntyped as XRPCTypes.AppBskyGraphGetLists.QueryParams; + + const response: XRPCTypes.AppBskyGraphGetLists.OutputSchema = { + lists: [], + }; + + return new Response(JSON.stringify(response), { + headers: withCors({ "Content-Type": "application/json" }), + }); + } + //https://shimeji.us-east.host.bsky.network/xrpc/app.bsky.unspecced.getTrendingTopics?limit=14 + case "app.bsky.unspecced.getTrendingTopics": { + const jsonTyped = + jsonUntyped as XRPCTypes.AppBskyUnspeccedGetTrendingTopics.QueryParams; + + const response: XRPCTypes.AppBskyUnspeccedGetTrendingTopics.OutputSchema = + { + topics: [ + { + $type: "app.bsky.unspecced.defs#trendingTopic", + topic: "coolio", + displayName: "coolio", + description: "coolio", + link: "https://custom-appview.deer-social.pages.dev/lists", + }, + ], + suggested: [ + { + $type: "app.bsky.unspecced.defs#trendingTopic", + topic: "coolio", + displayName: "coolio", + description: "coolio", + link: "https://custom-appview.deer-social.pages.dev/lists", + }, + ], + }; + + return new Response(JSON.stringify(response), { + headers: withCors({ "Content-Type": "application/json" }), + }); + } + default: { + return new Response( + JSON.stringify({ + error: "XRPCNotSupported", + message: "HEY hello there my name is whey dot party and you have used my custom appview that is very cool but have you considered that XRPC Not Supported", + }), + { + status: 404, + headers: withCors({ "Content-Type": "application/json" }), + } + ); + } + } }); +function withCors(headers: HeadersInit = {}) { + return { + "Access-Control-Allow-Origin": "*", + ...headers, + }; +} +const corsfree = { + "Access-Control-Allow-Origin": "*", + "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS", + "Access-Control-Allow-Headers": "Content-Type, Authorization", +}; +const json = "application/json"; + + // ------------------------------------------ // Indexer // ------------------------------------------ diff --git a/utils/auth.ts b/utils/auth.ts index 60969c4..66144c7 100644 --- a/utils/auth.ts +++ b/utils/auth.ts @@ -1,4 +1,8 @@ -import { AuthResult, MethodAuthVerifier, XRPCError } from "npm:@atproto/xrpc-server"; +import { + AuthResult, + MethodAuthVerifier, + XRPCError, +} from "npm:@atproto/xrpc-server"; import * as borrowed from "./auth.borrowed.ts"; export interface AuthConfig { @@ -18,14 +22,20 @@ export function setupAuth(config: AuthConfig) { console.log("Authentication module initialized."); } -export async function getAuthenticatedDid(req: Request): Promise { +export async function getAuthenticatedDid( + req: Request +): Promise { const authHeader = req.headers.get("Authorization"); return await internalGetAuthenticatedDid(authHeader ?? undefined); } -async function internalGetAuthenticatedDid(authHeader: string | undefined): Promise { +async function internalGetAuthenticatedDid( + authHeader: string | undefined +): Promise { if (!isInitialized) { - console.error("Authentication module has not been initialized. Call setupAuth() first."); + console.error( + "Authentication module has not been initialized. Call setupAuth() first." + ); return null; } if (!authHeader || !authHeader.startsWith("Bearer ")) { @@ -44,21 +54,32 @@ async function internalGetAuthenticatedDid(authHeader: string | undefined): Prom return result.payload.iss as string; } catch (err) { - console.warn("JWT verification failed:", err instanceof Error ? err.message : String(err)); + console.warn( + "JWT verification failed:", + err instanceof Error ? err.message : String(err) + ); return null; } } export const authVerifier: MethodAuthVerifier = async ({ req }) => { - console.log("help us all fuck you",req) - const authHeader = (req as any).headers['authorization']; - + //console.log("help us all fuck you",req) + console.log("you are doing well") + const url = (req as any).url; + const params = (req as any).params ?? {}; + console.log("Request info:", { url, params }); + return { + credentials: "did:plc:mn45tewwnse5btfftvd3powc", + }; + const authHeader = (req as any).headers["authorization"]; + const did = await internalGetAuthenticatedDid(authHeader); - if (!did) { - // i dont know the correct xrpc spec for this - throw new XRPCError(401, 'AuthenticationRequired', 'Invalid or missing authentication token.'); - } + // throw this later dont do it here + // if (!did) { + // // i dont know the correct xrpc spec for this + // throw new XRPCError(401, 'AuthenticationRequired', 'Invalid or missing authentication token.'); + // } console.log(`Successfully authenticated DID: ${did}`); @@ -67,4 +88,4 @@ export const authVerifier: MethodAuthVerifier = async ({ req }) => { did: did, }, }; -}; \ No newline at end of file +}; diff --git a/utils/dbsetup.ts b/utils/dbsetup.ts index 5d034bf..0507167 100644 --- a/utils/dbsetup.ts +++ b/utils/dbsetup.ts @@ -26,6 +26,27 @@ export default function dbsetup(){ handle TEXT ); ${createIndexINE} idx_did_handle ON did(handle); + + ${createTableINE} prefs ( + did TEXT PRIMARY KEY NOT NULL, + json TEXT + ); + ${createIndexINE} idx_prefs_did ON prefs(did); + + ${createTableINE} backlink_skeleton ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + srcuri TEXT, + srcdid TEXT, + srcfield TEXT, + srccol TEXT, + suburi TEXT, + subdid TEXT, + subcol TEXT + ); + ${createIndexINE} idx_backlink_subdid_mod ON backlink_skeleton(subdid, srcdid); + ${createIndexINE} idx_backlink_suburi_mod ON backlink_skeleton(suburi, srcdid); + ${createIndexINE} idx_backlink_subdid_filter_mod ON backlink_skeleton(subdid, srccol, srcdid); + ${createIndexINE} idx_backlink_suburi_filter_mod ON backlink_skeleton(suburi, srccol, srcdid); ${createTableINE} app_bsky_actor_profile ( ${baseColumns},