Skip to content

armgit / ente

Public Imported from GitHub
0

๐Ÿ’š End-to-end encrypted cloud for everything.

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.ts
index 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.tsx
index 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.json
index 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.json
index 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.json
index 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.ts
index 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,