From aa70b2a437eee54a92e23f4e4f4795f31beb29a4 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Tue, 27 May 2025 13:20:49 +0530 Subject: [PATCH] spl --- web/apps/photos/src/components/Upload.tsx | 5 +++-- web/packages/gallery/services/upload/index.ts | 16 ++++++++++++++++ .../gallery/services/upload/upload-service.ts | 18 +++++++++++++++--- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/web/apps/photos/src/components/Upload.tsx b/web/apps/photos/src/components/Upload.tsx index 6eacfd8266..ffa379411c 100644 --- a/web/apps/photos/src/components/Upload.tsx +++ b/web/apps/photos/src/components/Upload.tsx @@ -30,6 +30,7 @@ import type { CollectionMapping, Electron, ZipItem } from "ente-base/types/ipc"; import { useFileInput } from "ente-gallery/components/utils/use-file-input"; import { groupItemsBasedOnParentFolder, + uploadPathPrefix, type FileAndPath, type UploadItem, type UploadItemAndPath, @@ -562,7 +563,7 @@ export const Upload: React.FC = ({ const uploadItemsWithCollection = uploadItemsAndPaths.current.map( ([uploadItem, path], index) => ({ uploadItem, - uploadItemPathPrefix: dirname(path), + uploadItemPathPrefix: uploadPathPrefix(path), localID: index, collectionID: collection.id, }), @@ -614,7 +615,7 @@ export const Upload: React.FC = ({ ...uploadItemsWithCollection, ...uploadItems.map(([uploadItem, path]) => ({ localID: index++, - uploadItemPathPrefix: dirname(path), + uploadItemPathPrefix: uploadPathPrefix(path), collectionID: collection.id, uploadItem, })), diff --git a/web/packages/gallery/services/upload/index.ts b/web/packages/gallery/services/upload/index.ts index 8d340d31be..1df06e4258 100644 --- a/web/packages/gallery/services/upload/index.ts +++ b/web/packages/gallery/services/upload/index.ts @@ -163,9 +163,25 @@ export interface TimestampedFileSystemUploadItem { * * And can thus be used to associate the correct metadata JSON with the * corresponding {@link UploadItem}. + * + * As a special case, "/metadata" at the end of the path prefix is discarded. + * This allows the metadata JSON written by export to be read back in during + * uploads. See: [Note: Fold "metadata" directory into parent folder]. */ export type UploadPathPrefix = string; +/** + * Return the {@link UploadPathPrefix} for the given {@link pathOrName} of an + * item being uploaded. + */ +export const uploadPathPrefix = (pathOrName: string) => { + const folderPath = dirname(pathOrName); + if (basename(folderPath) == exportMetadataDirectoryName) { + return dirname(folderPath); + } + return folderPath; +}; + export type UploadItemAndPath = [UploadItem, string]; /** diff --git a/web/packages/gallery/services/upload/upload-service.ts b/web/packages/gallery/services/upload/upload-service.ts index b05854f530..1241bb5247 100644 --- a/web/packages/gallery/services/upload/upload-service.ts +++ b/web/packages/gallery/services/upload/upload-service.ts @@ -254,14 +254,26 @@ export type ExternalParsedMetadata = ParsedMetadata & { }; export interface UploadAsset { - /** `true` if this is a live photo. */ + /** + * `true` if this is a live photo. + */ isLivePhoto?: boolean; - /* Valid for live photos */ + /** + * The two parts of the live photo being uploaded. + * + * Valid for live photos. + */ livePhotoAssets?: LivePhotoAssets; - /* Valid for non-live photos */ + /** + * The item being uploaded. + * + * Valid for non-live photos. + */ uploadItem?: UploadItem; /** * The path prefix of the uploadItem, if available. + * + * Valid for non-live photos. */ uploadItemPathPrefix?: UploadPathPrefix; /**