From 8a278ca0ace8ba1b46515c807f722dfd51b18e6d Mon Sep 17 00:00:00 2001 From: thePR0M3TH3AN <53631862+PR0M3TH3AN@users.noreply.github.com> Date: Fri, 26 Sep 2025 23:46:52 -0400 Subject: [PATCH] Shorten Cloudflare bucket preview text --- js/app.js | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/js/app.js b/js/app.js index a18669a8..6a34a3e6 100644 --- a/js/app.js +++ b/js/app.js @@ -39,6 +39,22 @@ import { } from "./storage/r2-s3.js"; import { initQuickR2Upload } from "./r2-quick.js"; +function truncateMiddle(text, maxLength = 72) { + if (!text || typeof text !== "string") { + return ""; + } + + if (text.length <= maxLength) { + return text; + } + + const ellipsis = "…"; + const charsToShow = maxLength - ellipsis.length; + const front = Math.ceil(charsToShow / 2); + const back = Math.floor(charsToShow / 2); + return `${text.slice(0, front)}${ellipsis}${text.slice(text.length - back)}`; +} + /** * Simple "decryption" placeholder for private videos. */ @@ -1803,7 +1819,21 @@ class bitvidApp { const sampleKey = buildR2Key(npub, { name: "sample.mp4" }); const publicUrl = buildPublicUrl(entry.publicBaseUrl, sampleKey); - el.textContent = `${entry.bucket} • ${publicUrl}`; + const fullPreview = `${entry.bucket} • ${publicUrl}`; + + let displayHostAndPath = truncateMiddle(publicUrl, 96); + try { + const parsed = new URL(publicUrl); + const cleanPath = parsed.pathname.replace(/^\//, ""); + const truncatedPath = truncateMiddle(cleanPath || sampleKey, 48); + displayHostAndPath = `${truncateMiddle(parsed.host, 48)}/${truncatedPath}`; + } catch (err) { + // ignore URL parse issues and fall back to the raw string + } + + const truncatedBucket = truncateMiddle(entry.bucket, 40); + el.textContent = `${truncatedBucket} • ${displayHostAndPath}`; + el.setAttribute("title", fullPreview); } async handleCloudflareUploadSubmit() {