diff --git a/config.ts b/config.ts index cadb68c..310af7e 100644 --- a/config.ts +++ b/config.ts @@ -23,7 +23,6 @@ export interface ServerConfigValues { videoCdn?: string; mediaCdn?: string; - thumbCdn?: string; dbUri?: string; dbName?: string; @@ -67,7 +66,6 @@ export class ServerConfig { const videoCdn = envStr("SPRK_VIDEO_CDN") ?? "https://video.sprk.so"; const mediaCdn = envStr("SPRK_MEDIA_CDN") ?? "https://media.sprk.so"; - const thumbCdn = envStr("SPRK_THUMB_CDN") ?? "https://thumb.sprk.so"; const dbUri = envStr("SPRK_DB_URI") ?? "mongodb://mongo:mongo@localhost:27017/dev"; @@ -102,7 +100,6 @@ export class ServerConfig { notificationsDelayMs, videoCdn, mediaCdn, - thumbCdn, dbUri, dbName, dbUser, @@ -170,10 +167,6 @@ export class ServerConfig { get mediaCdn() { return this.cfg.mediaCdn; } - get thumbCdn() { - return this.cfg.thumbCdn; - } - get dbUri() { return this.cfg.dbUri; } diff --git a/main.ts b/main.ts index ad3324d..2e79cc3 100644 --- a/main.ts +++ b/main.ts @@ -56,7 +56,6 @@ export function setupApp(): { app: Hono; ctx: AppContext } { indexedAtEpoch: cfg.indexedAtEpoch, videoCdn: cfg.videoCdn, mediaCdn: cfg.mediaCdn, - thumbCdn: cfg.thumbCdn, }); const authVerifier = createAuthVerifier(dataplane, { diff --git a/tests/stories_test.ts b/tests/stories_test.ts index 4f9e1db..ef8d6fc 100644 --- a/tests/stories_test.ts +++ b/tests/stories_test.ts @@ -510,7 +510,6 @@ Deno.test({ const views = new Views({ mediaCdn: "https://media.example.com", - thumbCdn: "https://thumb.example.com", videoCdn: "https://video.example.com", }); @@ -591,7 +590,6 @@ Deno.test({ const views = new Views({ mediaCdn: "https://media.example.com", - thumbCdn: "https://thumb.example.com", videoCdn: "https://video.example.com", }); @@ -653,7 +651,6 @@ Deno.test({ const views = new Views({ mediaCdn: "https://media.example.com", - thumbCdn: "https://thumb.example.com", videoCdn: "https://video.example.com", }); @@ -732,7 +729,6 @@ Deno.test({ const views = new Views({ mediaCdn: "https://media.example.com", - thumbCdn: "https://thumb.example.com", videoCdn: "https://video.example.com", }); diff --git a/tests/views_test.ts b/tests/views_test.ts new file mode 100644 index 0000000..31d4ad0 --- /dev/null +++ b/tests/views_test.ts @@ -0,0 +1,31 @@ +import { assertEquals } from "@std/assert"; +import { parseCid } from "@atp/lex/data"; +import * as so from "../lex/so.ts"; +import { Views } from "../views/index.ts"; + +const DID = "did:plc:testuser"; +const CID = "bafyreihdwdcefgh4dqkjv67uzcmw7ojee6xedzdetojuzjevtenxquvyku"; + +const videoMedia = so.sprk.media.video.$build({ + video: { + $type: "blob", + ref: parseCid(CID), + mimeType: "video/mp4", + size: 12345, + }, +}); + +Deno.test("video view serves playlists and thumbnails from the video service", () => { + const views = new Views({ videoCdn: "https://video.example.com" }); + + const view = views.videoMedia(DID, videoMedia); + + assertEquals( + view.playlist, + `https://video.example.com/watch/${DID}/${CID}/playlist.m3u8`, + ); + assertEquals( + view.thumbnail, + `https://video.example.com/watch/${DID}/${CID}/thumbnail.jpg`, + ); +}); diff --git a/views/index.ts b/views/index.ts index 107437b..bec1f8c 100644 --- a/views/index.ts +++ b/views/index.ts @@ -96,20 +96,17 @@ export class Views { private videoCdn: string; private mediaCdn: string; - private thumbCdn: string; constructor( opts: { indexedAtEpoch?: Date | undefined; videoCdn?: string; mediaCdn?: string; - thumbCdn?: string; }, ) { this.indexedAtEpoch = opts?.indexedAtEpoch; this.videoCdn = opts?.videoCdn ?? "https://video.sprk.so"; this.mediaCdn = opts?.mediaCdn ?? "https://media.sprk.so"; - this.thumbCdn = opts?.thumbCdn ?? "https://thumb.sprk.so"; } // Labels @@ -1057,8 +1054,9 @@ export class Views { ): VideoMediaView & { $type: string } { const cid = cidFromBlobJson(media.video); - const playlist = `${this.videoCdn}/watch/${did}/${cid}/playlist.m3u8`; - const thumbnail = `${this.thumbCdn}/${did}/${cid}/thumbnail`; + const videoUrl = `${this.videoCdn}/watch/${did}/${cid}`; + const playlist = `${videoUrl}/playlist.m3u8`; + const thumbnail = `${videoUrl}/thumbnail.jpg`; return { $type: "so.sprk.media.video#view", diff --git a/views/util.ts b/views/util.ts index d3fcda8..40a0db2 100644 --- a/views/util.ts +++ b/views/util.ts @@ -9,11 +9,6 @@ type BlobJson = BlobRef | { cid?: string; }; -// Simple string format function to replace util.format -const format = (template: string, ...args: string[]): string => { - return template.replace(/%s/g, () => args.shift() || ""); -}; - export const cidFromBlobJson = (json: BlobJson) => { // @NOTE below handles the fact that parseRecordBytes() produces raw json rather than lexicon values if (json.$type === "blob") { @@ -22,26 +17,3 @@ export const cidFromBlobJson = (json: BlobJson) => { } return "cid" in json ? json.cid ?? "" : ""; }; - -export class VideoUriBuilder { - constructor( - private opts: { - playlistUrlPattern: string; // e.g. https://hostname/vid/%s/%s/playlist.m3u8 - thumbnailUrlPattern: string; // e.g. https://hostname/vid/%s/%s/thumbnail.jpg - }, - ) {} - playlist({ did, cid }: { did: string; cid: string }) { - return format( - this.opts.playlistUrlPattern, - encodeURIComponent(did), - encodeURIComponent(cid), - ); - } - thumbnail({ did, cid }: { did: string; cid: string }) { - return format( - this.opts.thumbnailUrlPattern, - encodeURIComponent(did), - encodeURIComponent(cid), - ); - } -}