π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Normalize Locker info types when reading on web
Neeraj Gupta7ac07de41754
diff --git a/web/apps/locker/src/services/info-type-wire.ts b/web/apps/locker/src/services/info-type-wire.tsnew file mode 100644index 0000000000..980b067239--- /dev/null+++ b/web/apps/locker/src/services/info-type-wire.ts@@ -0,0 +1,17 @@+import type { LockerItemType } from "types";++type LockerInfoInternalType = Exclude<LockerItemType, "file">;++const internalTypeByWireType = new Map<string, LockerInfoInternalType>([+ ["note", "note"],+ ["physical-record", "physicalRecord"],+ ["physicalRecord", "physicalRecord"],+ ["account-credential", "accountCredential"],+ ["accountCredential", "accountCredential"],+ ["emergency-contact", "emergencyContact"],+ ["emergencyContact", "emergencyContact"],+]);++export const fromInfoTypeWireValue = (+ value: string,+): LockerItemType | undefined => internalTypeByWireType.get(value);diff --git a/web/apps/locker/src/services/remote-read.ts b/web/apps/locker/src/services/remote-read.tsindex de0dfed9d4..3478501942 100644--- a/web/apps/locker/src/services/remote-read.ts+++ b/web/apps/locker/src/services/remote-read.ts@@ -10,7 +10,6 @@ import type {LockerCollection,LockerCollectionParticipant,LockerItem,- LockerItemType,} from "types";import { z } from "zod";import {@@ -22,6 +21,7 @@ import {encryptBox,stringToB64,} from "./crypto";+import { fromInfoTypeWireValue } from "./info-type-wire";import {type StoredTrashFileRecord,deleteCollectionSinceTime,@@ -636,18 +636,17 @@ const decryptFileToLockerItem = async (| { type?: string; data?: Record<string, unknown> }| undefined;- const validInfoTypes = new Set<string>([- "note",- "accountCredential",- "physicalRecord",- "emergencyContact",- ]);+ const infoType =+ typeof info?.type === "string"+ ? fromInfoTypeWireValue(info.type)+ : undefined;+ const infoData = info?.data;- if (info?.type && info.data && validInfoTypes.has(info.type)) {+ if (infoType && infoData) {return {id: record.id,- type: info.type as LockerItemType,- data: info.data as unknown as LockerItem["data"],+ type: infoType,+ data: infoData as unknown as LockerItem["data"],collectionID: record.collectionID,collectionIDs: [record.collectionID],ownerID: record.ownerID ?? collectionOwnerID,diff --git a/web/apps/share/src/services/file-share.ts b/web/apps/share/src/services/file-share.tsindex 92848acda0..264dc9586e 100644--- a/web/apps/share/src/services/file-share.ts+++ b/web/apps/share/src/services/file-share.ts@@ -126,6 +126,26 @@ const decryptPubMagicMetadata = async (}};+const normalizeLockerInfoType = (+ type: string | undefined,+): string | undefined => {+ switch (type) {+ case "note":+ return "note";+ case "physical-record":+ case "physicalRecord":+ return "physicalRecord";+ case "account-credential":+ case "accountCredential":+ return "accountCredential";+ case "emergency-contact":+ case "emergencyContact":+ return "emergencyContact";+ default:+ return undefined;+ }+};+/*** Parse locker info from pubMagicMetadata*/@@ -134,15 +154,22 @@ const parseLockerInfo = (): LockerInfo | undefined => {if (!rawInfo) return undefined;- if (typeof rawInfo === "string") {- try {- return JSON.parse(rawInfo) as LockerInfo;- } catch {- return undefined;- }+ const parsedInfo =+ typeof rawInfo === "string"+ ? (() => {+ try {+ return JSON.parse(rawInfo) as LockerInfo;+ } catch {+ return undefined;+ }+ })()+ : rawInfo;++ if (!parsedInfo) {+ return undefined;}- return rawInfo;+ return { ...parsedInfo, type: normalizeLockerInfoType(parsedInfo.type) };};/**