@umituz/react-native-filesystem 2.1.20 → 2.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-filesystem",
3
- "version": "2.1.20",
3
+ "version": "2.1.21",
4
4
  "description": "File operations and import/export functionality for React Native apps",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -11,7 +11,7 @@ import { downloadFile } from "./download.service";
11
11
  import { clearCache, getDirectorySize } from "./cache.service";
12
12
  import { generateFilePath } from "./file-path.service";
13
13
  import { FileUtils } from "../../domain/entities/File";
14
- import type { FileEncoding, DirectoryType, FileOperationResult } from "../../domain/entities/File";
14
+ import type { FileOperationResult } from "../../domain/entities/File";
15
15
 
16
16
  export class FileSystemService {
17
17
  static readFile = readFile;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Download Service Constants
3
+ */
4
+
5
+ export const SUPPORTED_DOWNLOAD_EXTENSIONS = ["mp4", "mov", "m4v", "webm", "jpg", "png", "pdf"] as const;
6
+ export const DEFAULT_DOWNLOAD_EXTENSION = "mp4" as const;
@@ -5,6 +5,7 @@
5
5
  import { File, Paths, Directory } from "expo-file-system";
6
6
  import type { FileOperationResult } from "../../domain/entities/File";
7
7
  import { FileUtils } from "../../domain/entities/File";
8
+ import { SUPPORTED_DOWNLOAD_EXTENSIONS, DEFAULT_DOWNLOAD_EXTENSION } from "./download.constants";
8
9
  import type { DownloadProgressCallback, DownloadWithProgressResult } from "./download.types";
9
10
 
10
11
  const hashUrl = (url: string) => {
@@ -14,8 +15,9 @@ const hashUrl = (url: string) => {
14
15
  };
15
16
 
16
17
  const getExt = (url: string) => {
17
- const ext = url.split("?")[0].split(".").pop()?.toLowerCase() || "mp4";
18
- return ["mp4", "mov", "m4v", "webm", "jpg", "png", "pdf"].includes(ext) ? ext : "mp4";
18
+ const parts = url.split("?")[0]?.split(".") || [];
19
+ const ext = parts.length > 1 ? parts.pop()?.toLowerCase() || DEFAULT_DOWNLOAD_EXTENSION : DEFAULT_DOWNLOAD_EXTENSION;
20
+ return (SUPPORTED_DOWNLOAD_EXTENSIONS as readonly string[]).includes(ext) ? ext : DEFAULT_DOWNLOAD_EXTENSION;
19
21
  };
20
22
 
21
23
  const getCacheUri = (url: string, dir: string) => FileUtils.joinPaths(dir, `cached_${hashUrl(url)}.${getExt(url)}`);
@@ -11,8 +11,7 @@ export function blobToBase64(blob: Blob): Promise<string> {
11
11
  const reader = new FileReader();
12
12
  reader.onloadend = () => {
13
13
  const result = reader.result as string;
14
- // Remove data URL prefix if present
15
- const base64 = result.includes(",") ? result.split(",")[1] : result;
14
+ const base64 = result.includes(",") ? result.split(",")[1] ?? result : result;
16
15
  resolve(base64);
17
16
  };
18
17
  reader.onerror = reject;