diff --git a/src/meta.ts b/src/classes/Meta.ts similarity index 100% rename from src/meta.ts rename to src/classes/Meta.ts diff --git a/src/classes/SubscribeFilters.ts b/src/classes/SubscribeFilters.ts index faea67b..e7ac6b8 100644 --- a/src/classes/SubscribeFilters.ts +++ b/src/classes/SubscribeFilters.ts @@ -2,19 +2,26 @@ export default class SubscribeFilters { collections?: string[]; dids?: string[]; mimeTypes?: string[]; + pdses?: string[]; constructor( collections?: string[] | undefined, dids?: string[] | undefined, mimeTypes?: string[] | undefined, + pdses?: string[] | undefined ) { this.collections = collections && collections.length ? Array.from(new Set(collections)) : undefined; - this.dids = dids && dids.length ? Array.from(new Set(dids)) : undefined; + this.dids = dids && dids.length + ? Array.from(new Set(dids)) + : undefined; this.mimeTypes = mimeTypes && mimeTypes.length ? Array.from(new Set(mimeTypes)) : undefined; + this.pdses = pdses && pdses.length + ? Array.from(new Set(pdses)) + : undefined; } private static splitParamValues(values: string[]): string[] { @@ -25,20 +32,19 @@ export default class SubscribeFilters { } static fromSearchParams(params: URLSearchParams): SubscribeFilters { - const collections = SubscribeFilters.splitParamValues( - params.getAll("wantedCollections"), - ); + const collections = SubscribeFilters.splitParamValues(params.getAll("wantedCollections")); const dids = SubscribeFilters.splitParamValues(params.getAll("wantedDids")); - const mimeTypes = SubscribeFilters.splitParamValues( - params.getAll("wantedMimeTypes"), - ); - return new SubscribeFilters(collections, dids, mimeTypes); + const mimeTypes = SubscribeFilters.splitParamValues(params.getAll("wantedMimeTypes")); + const pdses = SubscribeFilters.splitParamValues(params.getAll("wantedPdses")) + .map(p => `https://${p.replace(/^\/+/, '')}`); + return new SubscribeFilters(collections, dids, mimeTypes, pdses); } matches(data: any): boolean { const col = data?.source?.collection; const did = data?.source?.did; const mtype = data?.blob?.mimeType; + const pds = data?.source?.pds; const matchesCollection = !this.collections || (col !== undefined && this.collections.includes(col)); @@ -46,17 +52,18 @@ export default class SubscribeFilters { (did !== undefined && this.dids.includes(did)); const matchesMimeType = !this.mimeTypes || (mtype !== undefined && this.mimeTypes.includes(mtype)); + const matchesPds = !this.pdses || + (pds !== undefined && this.pdses.includes(pds)); - return matchesCollection && matchesDid && matchesMimeType; + return matchesCollection && matchesDid && matchesMimeType && matchesPds; } toString(): string { const parts: string[] = []; - if (this.collections) { - parts.push(`collection=${this.collections.join(",")}`); - } + if (this.collections) parts.push(`collection=${this.collections.join(",")}`); if (this.dids) parts.push(`did=${this.dids.join(",")}`); if (this.mimeTypes) parts.push(`mimeType=${this.mimeTypes.join(",")}`); + if (this.pdses) parts.push(`pds=${this.pdses.join(",")}`) return parts.length ? parts.join(", ") : "any"; } } \ No newline at end of file diff --git a/src/services.ts b/src/services.ts index 6cf6863..609fb83 100644 --- a/src/services.ts +++ b/src/services.ts @@ -1,5 +1,5 @@ import SubscribeFilters from "./classes/SubscribeFilters.ts"; -import Meta from "./meta.ts"; +import Meta from "./classes/Meta.ts"; import { args, didPdsCache, stats } from "./store.ts"; export async function parseEvent(e: MessageEvent) { @@ -70,6 +70,8 @@ WebSocket endpoint at /subscribe. Filter with queries: (e.g. did:plc:z72i7hdynmk6r22z27h6tvur, did:web:didd.uk) * wantedMimeTypes — MimeType(s) to filter by (e.g. image/jpeg, video/mp4) +* wantedPdses — PDS(es) to filter by (without protocol) + (e.g. shimeji.us-east.host.bsky.network, zio.blue) 🐑 @zio.sh/blobstream ・ ${Meta.version}