Better fallback

This commit is contained in:
Manav Rathi
2025-04-03 18:55:55 +05:30
parent aa422889f3
commit f0b8e3b4af
3 changed files with 14 additions and 5 deletions

View File

@@ -236,6 +236,10 @@ export const uploadItemFileName = (uploadItem: UploadItem) => {
/* -- Various intermediate type used during upload -- */
export type ExternalParsedMetadata = ParsedMetadata & {
creationTime?: number | undefined;
};
export interface UploadAsset {
/** `true` if this is a live photo. */
isLivePhoto?: boolean;
@@ -254,7 +258,7 @@ export interface UploadAsset {
*
* This will not be present for live photos.
*/
externalParsedMetadata?: ParsedMetadata;
externalParsedMetadata?: ExternalParsedMetadata;
}
interface ThumbnailedFile {
@@ -973,7 +977,7 @@ const extractLivePhotoMetadata = async (
const extractImageOrVideoMetadata = async (
uploadItem: UploadItem,
externalParsedMetadata: ParsedMetadata | undefined,
externalParsedMetadata: ExternalParsedMetadata | undefined,
fileTypeInfo: FileTypeInfo,
lastModifiedMs: number,
collectionID: number,
@@ -983,7 +987,7 @@ const extractImageOrVideoMetadata = async (
const fileName = uploadItemFileName(uploadItem);
const { fileType } = fileTypeInfo;
let parsedMetadata: ParsedMetadata | undefined;
let parsedMetadata: (ParsedMetadata & ExternalParsedMetadata) | undefined;
if (fileType == FileType.image) {
parsedMetadata = await tryExtractImageMetadata(
uploadItem,
@@ -1026,6 +1030,8 @@ const extractImageOrVideoMetadata = async (
creationTime = timestamp;
publicMagicMetadata.dateTime = dateTime;
if (offset) publicMagicMetadata.offsetTime = offset;
} else if (parsedMetadata.creationTime) {
creationTime = parsedMetadata.creationTime;
} else {
creationTime =
tryParseEpochMicrosecondsFromFileName(fileName) ?? modificationTime;

View File

@@ -472,11 +472,14 @@ class UploadManager {
? { timestamp, dateTime, offset }
: undefined;
// Fallback to the timestamp if a creationDate could not be constructed.
const creationTime = creationDate ? undefined : timestamp;
const item = {
uploadItem: file,
localID: 1,
collectionID: collection.id,
externalParsedMetadata: { creationDate },
externalParsedMetadata: { creationDate, creationTime },
};
return this.uploadItems([item], [collection]);

View File

@@ -778,7 +778,7 @@ export interface ParsedMetadata {
* Logically this is a date in local timezone of the place where the photo
* was taken. See: [Note: Photos are always in local date/time].
*/
creationDate?: ParsedMetadataDate;
creationDate?: ParsedMetadataDate | undefined;
/** The GPS coordinates where the photo was taken. */
location?: Location;
/**