Download mobile/modules/engine/src/utils/permissions/galleryDisplayName.ts from Anirudh1950/MentraOS: direct link, hf CLI and curl.
- Browser
- Download file 999 Bytes
-
https://huggingface.co/Anirudh1950/MentraOS/resolve/main/mobile/modules/engine/src/utils/permissions/galleryDisplayName.ts
- Command line
-
hf download hf://Anirudh1950/MentraOS/mobile/modules/engine/src/utils/permissions/galleryDisplayName.ts
-
curl -L -o galleryDisplayName.ts https://huggingface.co/Anirudh1950/MentraOS/resolve/main/mobile/modules/engine/src/utils/permissions/galleryDisplayName.ts
999 Bytes
| const CAPTURE_FOLDER_PATTERN = /^(IMG|VID)_/ | |
| /** | |
| * Derive a unique MediaStore display name for camera-roll saves. | |
| * | |
| * Capture downloads use folder layout `IMG_xxx/base.jpg` (or `VID_xxx/base.mp4`). | |
| * Using the leaf filename (`base.jpg`) causes MediaStore collisions on Android. | |
| */ | |
| export function deriveGalleryDisplayName(filePath: string): string { | |
| const cleanPath = filePath.replace("file://", "") | |
| const lastSlash = cleanPath.lastIndexOf("/") | |
| if (lastSlash < 0) { | |
| return cleanPath | |
| } | |
| const fileName = cleanPath.substring(lastSlash + 1) | |
| const parentDir = cleanPath.substring(0, lastSlash) | |
| const parentSlash = parentDir.lastIndexOf("/") | |
| const parentName = parentSlash < 0 ? parentDir : parentDir.substring(parentSlash + 1) | |
| if (!CAPTURE_FOLDER_PATTERN.test(parentName)) { | |
| return fileName | |
| } | |
| const isVideo = /\.(mp4|mov|m4v|avi)(\.|$)/i.test(fileName) | |
| const extension = isVideo ? "mp4" : "jpg" | |
| return `${parentName}.${extension}` | |
| } | |