From d0c316a9bf999881b8bf0a820ea993ebd728db5d Mon Sep 17 00:00:00 2001 From: Peifan Li Date: Sun, 28 Dec 2025 00:13:21 -0500 Subject: [PATCH] style: Improve code formatting and add error retries --- backend/Dockerfile | 5 +++-- backend/src/server.ts | 30 +++++++++++++++--------------- frontend/src/pages/VideoPlayer.tsx | 10 ++++++++-- 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/backend/Dockerfile b/backend/Dockerfile index e5eb6bf..c1b5c7b 100644 --- a/backend/Dockerfile +++ b/backend/Dockerfile @@ -54,14 +54,15 @@ RUN apk add --no-cache \ pango \ libjpeg-turbo \ giflib \ - librsvg && \ + librsvg \ + ca-certificates && \ ln -sf python3 /usr/bin/python # Install cloudflared (Binary download) ARG TARGETARCH -RUN curl -L --output /usr/local/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${TARGETARCH:-amd64} && \ +RUN curl -L --retry 5 --retry-delay 2 --output /usr/local/bin/cloudflared https://github.com/cloudflare/cloudflared/releases/latest/download/cloudflared-linux-${TARGETARCH:-amd64} && \ chmod +x /usr/local/bin/cloudflared # Install yt-dlp, bgutil-ytdlp-pot-provider, and yt-dlp-ejs for YouTube n challenge solving diff --git a/backend/src/server.ts b/backend/src/server.ts index b1c2491..7518447 100644 --- a/backend/src/server.ts +++ b/backend/src/server.ts @@ -7,10 +7,10 @@ import cors from "cors"; import express from "express"; import path from "path"; import { - CLOUD_THUMBNAIL_CACHE_DIR, - IMAGES_DIR, - SUBTITLES_DIR, - VIDEOS_DIR, + CLOUD_THUMBNAIL_CACHE_DIR, + IMAGES_DIR, + SUBTITLES_DIR, + VIDEOS_DIR, } from "./config/paths"; import { runMigrations } from "./db/migrate"; import { visitorModeMiddleware } from "./middleware/visitorModeMiddleware"; @@ -82,7 +82,7 @@ const startServer = async () => { }, }) ); - + // Serve Frontend Static Files const frontendDist = path.join(__dirname, "../../frontend/dist"); app.use(express.static(frontendDist)); @@ -214,12 +214,12 @@ const startServer = async () => { // SPA Fallback for Frontend app.get("*", (req, res) => { - // Don't serve index.html for API calls that 404 - if (req.path.startsWith('/api') || req.path.startsWith('/cloud')) { - res.status(404).send('Not Found'); - return; - } - res.sendFile(path.join(frontendDist, "index.html")); + // Don't serve index.html for API calls that 404 + if (req.path.startsWith("/api") || req.path.startsWith("/cloud")) { + res.status(404).send("Not Found"); + return; + } + res.sendFile(path.join(frontendDist, "index.html")); }); app.listen(PORT, () => { @@ -247,11 +247,11 @@ const startServer = async () => { const settings = storageService.getSettings(); if (settings.cloudflaredTunnelEnabled) { if (settings.cloudflaredToken) { - cloudflaredService.start(settings.cloudflaredToken); + cloudflaredService.start(settings.cloudflaredToken); } else { - // Quick Tunnel - const port = typeof PORT === 'string' ? parseInt(PORT) : PORT; - cloudflaredService.start(undefined, port); + // Quick Tunnel + const port = typeof PORT === "string" ? parseInt(PORT) : PORT; + cloudflaredService.start(undefined, port); } } }); diff --git a/frontend/src/pages/VideoPlayer.tsx b/frontend/src/pages/VideoPlayer.tsx index 9b2e5fb..d3ee89c 100644 --- a/frontend/src/pages/VideoPlayer.tsx +++ b/frontend/src/pages/VideoPlayer.tsx @@ -613,7 +613,13 @@ const VideoPlayer: React.FC = () => { }; // Get thumbnail URL for poster - const posterUrl = useCloudStorageUrl(video?.thumbnailPath, 'thumbnail'); + // Only load thumbnail from cloud if the video itself is in cloud storage + const isVideoInCloud = video?.videoPath?.startsWith('cloud:') ?? false; + const thumbnailPathForCloud = isVideoInCloud ? video?.thumbnailPath : null; + const posterUrl = useCloudStorageUrl(thumbnailPathForCloud, 'thumbnail'); + const localPosterUrl = !isVideoInCloud && video?.thumbnailPath + ? `${import.meta.env.VITE_BACKEND_URL ?? 'http://localhost:5551'}${video.thumbnailPath}` + : undefined; return ( @@ -622,7 +628,7 @@ const VideoPlayer: React.FC = () => {