2f3c22000c
Restored mobile/ from d22175310a711e7ebdd8062ae29a54f0136dc3f6^ (parent commitd94e9ca4bc). Commitd22175310a(google-labs-jules[bot], 2026-03-23T14:45:22Z) introduced an SSRF security fix for IMAP connections but unintentionally deleted or truncated a large number of files across the repository, including 24 files under mobile/. This commit targets only the mobile/ directory and restores the following files to their pre-d2217531 state: - mobile/README.md - mobile/app.json - mobile/app/(tabs)/_layout.tsx - mobile/app/(tabs)/file-detail.tsx (re-added) - mobile/app/+not-found.tsx (re-added) - mobile/app/_layout.tsx - mobile/eslint.config.js (re-added) - mobile/package-lock.json - mobile/package.json - mobile/src/context/ShareContext.tsx - mobile/src/i18n/de.json (re-added) - mobile/src/i18n/en.json (re-added) - mobile/src/i18n/es.json (re-added) - mobile/src/i18n/fr.json (re-added) - mobile/src/i18n/index.ts (re-added) - mobile/src/i18n/it.json (re-added) - mobile/src/screens/FileDetailScreen.tsx (re-added) - mobile/src/screens/FilesScreen.tsx - mobile/src/screens/LoginScreen.tsx - mobile/src/screens/ProfileScreen.tsx - mobile/src/screens/UploadScreen.tsx - mobile/src/screens/WelcomeScreen.tsx - mobile/src/services/api.ts - mobile/src/utils/mimeTypes.ts (re-added) - mobile/src/utils/normalizeUri.ts (re-added) Security fixes introduced byd2217531that are unrelated to mobile/ (IMAP SSRF fix in app/utils/network.py and app/tasks/imap_tasks.py) are preserved — this restore targets only files under mobile/.
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
/**
|
||
* ShareContext – propagates files received from the iOS Share Sheet or the
|
||
* Android Share Intent to the UploadScreen so they can be uploaded
|
||
* automatically.
|
||
*
|
||
* The root layout listens for incoming file:// / content:// URLs via
|
||
* expo-linking and calls addPendingFile(). UploadScreen consumes the context,
|
||
* uploads each pending file, then calls clearPendingFiles().
|
||
*/
|
||
|
||
import React, { createContext, useCallback, useContext, useState } from "react";
|
||
import { normalizeFileUri } from "../utils/normalizeUri";
|
||
|
||
export interface SharedFile {
|
||
uri: string;
|
||
filename: string;
|
||
mimeType?: string;
|
||
}
|
||
|
||
interface ShareContextValue {
|
||
pendingFiles: SharedFile[];
|
||
addPendingFile: (file: SharedFile) => void;
|
||
clearPendingFiles: () => void;
|
||
}
|
||
|
||
const ShareContext = createContext<ShareContextValue>({
|
||
pendingFiles: [],
|
||
addPendingFile: () => {},
|
||
clearPendingFiles: () => {},
|
||
});
|
||
|
||
export function ShareProvider({ children }: { children: React.ReactNode }) {
|
||
const [pendingFiles, setPendingFiles] = useState<SharedFile[]>([]);
|
||
|
||
const addPendingFile = useCallback((file: SharedFile) => {
|
||
setPendingFiles((prev) => {
|
||
// Deduplicate by normalised URI so the same file is not uploaded twice
|
||
// when both the Linking handler (_layout.tsx) and +not-found.tsx fire.
|
||
const norm = normalizeFileUri(file.uri);
|
||
if (prev.some((f) => normalizeFileUri(f.uri) === norm)) return prev;
|
||
return [...prev, file];
|
||
});
|
||
}, []);
|
||
|
||
const clearPendingFiles = useCallback(() => {
|
||
setPendingFiles([]);
|
||
}, []);
|
||
|
||
return (
|
||
<ShareContext.Provider value={{ pendingFiles, addPendingFile, clearPendingFiles }}>
|
||
{children}
|
||
</ShareContext.Provider>
|
||
);
|
||
}
|
||
|
||
export function useShare(): ShareContextValue {
|
||
return useContext(ShareContext);
|
||
}
|