Merge branch 'public-album-styling' into bug-fix-public-sharing

This commit is contained in:
Abhinav 2022-01-28 11:51:55 +05:30
commit eb714a145b
14 changed files with 418 additions and 379 deletions

View file

@ -1,6 +1,6 @@
{
"name": "bada-frame",
"version": "0.4.3",
"version": "0.4.4",
"private": true,
"scripts": {
"dev": "next dev",

View file

@ -238,7 +238,9 @@ export default function Sidebar(props: Props) {
onHide={() => setRecoveryModalView(false)}
somethingWentWrong={() =>
props.setDialogMessage({
title: constants.RECOVER_KEY_GENERATION_FAILED,
title: constants.ERROR,
content:
constants.RECOVER_KEY_GENERATION_FAILED,
close: { variant: 'danger' },
})
}

View file

@ -129,10 +129,7 @@ const InProgressSection = (props: InProgressProps) => {
<FileList>
{fileList.map(({ fileName, progress }) => (
<li key={fileName}>
{constants.FILE_UPLOAD_PROGRESS(
fileName,
progress
)}
{`${fileName} - ${progress}%`}
</li>
))}
</FileList>
@ -235,7 +232,7 @@ export default function UploadProgress(props: Props) {
/>
<ResultSection
fileUploadResultMap={fileUploadResultMap}
fileUploadResult={FileUploadResults.SKIPPED}
fileUploadResult={FileUploadResults.ALREADY_UPLOADED}
sectionTitle={constants.SKIPPED_FILES}
sectionInfo={constants.SKIPPED_INFO}
/>

View file

@ -37,7 +37,7 @@ function GoToEnte() {
if (os === OS.ANDROID || os === OS.IOS) {
return constants.INSTALL;
} else {
return constants.SIGNUP_OR_LOGIN;
return constants.SIGN_UP;
}
};

View file

@ -30,11 +30,11 @@ export enum UPLOAD_STAGES {
}
export enum FileUploadResults {
FAILED = -1,
SKIPPED = -2,
UNSUPPORTED = -3,
BLOCKED = -4,
TOO_LARGE = -5,
LARGER_THAN_AVAILABLE_STORAGE = -6,
UPLOADED = 100,
FAILED,
ALREADY_UPLOADED,
UNSUPPORTED,
BLOCKED,
TOO_LARGE,
LARGER_THAN_AVAILABLE_STORAGE,
UPLOADED,
}

View file

@ -24,8 +24,16 @@ class DownloadManager {
}
if (!this.thumbnailObjectURLPromise.get(file.id)) {
const downloadPromise = async () => {
const thumbnailCache = await caches.open('thumbs');
const cacheResp: Response = await thumbnailCache.match(
const thumbnailCache = await (async () => {
try {
return await caches.open('thumbs');
} catch (e) {
return null;
// ignore
}
})();
const cacheResp: Response = await thumbnailCache?.match(
file.id.toString()
);
if (cacheResp) {
@ -34,7 +42,7 @@ class DownloadManager {
const thumb = await this.downloadThumb(token, file);
const thumbBlob = new Blob([thumb]);
try {
await thumbnailCache.put(
await thumbnailCache?.put(
file.id.toString(),
new Response(thumbBlob)
);

View file

@ -1,4 +1,5 @@
import {
FileUploadResults,
RANDOM_PERCENTAGE_PROGRESS_FOR_PUT,
UPLOAD_STAGES,
} from 'constants/upload';
@ -9,7 +10,7 @@ class UIService {
private filesUploaded: number;
private totalFileCount: number;
private fileProgress: Map<string, number>;
private uploadResult: Map<string, number>;
private uploadResult: Map<string, FileUploadResults>;
private progressUpdater: ProgressUpdater;
init(progressUpdater: ProgressUpdater) {
@ -47,8 +48,8 @@ class UIService {
this.updateProgressBarUI();
}
moveFileToResultList(filename: string) {
this.uploadResult.set(filename, this.fileProgress.get(filename));
moveFileToResultList(filename: string, uploadResult: FileUploadResults) {
this.uploadResult.set(filename, uploadResult);
this.fileProgress.delete(filename);
this.updateProgressBarUI();
}

View file

@ -185,7 +185,11 @@ class UploadManager {
this.failedFiles.push(fileWithCollection);
}
UIService.moveFileToResultList(fileWithCollection.file.name);
UIService.moveFileToResultList(
fileWithCollection.file.name,
fileUploadResult
);
UploadService.reducePendingUploadCount();
}
}

View file

@ -36,6 +36,10 @@ class UploadService {
await this.preFetchUploadURLs();
}
reducePendingUploadCount() {
this.pendingUploadCount--;
}
async readFile(
worker: any,
reader: FileReader,

View file

@ -1,5 +1,4 @@
import { EnteFile } from 'types/file';
import { sleep } from 'utils/common';
import { handleUploadError, CustomError } from 'utils/error';
import { decryptFile } from 'utils/file';
import { logError } from 'utils/sentry';
@ -22,7 +21,6 @@ import {
import { FILE_TYPE } from 'constants/file';
import { FileUploadResults } from 'constants/upload';
const TwoSecondInMillSeconds = 2000;
const FIVE_GB_IN_BYTES = 5 * 1024 * 1024 * 1024;
interface UploadResponse {
fileUploadResult: FileUploadResults;
@ -46,12 +44,6 @@ export default async function uploader(
try {
if (rawFile.size >= FIVE_GB_IN_BYTES) {
UIService.setFileProgress(
rawFile.name,
FileUploadResults.TOO_LARGE
);
// wait two second before removing the file from the progress in file section
await sleep(TwoSecondInMillSeconds);
return { fileUploadResult: FileUploadResults.TOO_LARGE };
}
fileTypeInfo = await getFileType(reader, rawFile);
@ -65,10 +57,7 @@ export default async function uploader(
);
if (fileAlreadyInCollection(existingFilesInCollection, metadata)) {
UIService.setFileProgress(rawFile.name, FileUploadResults.SKIPPED);
// wait two second before removing the file from the progress in file section
await sleep(TwoSecondInMillSeconds);
return { fileUploadResult: FileUploadResults.SKIPPED };
return { fileUploadResult: FileUploadResults.ALREADY_UPLOADED };
}
file = await UploadService.readFile(
@ -105,7 +94,6 @@ export default async function uploader(
const uploadedFile = await UploadHttpClient.uploadFile(uploadFile);
const decryptedFile = await decryptFile(uploadedFile, collection.key);
UIService.setFileProgress(rawFile.name, FileUploadResults.UPLOADED);
UIService.increaseFileUploaded();
return {
fileUploadResult: FileUploadResults.UPLOADED,
@ -118,32 +106,15 @@ export default async function uploader(
const error = handleUploadError(e);
switch (error.message) {
case CustomError.ETAG_MISSING:
UIService.setFileProgress(
rawFile.name,
FileUploadResults.BLOCKED
);
return { fileUploadResult: FileUploadResults.BLOCKED };
case CustomError.UNSUPPORTED_FILE_FORMAT:
UIService.setFileProgress(
rawFile.name,
FileUploadResults.UNSUPPORTED
);
return { fileUploadResult: FileUploadResults.UNSUPPORTED };
case CustomError.FILE_TOO_LARGE:
UIService.setFileProgress(
rawFile.name,
FileUploadResults.LARGER_THAN_AVAILABLE_STORAGE
);
return {
fileUploadResult:
FileUploadResults.LARGER_THAN_AVAILABLE_STORAGE,
};
default:
UIService.setFileProgress(
rawFile.name,
FileUploadResults.FAILED
);
return { fileUploadResult: FileUploadResults.FAILED };
}
} finally {

View file

@ -72,13 +72,21 @@ export const setRecoveryKey = (token: string, recoveryKey: RecoveryKey) =>
});
export const logoutUser = async () => {
// ignore server logout result as logoutUser can be triggered before sign up or on token expiry
await _logout();
clearKeys();
clearData();
await caches.delete('thumbs');
await clearFiles();
router.push(PAGES.ROOT);
try {
// ignore server logout result as logoutUser can be triggered before sign up or on token expiry
await _logout();
clearKeys();
clearData();
try {
await caches.delete('thumbs');
} catch (e) {
// ignore
}
await clearFiles();
router.push(PAGES.ROOT);
} catch (e) {
logError(e, 'logoutUser failed');
}
};
export const clearFiles = async () => {

View file

@ -4,7 +4,6 @@ import localForage from 'localforage';
if (runningInBrowser()) {
localForage.config({
driver: localForage.INDEXEDDB,
name: 'ente-files',
version: 1.0,
storeName: 'files',

View file

@ -109,26 +109,6 @@ const englishConstants = {
},
UPLOADING_FILES: 'file upload',
FILE_NOT_UPLOADED_LIST: 'the following files were not uploaded',
FILE_UPLOAD_PROGRESS: (name: string, progress: number) => (
<div id={name}>
{name}
{' - '}
<span style={{ color: '#eee' }}>
{(() => {
switch (progress) {
case -1:
return 'failed';
case -2:
return 'already uploaded, skipping...';
case -3:
return 'unsupported file format, skipping....';
default:
return `${progress}%`;
}
})()}
</span>
</div>
),
SUBSCRIPTION_EXPIRED: (action) => (
<>
your subscription has expired, please a{' '}
@ -636,7 +616,6 @@ const englishConstants = {
REPORT_SUBMIT_SUCCESS_TITLE: 'report sent',
REPORT_SUBMIT_FAILED: 'failed to sent report, try again',
INSTALL: 'install',
SIGNUP_OR_LOGIN: 'signup / login',
ALBUM_URL: 'album url',
PUBLIC_SHARING: 'public sharing',
NOT_FOUND: '404 - not found',

662
yarn.lock

File diff suppressed because it is too large Load diff