From 61b50df864b5733d32e85f0ce7a7de237292bff7 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 20 Oct 2025 15:32:32 +0000 Subject: [PATCH] viewcontent fix --- src/pages/view-content/index.tsx | 136 +++++++++++++++++++++---------- 1 file changed, 92 insertions(+), 44 deletions(-) diff --git a/src/pages/view-content/index.tsx b/src/pages/view-content/index.tsx index 8f4a221..3a6eeb0 100644 --- a/src/pages/view-content/index.tsx +++ b/src/pages/view-content/index.tsx @@ -52,9 +52,22 @@ export const ViewContentPage = () => { } }, [statusState]); + const haveLicense = useMemo(() => ( + content?.data?.have_licenses?.includes('listen') || + content?.data?.have_licenses?.includes('resale') + ), [content]); + + const contentMime = content?.data?.content_mime ?? null; + const contentKind = content?.data?.display_options?.content_kind ?? null; const mediaUrl = content?.data?.display_options?.content_url ?? null; - const isAudio = Boolean(content?.data?.content_type?.startsWith('audio')); - const isReady = Boolean(mediaUrl); + const isAudio = contentKind === 'audio' || Boolean(content?.data?.content_type?.startsWith('audio')); + const isVideo = contentKind === 'video' || Boolean(content?.data?.content_type?.startsWith('video')); + const isBinary = contentKind === 'binary' || (!isAudio && !isVideo); + const hasInlinePlayer = Boolean(mediaUrl) && (isAudio || isVideo); + const binaryDownloadReady = Boolean(mediaUrl) && isBinary; + const isReadyState = statusState === "ready"; + const previewAvailable = Boolean(content?.data?.display_options?.has_preview); + const coverImage = content?.data?.display_options?.metadata?.image ?? null; const metadataName = content?.data?.display_options?.metadata?.name; const contentTitle = metadataName || content?.data?.encrypted?.title || 'Контент'; const processingDetails = useMemo(() => { @@ -67,6 +80,10 @@ export const ViewContentPage = () => { }; }, [conversionState, statusMessage, uploadState]); + const canDownload = Boolean(mediaUrl) && haveLicense && ((content?.data?.downloadable ?? false) || isBinary); + const binaryAwaitingAccess = isBinary && !binaryDownloadReady; + const isFailed = statusState === "failed"; + const handleBuyContentTON = useCallback(async () => { if (!contentId) { console.error('No content identifier available for purchase'); @@ -185,11 +202,6 @@ export const ViewContentPage = () => { } }, [content, refetchContent]); - const haveLicense = useMemo(() => ( - content?.data?.have_licenses?.includes('listen') || - content?.data?.have_licenses?.includes('resale') - ), [content]); - const hadLicenseRef = useRef(haveLicense); useEffect(() => { @@ -230,11 +242,15 @@ export const ViewContentPage = () => { const handleDwnldContent = async () => { try { const fileUrl = content?.data?.display_options?.content_url; + if (!fileUrl) { + return; + } const fileName = content?.data?.display_options?.metadata?.name || 'content'; - const fileFormat = content?.data?.content_ext || '.raw'; + const rawExt = content?.data?.content_ext ?? 'bin'; + const normalizedExt = rawExt.replace(/^\.+/, ''); await WebApp.downloadFile({ url: fileUrl, - file_name: fileName + '.' + fileFormat, + file_name: `${fileName}.${normalizedExt}`, }); } catch (error) { console.error('Error downloading content:', error); @@ -242,40 +258,56 @@ export const ViewContentPage = () => { }; return ( -
+
{isCongratsModal && } {isErrorModal && } - {isReady && isAudio && - content?.data?.display_options?.metadata?.image && ( -
- {'content_image'} + {coverImage && ( +
+
+
+ {'content +
- )} +
+ )} - {isReady ? ( + {isReadyState ? ( <> - {isAudio ? ( - - ) : ( - + ) : ( + + }} + url={mediaUrl ?? ''} + light={coverImage || undefined} + /> + ) + )} + + {binaryDownloadReady && ( +
+

Файл готов к скачиванию

+

+ {contentMime ? `Тип файла: ${contentMime}` : 'Скачайте оригинальные данные на устройство.'} +

+
)}
@@ -285,26 +317,40 @@ export const ViewContentPage = () => {

+ {binaryAwaitingAccess && ( +
+

Предпросмотр недоступен

+

+ Этот файл нельзя открыть в браузере. Получите доступ, чтобы скачать оригинал на устройство. +

+ {!previewAvailable && ( +

+ Предпросмотр не формируется для бинарных данных. +

+ )} +
+ )} +
- {content?.data?.downloadable && ( + {canDownload && (