π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
More tsc fixes
Manav Rathibafa3b5c5b08
diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsxindex 6888c92b90..105d55a610 100644--- a/web/apps/photos/src/components/Upload.tsx+++ b/web/apps/photos/src/components/Upload.tsx@@ -1,3 +1,4 @@+// TODO: Too many null assertions in this file. The types need reworking.// TODO: Audit this file/* eslint-disable @typescript-eslint/no-misused-promises */import ChevronRightIcon from "@mui/icons-material/ChevronRight";@@ -272,7 +273,9 @@ export const Upload: React.FC<UploadProps> = ({* If set, this will be the name of the collection that our desktop app* wishes for us to upload into.*/- const pendingDesktopUploadCollectionName = useRef<string>("");+ const pendingDesktopUploadCollectionName = useRef<string | undefined>(+ undefined,+ );/*** This is set to thue user's choice when the user chooses one of the@@ -368,6 +371,8 @@ export const Upload: React.FC<UploadProps> = ({setInProgressUploads,setFinishedUploads,setUploadPhase,+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment+ // @ts-ignoresetUploadFilenames: setUploadFileNames,setHasLivePhotos,setUploadProgressView,@@ -503,7 +508,7 @@ export const Upload: React.FC<UploadProps> = ({);uploadItemsAndPaths.current = prunedItemAndPaths;- if (uploadItemsAndPaths.current.length === 0) {+ if (uploadItemsAndPaths.current.length == 0) {props.setLoading(false);return;}@@ -518,15 +523,15 @@ export const Upload: React.FC<UploadProps> = ({log.debug(() => ["Import suggestion", importSuggestion]);const _selectedUploadType = selectedUploadType.current;- selectedUploadType.current = null;+ selectedUploadType.current = undefined;props.setLoading(false);(async () => {if (publicCollectionGalleryContext.credentials) {setUploaderName(- await savedPublicCollectionUploaderName(+ (await savedPublicCollectionUploaderName(publicCollectionGalleryContext.credentials.accessToken,- ),+ )) ?? "",);showUploaderNameInput();return;@@ -539,7 +544,7 @@ export const Upload: React.FC<UploadProps> = ({"root",pendingDesktopUploadCollectionName.current,);- pendingDesktopUploadCollectionName.current = null;+ pendingDesktopUploadCollectionName.current = undefined;} else {uploadFilesToNewCollections("parent");}@@ -579,7 +584,7 @@ export const Upload: React.FC<UploadProps> = ({};}- onOpenCollectionSelector({+ onOpenCollectionSelector?.({action: "upload",onSelectCollection: uploadFilesToExistingCollection,onCreateCollection: showNextModal,@@ -613,7 +618,7 @@ export const Upload: React.FC<UploadProps> = ({[collection],uploaderName,);- uploadItemsAndPaths.current = null;+ uploadItemsAndPaths.current = [];};const uploadFilesToNewCollections = async (@@ -628,7 +633,9 @@ export const Upload: React.FC<UploadProps> = ({>();if (mapping == "root") {collectionNameToUploadItems.set(- collectionName,+ // Un-enforced convention is that collectionName is always set+ // when mapping is "root". TODO: Reflect this in types.+ collectionName!,uploadItemsAndPaths.current,);} else {@@ -668,7 +675,7 @@ export const Upload: React.FC<UploadProps> = ({return;}await waitInQueueAndUploadFiles(uploadItemsWithCollection, collections);- uploadItemsAndPaths.current = null;+ uploadItemsAndPaths.current = [];};const waitInQueueAndUploadFiles = async (@@ -719,7 +726,7 @@ export const Upload: React.FC<UploadProps> = ({collections,uploadItemsWithCollection.map(({ uploadItem }) => uploadItem)- .filter((x) => x),+ .filter((x) => x !== undefined),);}const wereFilesProcessed = await uploadManager.uploadItems(@@ -825,14 +832,14 @@ export const Upload: React.FC<UploadProps> = ({const handlePublicUpload = (uploaderName: string) => {savePublicCollectionUploaderName(- publicCollectionGalleryContext.credentials.accessToken,+ publicCollectionGalleryContext.credentials!.accessToken,uploaderName,);// Do not keep the uploader name input dialog open while the upload is// progressing (the upload progress indicator will take out now).void uploadFilesToExistingCollection(- props.uploadCollection,+ props.uploadCollection!,uploaderName,);};@@ -871,7 +878,7 @@ export const Upload: React.FC<UploadProps> = ({open={uploadProgressView}onClose={closeUploadProgress}percentComplete={percentComplete}- uploadFileNames={uploadFileNames}+ uploadFileNames={uploadFileNames!}uploadCounter={uploadCounter}uploadPhase={uploadPhase}inProgressUploads={inProgressUploads}@@ -892,7 +899,7 @@ export const Upload: React.FC<UploadProps> = ({open={uploaderNameInputVisibilityProps.open}onClose={handleUploaderNameInputClose}uploaderName={uploaderName}- uploadFileCount={uploadItemsAndPaths.current?.length ?? 0}+ uploadFileCount={uploadItemsAndPaths.current.length}onSubmit={handlePublicUpload}/></>@@ -984,7 +991,7 @@ const defaultImportSuggestion: ImportSuggestion = {};const deriveImportSuggestion = (- uploadType: UploadType,+ uploadType: UploadType | undefined,paths: string[],): ImportSuggestion => {if (isDesktop && uploadType == "files") {@@ -996,8 +1003,8 @@ const deriveImportSuggestion = ();const separatorCount = (s: string) => separatorCounts.get(s)!;paths.sort((path1, path2) => separatorCount(path1) - separatorCount(path2));- const firstPath = paths[0];- const lastPath = paths[paths.length - 1];+ const firstPath = paths[0]!;+ const lastPath = paths[paths.length - 1]!;const L = firstPath.length;let i = 0;@@ -1020,7 +1027,7 @@ const deriveImportSuggestion = (}return {- rootFolderName: commonPathPrefix || null,+ rootFolderName: commonPathPrefix || "",hasNestedFolders: firstFileFolder !== lastFileFolder,};};@@ -1074,7 +1081,7 @@ const setPendingUploads = async (and on next upload we can directly start uploading to this collection*/if (collections.length == 1) {- collectionName = collections[0].name;+ collectionName = collections[0]!.name;}const filePaths: string[] = [];diff --git a/web/apps/photos/src/services/upload-manager.ts b/web/apps/photos/src/services/upload-manager.tsindex e5d61f6170..e4d0d4e6a1 100644--- a/web/apps/photos/src/services/upload-manager.ts+++ b/web/apps/photos/src/services/upload-manager.ts@@ -1,3 +1,4 @@+// TODO: Too many null assertions in this file. The types need reworking.import { ensureLocalUser } from "ente-accounts/services/user";import { isDesktop } from "ente-base/app";import { createComlinkCryptoWorker } from "ente-base/crypto";@@ -96,6 +97,8 @@ export type UploadItemWithCollection = UploadAsset & {};class UIService {+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment+ // @ts-ignoreprivate progressUpdater: ProgressUpdater;// UPLOAD LEVEL STATES@@ -105,9 +108,9 @@ class UIService {private uploadProgressView = false;// STAGE LEVEL STATES- private perFileProgress: number;- private filesUploadedCount: number;- private totalFilesCount: number;+ private perFileProgress = 0;+ private filesUploadedCount = 0;+ private totalFilesCount = 0;private inProgressUploads: InProgressUploads = new Map();private finishedUploads: FinishedUploads = new Map();@@ -243,7 +246,7 @@ const groupByResult = (finishedUploads: FinishedUploads) => {const groups: SegregatedFinishedUploads = new Map();for (const [localID, result] of finishedUploads) {if (!groups.has(result)) groups.set(result, []);- groups.get(result).push(localID);+ groups.get(result)!.push(localID);}return groups;};@@ -251,13 +254,13 @@ const groupByResult = (finishedUploads: FinishedUploads) => {class UploadManager {private comlinkCryptoWorkers: ComlinkWorker<typeof CryptoWorker>[] =new Array(maxConcurrentUploads);- private parsedMetadataJSONMap: Map<string, ParsedMetadataJSON>;- private itemsToBeUploaded: ClusteredUploadItem[];- private failedItems: ClusteredUploadItem[];- private existingFiles: EnteFile[];- private onUploadFile: (file: EnteFile) => void;- private collections: Map<number, Collection>;- private uploadInProgress: boolean;+ private parsedMetadataJSONMap = new Map<string, ParsedMetadataJSON>();+ private itemsToBeUploaded: ClusteredUploadItem[] = [];+ private failedItems: ClusteredUploadItem[] = [];+ private existingFiles: EnteFile[] = [];+ private onUploadFile: ((file: EnteFile) => void) | undefined;+ private collections = new Map<number, Collection>();+ private uploadInProgress = false;private publicAlbumsCredentials: PublicAlbumsCredentials | undefined;private uploaderName: string | undefined;/**@@ -481,14 +484,14 @@ class UploadManager {await UploadService.setFileCount(mediaItems.length);this.uiService.setUploadPhase("uploading");- const uploadProcesses = [];+ const uploadProcesses = new Array<Promise<void>>();for (let i = 0;i < maxConcurrentUploads && this.itemsToBeUploaded.length > 0;i++) {this.comlinkCryptoWorkers[i] = createComlinkCryptoWorker();- const worker = await this.comlinkCryptoWorkers[i].remote;+ const worker = await this.comlinkCryptoWorkers[i]!.remote;uploadProcesses.push(this.uploadNextItemInQueue(worker));}await Promise.all(uploadProcesses);@@ -508,9 +511,9 @@ class UploadManager {this.abortIfCancelled();logAboutMemoryPressureIfNeeded();- const clusteredItem = this.itemsToBeUploaded.pop();+ const clusteredItem = this.itemsToBeUploaded.pop()!;const { localID, collectionID } = clusteredItem;- const collection = this.collections.get(collectionID);+ const collection = this.collections.get(collectionID)!;const uploadableItem = { ...clusteredItem, collection };uiService.setFileProgress(localID, 0);@@ -605,7 +608,7 @@ class UploadManager {private updateExistingFiles(file: EnteFile) {this.existingFiles.push(file);- this.onUploadFile(file);+ this.onUploadFile!(file);}/**@@ -668,8 +671,8 @@ const makeUploadItemWithCollectionIDAndName = (localID: f.localID!,collectionID: f.collectionID!,fileName: (f.isLivePhoto- ? uploadItemFileName(f.livePhotoAssets.image)- : uploadItemFileName(f.uploadItem))!,+ ? uploadItemFileName(f.livePhotoAssets!.image)+ : uploadItemFileName(f.uploadItem!))!,isLivePhoto: f.isLivePhoto,uploadItem: f.uploadItem,pathPrefix: f.pathPrefix,@@ -689,7 +692,10 @@ const splitMetadataAndMediaItems = (else media.push(f);return [metadata, media];},- [[], []],+ [+ new Array<UploadItemWithCollectionIDAndName>(),+ new Array<UploadItemWithCollectionIDAndName>(),+ ],);/**@@ -710,22 +716,22 @@ const clusterLivePhotos = async (.sort((f, g) => f.collectionID - g.collectionID);let index = 0;while (index < items.length - 1) {- const f = items[index];- const g = items[index + 1];- const fFileType = potentialFileTypeFromExtension(f.fileName);- const gFileType = potentialFileTypeFromExtension(g.fileName);+ const f = items[index]!;+ const g = items[index + 1]!;+ const fFileType = potentialFileTypeFromExtension(f.fileName)!;+ const gFileType = potentialFileTypeFromExtension(g.fileName)!;const fa: PotentialLivePhotoAsset = {fileName: f.fileName,fileType: fFileType,collectionID: f.collectionID,- uploadItem: f.uploadItem,+ uploadItem: f.uploadItem!,pathPrefix: f.pathPrefix,};const ga: PotentialLivePhotoAsset = {fileName: g.fileName,fileType: gFileType,collectionID: g.collectionID,- uploadItem: g.uploadItem,+ uploadItem: g.uploadItem!,pathPrefix: g.pathPrefix,};if (await areLivePhotoAssets(fa, ga, parsedMetadataJSONMap)) {@@ -738,8 +744,8 @@ const clusterLivePhotos = async (isLivePhoto: true,pathPrefix: image.pathPrefix,livePhotoAssets: {- image: image.uploadItem,- video: video.uploadItem,+ image: image.uploadItem!,+ video: video.uploadItem!,},});index += 2;