π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Use raw exif - wip 1
Manav Rathi76faf4c1d784
diff --git a/web/apps/photos/src/components/PhotoViewer/index.tsx b/web/apps/photos/src/components/PhotoViewer/index.tsxindex a12fa6db07..e951d6b872 100644--- a/web/apps/photos/src/components/PhotoViewer/index.tsx+++ b/web/apps/photos/src/components/PhotoViewer/index.tsx@@ -18,8 +18,8 @@ import { lowercaseExtension } from "@/base/file";import { FILE_TYPE } from "@/media/file-type";import { isHEICExtension, needsJPEGConversion } from "@/media/formats";import downloadManager from "@/new/photos/services/download";+import { extractRawExif, type RawExif } from "@/new/photos/services/exif";import type { LoadedLivePhotoSourceURL } from "@/new/photos/types/file";-import { detectFileTypeInfo } from "@/new/photos/utils/detect-type";import { FlexWrapper } from "@ente/shared/components/Container";import EnteSpinner from "@ente/shared/components/EnteSpinner";import AlbumOutlined from "@mui/icons-material/AlbumOutlined";@@ -46,7 +46,6 @@ import { t } from "i18next";import isElectron from "is-electron";import { AppContext } from "pages/_app";import { GalleryContext } from "pages/gallery";-import { getParsedExifData } from "services/exif";import { trashFiles } from "services/fileService";import { SetFilesDownloadProgressAttributesCreator } from "types/gallery";import { isClipboardItemPresent } from "utils/common";@@ -108,11 +107,11 @@ function PhotoViewer(props: Iprops) {useState<Photoswipe<Photoswipe.Options>>();const [isFav, setIsFav] = useState(false);const [showInfo, setShowInfo] = useState(false);- const [exif, setExif] = useState<{+ const [rawExif, setRawExif] = useState<{key: string;- value: Record<string, any>;+ value: RawExif;}>();- const exifCopy = useRef(null);+ const rawExifCopy = useRef(null);const [livePhotoBtnOptions, setLivePhotoBtnOptions] = useState(defaultLivePhotoDefaultOptions,);@@ -291,8 +290,8 @@ function PhotoViewer(props: Iprops) {}, [photoSwipe?.currItem, isOpen, isSourceLoaded]);useEffect(() => {- exifCopy.current = exif;- }, [exif]);+ rawExifCopy.current = rawExif;+ }, [rawExif]);function updateFavButton(file: EnteFile) {setIsFav(isInFav(file));@@ -307,14 +306,14 @@ function PhotoViewer(props: Iprops) {function updateExif(file: EnteFile) {if (file.metadata.fileType === FILE_TYPE.VIDEO) {- setExif({ key: file.src, value: null });+ setRawExif({ key: file.src, value: null });return;}if (!file.isSourceLoaded || file.conversionFailed) {return;}- if (!file || !exifCopy?.current?.value === null) {+ if (!file || !rawExifCopy?.current?.value === null) {return;}const key =@@ -322,10 +321,10 @@ function PhotoViewer(props: Iprops) {? file.src: (file.srcURLs.url as LoadedLivePhotoSourceURL).image;- if (exifCopy?.current?.key === key) {+ if (rawExifCopy?.current?.key === key) {return;}- setExif({ key, value: undefined });+ setRawExif({ key, value: undefined });checkExifAvailable(file);}@@ -603,28 +602,20 @@ function PhotoViewer(props: Iprops) {.image;fileObject = await getFileFromURL(url, file.metadata.title);}- const fileTypeInfo = await detectFileTypeInfo(fileObject);- const exifData = await getParsedExifData(- fileObject,- fileTypeInfo,- );+ const rawExif = await extractRawExif(fileObject);// TODO: Exif// if (await wipNewLib()) {// const newLib = await extractExif(fileObject);// cmpNewLib(file.metadata, newLib);// }if (exifExtractionInProgress.current === file.src) {- if (exifData) {- setExif({ key: file.src, value: exifData });- } else {- setExif({ key: file.src, value: null });- }+ setRawExif({ key: file.src, value: rawExif });}} finally {exifExtractionInProgress.current = null;}} catch (e) {- setExif({ key: file.src, value: null });+ setRawExif({ key: file.src, value: null });log.error(`checkExifAvailable failed for file ${file.metadata.title}`,e,@@ -955,7 +946,7 @@ function PhotoViewer(props: Iprops) {showInfo={showInfo}handleCloseInfo={handleCloseInfo}file={photoSwipe?.currItem as EnteFile}- exif={exif?.value}+ rawExif={rawExif?.value}scheduleUpdate={scheduleUpdate}refreshPhotoswipe={refreshPhotoswipe}fileToCollectionsMap={props.fileToCollectionsMap}diff --git a/web/packages/new/photos/services/exif.ts b/web/packages/new/photos/services/exif.tsindex 5b5f15f423..c3faaa2a8a 100644--- a/web/packages/new/photos/services/exif.ts+++ b/web/packages/new/photos/services/exif.ts@@ -9,7 +9,7 @@ export const wipNewLib = async () => isDevBuild && (await isInternalUser());export const cmpNewLib = (oldLib: ParsedExtractedMetadata,- newLib: ExtractedExif,+ newLib: ParsedExif,) => {if (oldLib.width == newLib.width &&@@ -34,7 +34,7 @@ export const cmpNewLib = (* be attached to an {@link EnteFile} allows us to perform operations using* these attributes without needing to re-download the original image.*/-interface ExtractedExif {+interface ParsedExif {/** The width of the image, in pixels. */width?: number;/** The height of the image, in pixels. */@@ -73,7 +73,7 @@ export const extractExif = async (file: File) => {const creationDate = parseCreationDate(tags);const dimensions = parseDimensions(tags);- const metadata: ExtractedExif = dimensions ?? {};+ const metadata: ParsedExif = dimensions ?? {};if (creationDate) metadata.creationTime = creationDate.getTime() * 1000;if (location) metadata.location = location;return metadata;@@ -109,7 +109,7 @@ const parseCreationDate = (tags: ExifReader.ExpandedTags) => {* from all forms of metadata we support (Exif, XMP, IPTC). They roughly* correspond to the three Exif DateTime* tags, and the XMP MetadataDate tag.*/-interface ExtractedExifDates {+interface ParsedExifDates {DateTimeOriginal: Date | undefined;DateTimeDigitized: Date | undefined;DateTime: Date | undefined;@@ -119,7 +119,7 @@ interface ExtractedExifDates {/*** Extract dates from Exif and other metadata for the given file.*/-export const extractExifDates = (file: File): Promise<ExtractedExifDates> =>+export const extractExifDates = (file: File): Promise<ParsedExifDates> =>extractTags(file).then(parseDates);/**@@ -433,6 +433,10 @@ const parseXMPNum = (xmpTag: ExifReader.XmpTag | undefined) => {return n;};+export type RawExif = Omit<ExifReader.ExpandedTags, "Thumbnail" | "xmp"> & {+ xmp?: ExifReader.XmpTags;+};+/*** Extract "raw" exif and other metadata from the given file.*@@ -494,7 +498,7 @@ const parseXMPNum = (xmpTag: ExifReader.XmpTag | undefined) => {* while allowing us to consume this JSON in arbitrary clients without needing* to know about ExifReader specifically.*/-export const extractRawExif = async (blob: Blob) => {+export const extractRawExif = async (blob: Blob): Promise<RawExif> => {const tags = await extractTags(blob);// Remove the embedded thumbnail (if any).