From e7f50a66674eb5e77fdfc6092b2b7252f83cb014 Mon Sep 17 00:00:00 2001 From: kenilkb Date: Wed, 15 Jul 2026 14:57:45 +0530 Subject: [PATCH] Refactor: Add metadata and thumbnail scraping to External URL tab --- .../assets/components/AssetViewerModal.tsx | 75 ++++++++++++------- .../assets/components/UploadAssetModal.tsx | 55 ++++++++++++-- 2 files changed, 96 insertions(+), 34 deletions(-) diff --git a/Channel-Frontend/src/features/assets/components/AssetViewerModal.tsx b/Channel-Frontend/src/features/assets/components/AssetViewerModal.tsx index 77df3b0..3780f51 100644 --- a/Channel-Frontend/src/features/assets/components/AssetViewerModal.tsx +++ b/Channel-Frontend/src/features/assets/components/AssetViewerModal.tsx @@ -271,35 +271,58 @@ export const AssetViewerModal: React.FC = ({ ) : asset.type === 'url' ? ( -
-
- +
+
+ + + External Web Link Preview + + {asset.url}
-
-

External Resource Portal

-

- This asset points to an external destination outside of the local CDN container. -

-
- {asset.url} +
+
+ {asset.thumbnailUrl ? ( +
+ Web Preview Banner +
+ ) : ( +
+ +
+ )} + +
+

{asset.title}

+ {asset.description ? ( +

{asset.description}

+ ) : ( +

No description provided for this external link.

+ )} +
+ +
+ {(user?.role === 'ADMIN' || asset.isDownloadable || asset.downloadRequests?.[0]?.status === 'APPROVED') ? ( + + Open Website in New Tab + + + ) : ( +
+ Access Restricted: You must request and receive approval from the Administrator to open this external link. +
+ )} +
- - {(user?.role === 'ADMIN' || asset.isDownloadable || asset.downloadRequests?.[0]?.status === 'APPROVED') ? ( - - Open Link in New Tab - - - ) : ( -
- Access Restricted: You must request and receive download approval from the Administrator to open this resource link. -
- )}
) : asset.type.includes('pdf') ? (
diff --git a/Channel-Frontend/src/features/assets/components/UploadAssetModal.tsx b/Channel-Frontend/src/features/assets/components/UploadAssetModal.tsx index 1681361..7596526 100644 --- a/Channel-Frontend/src/features/assets/components/UploadAssetModal.tsx +++ b/Channel-Frontend/src/features/assets/components/UploadAssetModal.tsx @@ -95,6 +95,30 @@ export const UploadAssetModal: React.FC = ({ } }; + const handleFetchUrlDetails = async () => { + if (!uploadUrl) { + error('URL Required', 'Please enter a URL first.'); + return; + } + if (!uploadUrl.startsWith('http')) { + error('Invalid URL', 'Please enter a valid URL starting with http:// or https://'); + return; + } + + setIsScraping(true); + try { + const data = await scrapeCaseStudy(uploadUrl); + setUploadTitle(data.title); + setThumbnailUrl(data.thumbnailUrl || ''); + success('Page Details Fetched', 'Title and banner image successfully retrieved.'); + } catch (err: any) { + console.error('Failed to scrape URL details', err); + error('Failed to retrieve page details', err.response?.data?.error || 'Make sure the URL is accessible.'); + } finally { + setIsScraping(false); + } + }; + const formatBytes = (bytes: number, decimals = 2) => { if (bytes === 0) return '0 Bytes'; const k = 1024; @@ -318,14 +342,29 @@ export const UploadAssetModal: React.FC = ({ ) : uploadTab === 'url' ? (
- setUploadUrl(e.target.value)} - placeholder="https://example.com/partner-docs" - required={uploadTab === 'url'} - className="w-full bg-ink-50 border border-ink-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ink-900/10 text-ink-900 placeholder-ink-400" - /> +
+ setUploadUrl(e.target.value)} + placeholder="https://example.com/partner-docs" + required={uploadTab === 'url'} + className="flex-1 bg-ink-50 border border-ink-200 rounded-lg px-3 py-2 text-sm focus:outline-none focus:ring-2 focus:ring-ink-900/10 text-ink-900 placeholder-ink-400" + /> + +
+ + Fetches title and thumbnail banner image from the target webpage automatically. +
) : (