π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Add file type detection and colored icons for Locker file sharing page
anandbaburajan138db645a733
diff --git a/web/apps/locker/src/pages/[token].tsx b/web/apps/locker/src/pages/[token].tsxindex 5fa700bb98..8bcd48bca4 100644--- a/web/apps/locker/src/pages/[token].tsx+++ b/web/apps/locker/src/pages/[token].tsx@@ -1,4 +1,3 @@-import ImageIcon from "@mui/icons-material/Image";import { Box, Button, CircularProgress, Typography } from "@mui/material";import bs58 from "bs58";import { EnteLogo } from "ente-base/components/EnteLogo";@@ -12,6 +11,7 @@ import {import { apiOrigin } from "ente-base/origins";import { useRouter } from "next/router";import React, { useEffect, useState } from "react";+import { getLockerFileIcon } from "../utils/file-type";const formatFileSize = (bytes: number): string => {if (bytes === 0) return "0 Bytes";@@ -65,6 +65,7 @@ interface DecryptedFileInfo {fileDecryptionHeader?: string;fileNonce?: string;fileKey?: string;+ lockerType?: string; // Locker file type from pubMagicMetadata.info}// Extract file key from URL hash (similar to extractCollectionKeyFromShareURL)@@ -145,6 +146,8 @@ const decryptFileInfo = async (// Get file size from info fieldconst fileSizeFromInfo = file.info?.fileSize || 0;+ console.log("file.info:", file.info);+ console.log("fileSizeFromInfo:", fileSizeFromInfo);// Extract nested encrypted metadata and decryption headerconst encryptedMetadata =@@ -183,10 +186,46 @@ const decryptFileInfo = async (fileKey,);metadata = decryptedMetadata as any;+ console.log("Decrypted metadata:", metadata);} catch (err) {metadata = {};}+ // Try to decrypt pubMagicMetadata if it exists+ let pubMagicMetadata: any = null;+ if (file.pubMagicMetadata?.data && file.pubMagicMetadata?.header) {+ try {+ const decryptedPubMagicMetadata = await decryptMetadataJSON(+ {+ encryptedData: file.pubMagicMetadata.data,+ decryptionHeader: file.pubMagicMetadata.header,+ },+ fileKey,+ );+ pubMagicMetadata = decryptedPubMagicMetadata;+ } catch (err) {+ // Failed to decrypt pubMagicMetadata+ }+ }++ // Extract and parse info from pubMagicMetadata+ console.log("pubMagicMetadata:", pubMagicMetadata);+ console.log("pubMagicMetadata?.info:", pubMagicMetadata?.info);++ // Check if info is a JSON string that needs parsing+ let infoObject = pubMagicMetadata?.info;+ if (typeof infoObject === "string") {+ try {+ infoObject = JSON.parse(infoObject);+ console.log("Parsed info object:", infoObject);+ } catch (e) {+ console.log("Failed to parse info as JSON");+ }+ }++ const lockerType = infoObject?.type;+ console.log("Extracted lockerType:", lockerType);+// Extract file info from decrypted metadataconst fileName =metadata.fileName ||@@ -194,8 +233,13 @@ const decryptFileInfo = async (metadata.name ||"Unknown file";+ // Check if there's file size in pubMagicMetadata.info.data+ const pubMagicFileSize = infoObject?.data?.size;+ console.log("pubMagicFileSize:", pubMagicFileSize);+// Use fileSize from info field first, then fall back to metadata or other sourcesconst fileSize =+ pubMagicFileSize ||fileSizeFromInfo ||metadata.fileSize ||metadata.size ||@@ -206,7 +250,7 @@ const decryptFileInfo = async (metadata.createdAt ||metadata.modificationTime;- return {+ const decryptedFileInfo = {id: fileId,fileName: fileName,fileSize: fileSize,@@ -215,7 +259,12 @@ const decryptFileInfo = async (fileDecryptionHeader: fileDecryptionHeader,fileNonce: undefined,fileKey: fileKey,+ lockerType: lockerType,};++ console.log("Final decryptedFileInfo:", decryptedFileInfo);++ return decryptedFileInfo;} catch (error) {// Return partial info if decryption failsif (!fileLinkInfo.file) {@@ -471,43 +520,46 @@ const FilePage: React.FC = () => {)}{/* File Info Display */}- {fileInfo && !loading && (- <>- {/* Spacer for mobile to push content down */}- <Box- sx={{- flex: { xs: 1, md: 0 },- minHeight: { xs: 40, md: 0 },- }}- />+ {fileInfo && !loading && (() => {+ const iconInfo = getLockerFileIcon(+ fileInfo.fileName,+ fileInfo.lockerType,+ );+ return (+ <>+ {/* Spacer for mobile to push content down */}+ <Box+ sx={{+ flex: { xs: 1, md: 0 },+ minHeight: { xs: 40, md: 0 },+ }}+ />- {/* File Info - Centered */}- <Box- sx={{- display: "flex",- flexDirection: "column",- alignItems: "center",- justifyContent: "center",- gap: 3,- width: "100%",- marginBottom: 4,- }}- >- {/* Large File Icon */}+ {/* File Info - Centered */}<Boxsx={{- backgroundColor: "#F0F0F0",- borderRadius: "24px",- padding: 1.5,display: "flex",+ flexDirection: "column",alignItems: "center",justifyContent: "center",+ gap: 3,+ width: "100%",+ marginBottom: 4,}}>- <ImageIcon- sx={{ fontSize: 48, color: "#757575" }}- />- </Box>+ {/* Large File Icon */}+ <Box+ sx={{+ backgroundColor: iconInfo.backgroundColor,+ borderRadius: "20px",+ padding: 1.8,+ display: "flex",+ alignItems: "center",+ justifyContent: "center",+ }}+ >+ {iconInfo.icon}+ </Box>{/* File Name */}<Typography@@ -522,19 +574,21 @@ const FilePage: React.FC = () => {{fileInfo.fileName}</Typography>- {/* File Size */}- <Typography- variant="body"- sx={{- color: "#757575",- mt: -2,- fontSize: "1rem",- }}- >- {fileInfo.fileSize > 0- ? formatFileSize(fileInfo.fileSize)- : "Unknown size"}- </Typography>+ {/* File Size - only show if no locker type */}+ {!fileInfo.lockerType && (+ <Typography+ variant="body"+ sx={{+ color: "#757575",+ mt: -2,+ fontSize: "1rem",+ }}+ >+ {fileInfo.fileSize > 0+ ? formatFileSize(fileInfo.fileSize)+ : "Unknown size"}+ </Typography>+ )}</Box>{/* Another spacer to push button to bottom on mobile */}@@ -583,7 +637,8 @@ const FilePage: React.FC = () => {</Button></Box></>- )}+ );+ })()}</Box></Box>);diff --git a/web/apps/locker/src/utils/file-type.tsx b/web/apps/locker/src/utils/file-type.tsxnew file mode 100644index 0000000000..92a2dfad67--- /dev/null+++ b/web/apps/locker/src/utils/file-type.tsx@@ -0,0 +1,167 @@+import {+ CallIcon,+ CollectionsBookmarkIcon,+ File02Icon,+ Image01Icon,+ MailAccount01Icon,+ StickyNote02Icon,+ Video02Icon,+} from "hugeicons-react";+import React from "react";++export enum LockerInfoType {+ Note = "note",+ PhysicalRecord = "physicalRecord",+ AccountCredential = "accountCredential",+ EmergencyContact = "emergencyContact",+}++interface LockerIconInfo {+ icon: React.ReactElement;+ backgroundColor: string;+}++/**+ * Extract the file extension from a filename+ * Returns lowercase extension without the dot, or empty string if no extension+ */+const getFileExtension = (fileName: string): string => {+ const lastDot = fileName.lastIndexOf(".");+ if (lastDot === -1 || lastDot === fileName.length - 1) {+ return "";+ }+ return fileName.slice(lastDot + 1).toLowerCase();+};++/**+ * Check if file extension is an image+ */+const isImageExtension = (extension: string): boolean => {+ const imageExtensions = [+ "jpg",+ "jpeg",+ "png",+ "gif",+ "webp",+ "bmp",+ "svg",+ "heic",+ "heif",+ "ico",+ "tiff",+ "tif",+ ];+ return imageExtensions.includes(extension);+};++/**+ * Check if file extension is a video+ */+const isVideoExtension = (extension: string): boolean => {+ const videoExtensions = [+ "mp4",+ "mov",+ "avi",+ "mkv",+ "webm",+ "wmv",+ "flv",+ "m4v",+ "3gp",+ "3g2",+ "ogv",+ "mpg",+ "mpeg",+ ];+ return videoExtensions.includes(extension);+};++/**+ * Check if file extension is a document/text file+ */+const isDocumentExtension = (extension: string): boolean => {+ const documentExtensions = [+ "pdf",+ "doc",+ "docx",+ "xls",+ "xlsx",+ "ppt",+ "pptx",+ "txt",+ "rtf",+ "odt",+ "ods",+ "odp",+ "md",+ "csv",+ ];+ return documentExtensions.includes(extension);+};++/**+ * Get icon based on locker info type (first priority) or file extension (fallback)+ */+export const getLockerFileIcon = (+ fileName: string,+ lockerType?: string,+): LockerIconInfo => {+ // First priority: Check locker info type+ if (lockerType) {+ switch (lockerType) {+ case LockerInfoType.Note:+ return {+ icon: <StickyNote02Icon size={42} color="#FFA825" />,+ backgroundColor: "rgba(255, 168, 37, 0.06)",+ };++ case LockerInfoType.EmergencyContact:+ return {+ icon: <CallIcon size={42} color="#DF61BB" />,+ backgroundColor: "rgba(223, 97, 187, 0.06)",+ };++ case LockerInfoType.AccountCredential:+ return {+ icon: <MailAccount01Icon size={42} color="#666666" />,+ backgroundColor: "rgba(102, 102, 102, 0.06)",+ };++ case LockerInfoType.PhysicalRecord:+ return {+ icon: <CollectionsBookmarkIcon size={42} color="#5FB7BB" />,+ backgroundColor: "rgba(95, 183, 187, 0.06)",+ };+ }+ }++ // Second priority: Detect based on file extension+ const extension = getFileExtension(fileName);++ if (isImageExtension(extension)) {+ return {+ icon: <Image01Icon size={42} color="#08C225" />,+ backgroundColor: "rgba(8, 194, 37, 0.06)",+ };+ }++ if (isVideoExtension(extension)) {+ return {+ icon: <Video02Icon size={42} color="#8A38F5" />,+ backgroundColor: "rgba(138, 56, 245, 0.06)",+ };+ }++ if (isDocumentExtension(extension)) {+ return {+ icon: <File02Icon size={42} color="#FF1A53" />,+ backgroundColor: "rgba(255, 26, 83, 0.06)",+ };+ }++ // Default: Generic file icon+ return {+ icon: <File02Icon size={42} color="#FF1A53" />,+ backgroundColor: "rgba(255, 26, 83, 0.06)",+ };+};diff --git a/web/package.json b/web/package.jsonindex 5c12deb6d1..d758105d77 100644--- a/web/package.json+++ b/web/package.json@@ -37,5 +37,8 @@"prettier": "^3.6.2","typescript": "^5.8.3"},- "packageManager": "[email protected]"+ "packageManager": "[email protected]",+ "dependencies": {+ "hugeicons-react": "^0.3.0"+ }}diff --git a/web/yarn.lock b/web/yarn.lockindex 279dabf572..83c9690127 100644--- a/web/yarn.lock+++ b/web/yarn.lock@@ -2587,6 +2587,11 @@ html-parse-stringify@^3.0.1:dependencies:void-elements "3.1.0"+hugeicons-react@^0.3.0:+ version "0.3.0"+ resolved "https://registry.yarnpkg.com/hugeicons-react/-/hugeicons-react-0.3.0.tgz#a788db21b116f16062b75ccf3a3633575722ec9f"+ integrity sha512-znmC+uX7xVqcIs0q09LvwEvJkjX0U3xgT05BSiRV19farS4lPONOKjYT0JkcQG5cvfV0rXHSEAEVNjbHAu81rg==+i18next-resources-to-backend@^1.2.1:version "1.2.1"resolved "https://registry.yarnpkg.com/i18next-resources-to-backend/-/i18next-resources-to-backend-1.2.1.tgz#fded121e63e3139ce839c9901b9449dbbea7351d"