diff --git a/pkgs/api/src/index.ts b/pkgs/api/src/index.ts index 2acbd9e..9330b96 100644 --- a/pkgs/api/src/index.ts +++ b/pkgs/api/src/index.ts @@ -55,7 +55,7 @@ app.get<{ Params: { "*": string } }>( urls.push(urls.at(-1)?.slice(0, -4) as string); } - urls = urls.map((url) => decodeURIComponent(url)); + urls = urls.map((url) => decodeURIComponent(url)).map((url) => url.replaceAll('\uFFFD', '')); const result = await Promise.allSettled( urls.map((url) => fetch(url).then((res) => res.arrayBuffer())) @@ -72,11 +72,11 @@ app.get<{ Params: { "*": string } }>( const video = await tsToMpeg4(buffers); - const fileName = `video-${new Date().toUTCString()}.mp4`; + // const fileName = `video-${new Date().toUTCString()}.mp4`; res.header("Content-Type", "video/mp4"); res.header("Cache-Control", "public, max-age=604800"); - res.header("Content-Disposition", `attachment; filename=${fileName}`); + // res.header("Content-Disposition", `attachment; filename=${fileName}`); res.send(video); } ); diff --git a/pkgs/api/tsconfig.json b/pkgs/api/tsconfig.json index 287a349..ea31308 100644 --- a/pkgs/api/tsconfig.json +++ b/pkgs/api/tsconfig.json @@ -8,6 +8,7 @@ "skipLibCheck": true, "moduleResolution": "NodeNext", "outDir": "./dist", + "lib": ["ESNext"] }, "include": ["./src/**/*.ts"], } diff --git a/pkgs/app/src/components/Post.tsx b/pkgs/app/src/components/Post.tsx index 3fab498..9eab0cb 100644 --- a/pkgs/app/src/components/Post.tsx +++ b/pkgs/app/src/components/Post.tsx @@ -37,8 +37,6 @@ const Video = ({ // Discord can't handle query params in the URL, so i have to do this 🔥beautiful mess🔥 const url = `${apiUrl}generate/${btoa(join(streamInfo.uri, ";"))}.mp4`; - console.log(url); - return ( <> @@ -113,8 +111,6 @@ export const Post = ({ const isAuthor = images === post.author.avatar; const description = parseEmbedDescription(post); - console.log(post); - return ( diff --git a/pkgs/app/src/index.ts b/pkgs/app/src/index.ts index 4520a70..6ab92a2 100644 --- a/pkgs/app/src/index.ts +++ b/pkgs/app/src/index.ts @@ -13,7 +13,9 @@ app.use("*", async (c, next) => { const agent = new BskyAgent({ service: c.env.BSKY_SERVICE_URL, async persistSession(_, session) { - return c.env.bskyx.put("session", JSON.stringify(session)); + if (session) { + return c.env.bskyx.put("session", JSON.stringify(session)); + } }, }); try { diff --git a/pkgs/app/src/lib/processVideoEmbed.ts b/pkgs/app/src/lib/processVideoEmbed.ts index 3ad4f72..b7d2db8 100644 --- a/pkgs/app/src/lib/processVideoEmbed.ts +++ b/pkgs/app/src/lib/processVideoEmbed.ts @@ -15,8 +15,19 @@ export interface M3U8Data { streams: StreamInfo[]; } -export async function processVideoEmbed(post: AppBskyFeedDefs.PostView) { - const videoUrl = post.embed?.playlist as string | undefined; +export interface VideoMedia { + $type: `app.bsky.embed.video${string}`; + cid: string; + playlist: string; + thumbnail: string; + aspectRatio: { + width: number; + height: number; + } +} + +export async function processVideoEmbed(source?: VideoMedia | undefined) { + const videoUrl = source?.playlist as string | undefined; if (!videoUrl) { return; diff --git a/pkgs/app/src/lib/utils.ts b/pkgs/app/src/lib/utils.ts index 257be6d..dc6f1a1 100644 --- a/pkgs/app/src/lib/utils.ts +++ b/pkgs/app/src/lib/utils.ts @@ -10,3 +10,6 @@ export const concatQueryParams = (params: Record) => export const join = (t: string | string[], s: string) => Array.isArray(t) ? t.join(s) : t; + +export const checkType = (t: string, o: any) => + (typeof o.$type === "string" && o.$type.startsWith(t)) || o.$type === t; diff --git a/pkgs/app/src/routes/getOEmbed.ts b/pkgs/app/src/routes/getOEmbed.ts index 0f7b545..9bd9fad 100644 --- a/pkgs/app/src/routes/getOEmbed.ts +++ b/pkgs/app/src/routes/getOEmbed.ts @@ -10,8 +10,6 @@ export const getOEmbed: Handler = async (c) => { const type = +(c.req.query("type") ?? 0); const avatar = c.req.query("avatar"); - console.log(type); - const defaults = { provider_name: "VixBluesky", provider_url: "https://bskyx.app/", diff --git a/pkgs/app/src/routes/getPost.tsx b/pkgs/app/src/routes/getPost.tsx index b94a331..6263c27 100644 --- a/pkgs/app/src/routes/getPost.tsx +++ b/pkgs/app/src/routes/getPost.tsx @@ -2,7 +2,8 @@ import { Handler } from "hono"; import { HTTPException } from "hono/http-exception"; import { fetchPost } from "../lib/fetchPostData"; import { Post } from "../components/Post"; -import { processVideoEmbed, StreamInfo } from "../lib/processVideoEmbed"; +import { processVideoEmbed, StreamInfo, VideoMedia } from "../lib/processVideoEmbed"; +import { checkType } from "../lib/utils"; export const getPost: Handler< Env, @@ -12,7 +13,6 @@ export const getPost: Handler< const agent = c.get("Agent"); const { data, success } = await fetchPost(agent, { user, post }); - console.log(data); if (!success) { throw new HTTPException(500, { message: "Failed to fetch the post!", @@ -24,10 +24,11 @@ export const getPost: Handler< let videoMetaData: StreamInfo[] | undefined; if ( - typeof fetchedPost.embed?.$type === "string" && - fetchedPost.embed?.$type.startsWith("app.bsky.embed.video") + checkType("app.bsky.embed.video", fetchedPost.embed) || + checkType("app.bsky.embed.video", fetchedPost.embed?.media) ) { - videoMetaData = await processVideoEmbed(fetchedPost); + // @ts-expect-error + videoMetaData = await processVideoEmbed(fetchedPost.embed?.media || fetchedPost.embed); } return c.html(