๐ End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
locker-web: clarify hard cap upload failures
Neeraj Gupta639ab86ea08a
diff --git a/web/apps/locker/src/components/createItemDialog/useCreateItemDialogState.ts b/web/apps/locker/src/components/createItemDialog/useCreateItemDialogState.tsindex 12cad44731..547b353667 100644--- a/web/apps/locker/src/components/createItemDialog/useCreateItemDialogState.ts+++ b/web/apps/locker/src/components/createItemDialog/useCreateItemDialogState.ts@@ -9,6 +9,7 @@ import {type LockerUpgradeCTAType,} from "services/locker-errors";import {+ exceedsPaidLockerHardLimit,validateLockerUploadBatch,type LockerUploadLimitState,type LockerUploadPreflightFailure,@@ -500,9 +501,21 @@ export const useCreateItemDialogState = ({effectiveIsProductionEndpoint,);if (preflightFailure) {+ const hitsPaidHardCap = exceedsPaidLockerHardLimit(+ pendingUploadItems.map(({ file }) => file),+ effectiveUserDetails,+ effectiveIsProductionEndpoint,+ );const preflightFailureMessage = (failure: LockerUploadPreflightFailure,) => {+ if (+ hitsPaidHardCap &&+ (failure.reason === "fileCountLimit" ||+ failure.reason === "storageLimit")+ ) {+ return t("uploadLockerHardCapErrorBody");+ }switch (failure.reason) {case "fileCountLimit":return t("uploadFileCountLimitErrorBody");@@ -515,7 +528,9 @@ export const useCreateItemDialogState = ({setError(preflightFailureMessage(preflightFailure));setUpgradeCTAType(- preflightFailure.reason === "fileCountLimit"+ hitsPaidHardCap+ ? null+ : preflightFailure.reason === "fileCountLimit"? "fileCountLimit": preflightFailure.reason === "storageLimit"? "storageLimit"diff --git a/web/apps/locker/src/components/lockerPage/useLockerActions.tsx b/web/apps/locker/src/components/lockerPage/useLockerActions.tsxindex d17ebf5883..c8d1c791d7 100644--- a/web/apps/locker/src/components/lockerPage/useLockerActions.tsx+++ b/web/apps/locker/src/components/lockerPage/useLockerActions.tsx@@ -27,8 +27,10 @@ import {type LockerUploadProgress,} from "services/remote";import {+ LOCKER_FILE_LIMIT_PAID,lockerUploadAllowance,LOCKER_MAX_FILE_SIZE_BYTES,+ LOCKER_STORAGE_LIMIT_PAID_BYTES,type LockerUploadLimitState,type LockerUploadPreflightFailure,} from "services/locker-limits";@@ -123,6 +125,8 @@ interface DropUploadScanOptions {interface DropUploadScanResult {items: LockerUploadCandidate[];preflightFailure?: LockerUploadPreflightFailure;+ scannedNonEmptyFileCount: number;+ scannedTotalSize: number;}type PendingDroppedNode =@@ -215,10 +219,15 @@ const collectUploadCandidatesFromDrop = async (file.webkitRelativePath || file.name,);if (preflightFailure) {- return { items, preflightFailure };+ return {+ items,+ preflightFailure,+ scannedNonEmptyFileCount,+ scannedTotalSize,+ };}}- return { items };+ return { items, scannedNonEmptyFileCount, scannedTotalSize };}while (pendingNodes.length > 0) {@@ -227,7 +236,12 @@ const collectUploadCandidatesFromDrop = async (if (node.type === "file") {const preflightFailure = addFile(node.file, node.relativePath);if (preflightFailure) {- return { items, preflightFailure };+ return {+ items,+ preflightFailure,+ scannedNonEmptyFileCount,+ scannedTotalSize,+ };}continue;}@@ -239,7 +253,12 @@ const collectUploadCandidatesFromDrop = async (: file.name;const preflightFailure = addFile(file, relativePath);if (preflightFailure) {- return { items, preflightFailure };+ return {+ items,+ preflightFailure,+ scannedNonEmptyFileCount,+ scannedTotalSize,+ };}continue;}@@ -265,7 +284,7 @@ const collectUploadCandidatesFromDrop = async (}}- return { items };+ return { items, scannedNonEmptyFileCount, scannedTotalSize };};const collectionIDsForItemMutation = (@@ -398,7 +417,19 @@ export const useLockerActions = ({deleteCollectionDialog ?? deleteCollectionDialogRef.current;const uploadPreflightFailureMessage = useCallback(- (failure: LockerUploadPreflightFailure) => {+ (+ failure: LockerUploadPreflightFailure,+ projectedFileCount: number,+ projectedUsage: number,+ ) => {+ if (+ (projectedFileCount > LOCKER_FILE_LIMIT_PAID ||+ projectedUsage > LOCKER_STORAGE_LIMIT_PAID_BYTES) &&+ (failure.reason === "fileCountLimit" ||+ failure.reason === "storageLimit")+ ) {+ return t("uploadLockerHardCapErrorBody");+ }switch (failure.reason) {case "fileCountLimit":return t("uploadFileCountLimitErrorBody");@@ -849,6 +880,13 @@ export const useLockerActions = ({setToast(uploadPreflightFailureMessage(scanResult.preflightFailure,+ lockerUploadAllowance(+ uploadLimitState.userDetails,+ uploadLimitState.isProductionEndpoint,+ ).currentFileCount ++ scanResult.scannedNonEmptyFileCount,+ uploadLimitState.userDetails.usage ++ scanResult.scannedTotalSize,),);return;diff --git a/web/apps/locker/src/locales/en-US/translation.json b/web/apps/locker/src/locales/en-US/translation.jsonindex a1106453fa..261cdd2a8a 100644--- a/web/apps/locker/src/locales/en-US/translation.json+++ b/web/apps/locker/src/locales/en-US/translation.json@@ -64,6 +64,7 @@"uploadStorageLimitErrorBody": "You've run out of storage space. Free up space to continue uploading.","uploadSubscriptionExpiredErrorBody": "Your Ente Photos subscription has expired. Renew your subscription to continue uploading.","uploadFileCountLimitErrorBody": "You've reached your file limit. Upgrade to a paid plan for more storage.",+ "uploadLockerHardCapErrorBody": "Locker is meant for important files. Even on the paid plan, it is capped at 1,000 items and 10 GB, so this upload won't fit.","uploadFileCountLimitErrorBodyWithUpgrade": "You've reached your file limit. Please <cta>upgrade</cta> to a paid plan.","uploadFileCountLimitErrorToast": "Action failed. You've reached your file limit.","uploadEmptyFileErrorBody": "Empty files can't be uploaded.",diff --git a/web/apps/locker/src/locales/fr-FR/translation.json b/web/apps/locker/src/locales/fr-FR/translation.jsonindex f3685347b3..a7b2c94c35 100644--- a/web/apps/locker/src/locales/fr-FR/translation.json+++ b/web/apps/locker/src/locales/fr-FR/translation.json@@ -50,6 +50,7 @@"uploadStorageLimitErrorBody": "Tu as epuise ton espace de stockage. Libere de l'espace pour continuer a televerser.","uploadSubscriptionExpiredErrorBody": "Ton abonnement Ente Photos a expire. Renouvelle ton abonnement pour continuer a televerser.","uploadFileCountLimitErrorBody": "Tu as atteint ta limite de fichiers. Passe a un forfait payant pour plus de stockage.",+ "uploadLockerHardCapErrorBody": "Locker est destine aux fichiers importants. Meme avec une offre payante, il est limite a 1 000 elements et 10 Go, donc cet envoi ne tiendra pas.","uploadFileCountLimitErrorToast": "Action echouee. Tu as atteint ta limite de fichiers.","uploadEmptyFileErrorBody": "Les fichiers vides ne peuvent pas etre televerses.","uploadFileTooLargeErrorBody": "Ce fichier depasse la taille maximale de telechargement prise en charge de 10 Go.",diff --git a/web/apps/locker/src/locales/ja-JP/translation.json b/web/apps/locker/src/locales/ja-JP/translation.jsonindex 2c6cd05795..217deac4ad 100644--- a/web/apps/locker/src/locales/ja-JP/translation.json+++ b/web/apps/locker/src/locales/ja-JP/translation.json@@ -54,6 +54,7 @@"uploadStorageLimitErrorBody": "ในใใฌใผใธๅฎน้ใไธ่ถณใใฆใใพใใใขใใใญใผใใ็ถใใใซใฏ็ฉบใๅฎน้ใ็ขบไฟใใฆใใ ใใใ","uploadSubscriptionExpiredErrorBody": "Ente Photos ใฎใตใในใฏใชใใทใงใณใฎๆๅนๆ้ใๅใใฆใใพใใใขใใใญใผใใ็ถใใใซใฏๆดๆฐใใฆใใ ใใใ","uploadFileCountLimitErrorBody": "ใใกใคใซๅถ้ใซ้ใใพใใใๆๆใใฉใณใซใขใใใฐใฌใผใใใฆใใใๅคใใฎในใใฌใผใธใๅฉ็จใใฆใใ ใใใ",+ "uploadLockerHardCapErrorBody": "Locker ใฏๅคงไบใชใใกใคใซๅใใงใใๆๆใใฉใณใงใ 1,000 ไปถ / 10 GB ใไธ้ใฎใใใใใฎใขใใใญใผใใฏๅใพใใพใใใ","uploadFileCountLimitErrorToast": "ๆไฝใซๅคฑๆใใพใใใใใกใคใซๅถ้ใซ้ใใฆใใพใใ","uploadEmptyFileErrorBody": "็ฉบใฎใใกใคใซใฏใขใใใญใผใใงใใพใใใ","uploadFileTooLargeErrorBody": "ใใฎใใกใคใซใฏใตใใผใใใใฆใใๆๅคงใขใใใญใผใใตใคใบ10GBใ่ถ ใใฆใใพใใ",diff --git a/web/apps/locker/src/services/locker-limits.ts b/web/apps/locker/src/services/locker-limits.tsindex 10377a4186..ed4cb83409 100644--- a/web/apps/locker/src/services/locker-limits.ts+++ b/web/apps/locker/src/services/locker-limits.ts@@ -2,8 +2,9 @@ import { apiOrigin } from "ente-base/origins";export const LOCKER_FILE_LIMIT_FREE = 100;export const LOCKER_FILE_LIMIT_PAID = 1000;+export const LOCKER_STORAGE_LIMIT_FREE_BYTES = 1 * 1024 * 1024 * 1024;+export const LOCKER_STORAGE_LIMIT_PAID_BYTES = 10 * 1024 * 1024 * 1024;export const LOCKER_MAX_FILE_SIZE_BYTES = 10 * 1024 * 1024 * 1024;-export const LOCKER_STORAGE_BUFFER_BYTES = 20 * 1024 * 1024;const ENTE_PRODUCTION_API_ORIGIN = "https://api.ente.io";@@ -67,12 +68,24 @@ export const lockerUploadAllowance = (maxFileCount,currentFileCount,remainingFileCount: Math.max(maxFileCount - currentFileCount, 0),- freeStorage:- Math.max(userDetails.storageLimit - userDetails.usage, 0) +- LOCKER_STORAGE_BUFFER_BYTES,+ freeStorage: Math.max(userDetails.storageLimit - userDetails.usage, 0),};};+export const exceedsPaidLockerHardLimit = (+ files: File[],+ userDetails: LockerUploadLimitState,+ isProductionEndpoint: boolean,+) => {+ const allowance = lockerUploadAllowance(userDetails, isProductionEndpoint);+ const totalUploadSize = files.reduce((total, file) => total + file.size, 0);++ return (+ allowance.currentFileCount + files.length > LOCKER_FILE_LIMIT_PAID ||+ userDetails.usage + totalUploadSize > LOCKER_STORAGE_LIMIT_PAID_BYTES+ );+};+export const validateLockerUploadBatch = (files: File[],userDetails: LockerUploadLimitState | undefined,