From 17a659345df7f092699caab9bf1cd16a5eca1fe3 Mon Sep 17 00:00:00 2001 From: notangelmario Date: Tue, 24 Jan 2023 01:45:46 +0200 Subject: [PATCH] Added cover in app page --- components/Container.tsx | 2 +- components/SlideContainer.tsx | 2 +- lib/app.ts | 2 +- routes/app/[id]/index.tsx | 120 ++++++++++++++++++---------------- scripts/update.ts | 16 ++++- 5 files changed, 81 insertions(+), 61 deletions(-) diff --git a/components/Container.tsx b/components/Container.tsx index baca101..7f7be45 100644 --- a/components/Container.tsx +++ b/components/Container.tsx @@ -8,7 +8,7 @@ const Container = (props: Props & JSX.IntrinsicElements["h1"]) => { return (
) { - -
-

- {data.app.name} -

-

- {data.app.author} -

-
-
- - - - {data.userLoggedIn - ? ( - - ) - : ( - - - - )} + + + {data.userLoggedIn + ? ( + + ) + : ( + + + + )} +
@@ -192,7 +201,7 @@ export default function App({ data }: PageProps) { export const handler: Handler = async (_, ctx) => { const { data: app } = await supabase.from("apps") .select( - "id, name, author, description, url, icon, accent_color, screenshots, features, categories, github_url, gitlab_url", + "id, name, author, description, url, icon, cover, accent_color, screenshots, features, categories, github_url, gitlab_url", ) .eq("id", ctx.params.id) .single(); @@ -222,7 +231,6 @@ export const handler: Handler = async (_, ctx) => { const { data: otherApps } = await supabase.from("random_apps") .select("id, name, author, icon") - .containedBy("categories", app.categories) .neq("id", app.id) .limit(5); diff --git a/scripts/update.ts b/scripts/update.ts index 5189cc8..74b0741 100644 --- a/scripts/update.ts +++ b/scripts/update.ts @@ -306,6 +306,18 @@ await Promise.all(apps.map(async (app) => { await clearAppFromStorage(app.id, "covers"); if (cover_url) { + if (cover_url.startsWith("http")) { + cover_url = slashSlashes(cover_url); + } else if (cover_url.startsWith("//")) { + cover_url = "https://" + cover_url.slice(2); + } else if (cover_url.startsWith("/")) { + cover_url = slashSlashes(new URL(app.url).origin) + + "/" + slashSlashes(cover_url); + } else { + cover_url = slashSlashes(manifestParent.join("/")) + + "/" + slashSlashes(cover_url); + } + const cover_blob = await fetch( new URL(cover_url, app.url).href, { @@ -342,8 +354,8 @@ await Promise.all(apps.map(async (app) => { manifest_hash: hash, icon: `${IMAGES_URL}/${app.id}/icon`, icon_original: icon_url, - cover: `${IMAGES_URL}/${app.id}/cover`, - cover_original: cover_url, + cover: cover_url ? `${IMAGES_URL}/${app.id}/cover` : undefined, + cover_original: cover_url || undefined, }) .eq("id", app.id); }