From b6af39c56700250a8a9d3118729df876e64142ab Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 16 Mar 2026 17:26:28 +0000 Subject: [PATCH] refactor(mobile): address code review feedback Extract APP_SCHEME_PREFIX constant for the custom URL scheme string, and derive the photo library fallback filename extension from the asset's MIME type instead of always using .jpg. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- mobile/app/_layout.tsx | 10 ++++++---- mobile/src/screens/UploadScreen.tsx | 4 +++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mobile/app/_layout.tsx b/mobile/app/_layout.tsx index f188ed76..3d328673 100644 --- a/mobile/app/_layout.tsx +++ b/mobile/app/_layout.tsx @@ -23,6 +23,9 @@ import { ShareProvider, useShare } from "../src/context/ShareContext"; // Helpers // --------------------------------------------------------------------------- +/** The custom URL scheme registered in app.json. */ +const APP_SCHEME_PREFIX = "docuelevate://"; + /** Extract a display filename from a file:// or content:// URI. */ function filenameFromUri(uri: string): string { try { @@ -41,8 +44,7 @@ function filenameFromUri(uri: string): string { * itself is created once and can be easily unit-tested without a React context. * * On iOS the Share Sheet / "Open In" action may deliver the file path under - * the app's custom URL scheme (e.g. - * `docuelevate://private/var/mobile/Library/…/file.pdf`) instead of a plain + * the app's custom URL scheme (`docuelevate://…/file.pdf`) instead of a plain * `file://` URL. When that happens we rewrite the URL to `file:///…` so the * upload logic can read the file normally. */ @@ -53,8 +55,8 @@ function makeUrlHandler(addPendingFile: (f: { uri: string; filename: string }) = // iOS may pass a filesystem path under the app's custom scheme. // Rewrite it to a file:// URL unless it looks like an in-app deep-link // (expo-router groups always start with "("). - if (url.startsWith("docuelevate://")) { - const path = url.slice("docuelevate://".length); + if (url.startsWith(APP_SCHEME_PREFIX)) { + const path = url.slice(APP_SCHEME_PREFIX.length); if (path.length > 0 && !path.startsWith("(")) { fileUri = "file:///" + path.replace(/^\/+/, ""); } diff --git a/mobile/src/screens/UploadScreen.tsx b/mobile/src/screens/UploadScreen.tsx index 78cf8097..727a1d56 100644 --- a/mobile/src/screens/UploadScreen.tsx +++ b/mobile/src/screens/UploadScreen.tsx @@ -180,7 +180,9 @@ export default function UploadScreen() { if (!result.canceled && result.assets.length > 0) { const asset = result.assets[0]; - const filename = asset.fileName ?? `photo_${Date.now()}.jpg`; + // Derive extension from MIME type so the filename matches the actual format + const ext = asset.mimeType?.split("/")[1]?.replace("jpeg", "jpg") ?? "jpg"; + const filename = asset.fileName ?? `photo_${Date.now()}.${ext}`; await uploadFile(asset.uri, filename, asset.mimeType ?? "image/jpeg"); } }