From ef4f54a5c077e10f16792e74f9e60fb21ac0c696 Mon Sep 17 00:00:00 2001 From: 8-prime Date: Tue, 20 May 2025 11:16:53 +0200 Subject: [PATCH 1/4] Handle never expire and infinite download cases properly in text --- frontend/src/pages/FileView.tsx | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/FileView.tsx b/frontend/src/pages/FileView.tsx index 1e1a58e..02b0b17 100644 --- a/frontend/src/pages/FileView.tsx +++ b/frontend/src/pages/FileView.tsx @@ -11,6 +11,9 @@ const FileView = (): JSX.Element => { const { downloadInfo, error, isLoading } = useDownloadInfo(uploadId) const remainingDownloads = useMemo(() => { if (!downloadInfo) return undefined + if (downloadInfo.metadata.maxDownloads === -1) { + return Infinity + } return downloadInfo.metadata.maxDownloads - downloadInfo.metadata.currentDownloads }, [downloadInfo]) @@ -29,20 +32,38 @@ const FileView = (): JSX.Element => { return `/api/upload/${uploadId}/archive` } + + const getDownloadInfoString = () : string => { + if(isLoading || error){ + return "" + } + if(remainingDownloads === Infinity){ + return "You can download this file infinitely often" + } + return `You can download this file ${remainingDownloadsremainingDownloads} more time${remainingDownloads > 1 && "s"}` + } + + const getExpirationString = () : string => { + if (downloadInfo.metadata.expires === -1 ){ + return "This upload will never expire" + } + return `This upload will expire on ${expiration}` + } + return (
- Download File{remainingDownloads !== 1 && "s"} + Download File{(downloadInfo?.files.length ?? 0) > 1 && "s"} {isLoading && } {!isLoading && !error && !!remainingDownloads &&

- You can download this file {remainingDownloads} more time{remainingDownloads !== 1 && "s"} + {getDownloadInfoString()}

}
@@ -77,7 +98,7 @@ const FileView = (): JSX.Element => { )} {!isLoading && !error &&
-

This upload will expire on {expiration}

+

{getExpirationString()}

} From bf6b971c2fb2afb00a91d6050e4bfa9014e89933 Mon Sep 17 00:00:00 2001 From: 8-prime Date: Tue, 20 May 2025 11:28:06 +0200 Subject: [PATCH 2/4] fix incorrect variable name --- frontend/src/pages/FileView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/FileView.tsx b/frontend/src/pages/FileView.tsx index 02b0b17..d7a94ad 100644 --- a/frontend/src/pages/FileView.tsx +++ b/frontend/src/pages/FileView.tsx @@ -40,7 +40,7 @@ const FileView = (): JSX.Element => { if(remainingDownloads === Infinity){ return "You can download this file infinitely often" } - return `You can download this file ${remainingDownloadsremainingDownloads} more time${remainingDownloads > 1 && "s"}` + return `You can download this file ${remainingDownloads} more time${remainingDownloads > 1 && "s"}` } const getExpirationString = () : string => { From 1dba5223b3b7e657f6226b162bfc07d48234d327 Mon Sep 17 00:00:00 2001 From: 8-prime Date: Tue, 20 May 2025 11:28:47 +0200 Subject: [PATCH 3/4] handle null safety --- frontend/src/pages/FileView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/FileView.tsx b/frontend/src/pages/FileView.tsx index d7a94ad..3261a69 100644 --- a/frontend/src/pages/FileView.tsx +++ b/frontend/src/pages/FileView.tsx @@ -40,7 +40,7 @@ const FileView = (): JSX.Element => { if(remainingDownloads === Infinity){ return "You can download this file infinitely often" } - return `You can download this file ${remainingDownloads} more time${remainingDownloads > 1 && "s"}` + return `You can download this file ${remainingDownloads} more time${(remainingDownloads ?? 0) > 1 && "s"}` } const getExpirationString = () : string => { From d76f9a931b6dc0dc51a466148c70cafeb0672817 Mon Sep 17 00:00:00 2001 From: 8-prime Date: Tue, 20 May 2025 11:30:57 +0200 Subject: [PATCH 4/4] More null safety --- frontend/src/pages/FileView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/pages/FileView.tsx b/frontend/src/pages/FileView.tsx index 3261a69..ab69735 100644 --- a/frontend/src/pages/FileView.tsx +++ b/frontend/src/pages/FileView.tsx @@ -44,7 +44,7 @@ const FileView = (): JSX.Element => { } const getExpirationString = () : string => { - if (downloadInfo.metadata.expires === -1 ){ + if (downloadInfo?.metadata.expires === -1 ){ return "This upload will never expire" } return `This upload will expire on ${expiration}`