From 1cb1c1c179002a99b559910487b202a7c640baa0 Mon Sep 17 00:00:00 2001 From: jingrow Date: Mon, 22 Dec 2025 02:13:14 +0800 Subject: [PATCH] fix: allow image URLs without file extensions --- apps/jingrow/frontend/src/views/HomePage.vue | 11 +++++++++-- .../tools/remove_background/remove_background.vue | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/apps/jingrow/frontend/src/views/HomePage.vue b/apps/jingrow/frontend/src/views/HomePage.vue index 6b52fd3..b55a78b 100644 --- a/apps/jingrow/frontend/src/views/HomePage.vue +++ b/apps/jingrow/frontend/src/views/HomePage.vue @@ -766,10 +766,17 @@ const isValidImageUrl = (url: string): boolean => { if (!url || typeof url !== 'string') return false try { const urlObj = new URL(url) + if (!['http:', 'https:'].includes(urlObj.protocol)) { + return false + } + const pathname = urlObj.pathname.toLowerCase() const imageExtensions = ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.bmp'] - return imageExtensions.some(ext => pathname.endsWith(ext)) || - urlObj.pathname.match(/\.(jpg|jpeg|png|webp|gif|bmp)(\?|$)/i) !== null + + const hasImageExtension = imageExtensions.some(ext => pathname.endsWith(ext)) || + urlObj.pathname.match(/\.(jpg|jpeg|png|webp|gif|bmp)(\?|$)/i) !== null + + return hasImageExtension || pathname.length > 0 } catch { return false } diff --git a/apps/jingrow/frontend/src/views/tools/remove_background/remove_background.vue b/apps/jingrow/frontend/src/views/tools/remove_background/remove_background.vue index 507555e..01616ca 100644 --- a/apps/jingrow/frontend/src/views/tools/remove_background/remove_background.vue +++ b/apps/jingrow/frontend/src/views/tools/remove_background/remove_background.vue @@ -308,10 +308,17 @@ const isValidImageUrl = (url: string): boolean => { if (!url || typeof url !== 'string') return false try { const urlObj = new URL(url) + if (!['http:', 'https:'].includes(urlObj.protocol)) { + return false + } + const pathname = urlObj.pathname.toLowerCase() const imageExtensions = ['.jpg', '.jpeg', '.png', '.webp', '.gif', '.bmp'] - return imageExtensions.some(ext => pathname.endsWith(ext)) || - urlObj.pathname.match(/\.(jpg|jpeg|png|webp|gif|bmp)(\?|$)/i) !== null + + const hasImageExtension = imageExtensions.some(ext => pathname.endsWith(ext)) || + urlObj.pathname.match(/\.(jpg|jpeg|png|webp|gif|bmp)(\?|$)/i) !== null + + return hasImageExtension || pathname.length > 0 } catch { return false }