@umituz/react-native-ai-generation-content 1.37.0 → 1.37.2
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-ai-generation-content",
|
|
3
|
-
"version": "1.37.
|
|
3
|
+
"version": "1.37.2",
|
|
4
4
|
"description": "Provider-agnostic AI generation orchestration for React Native with result preview components",
|
|
5
5
|
"main": "src/index.ts",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@types/react": "~19.1.10",
|
|
67
67
|
"@typescript-eslint/eslint-plugin": "^8.0.0",
|
|
68
68
|
"@typescript-eslint/parser": "^8.0.0",
|
|
69
|
-
"@umituz/react-native-design-system": "^2.9.
|
|
69
|
+
"@umituz/react-native-design-system": "^2.9.50",
|
|
70
70
|
"@umituz/react-native-firebase": "^1.13.87",
|
|
71
71
|
"@umituz/react-native-localization": "*",
|
|
72
72
|
"@umituz/react-native-subscription": "*",
|
|
@@ -6,14 +6,14 @@
|
|
|
6
6
|
import { useState, useCallback } from "react";
|
|
7
7
|
import * as MediaLibrary from "expo-media-library";
|
|
8
8
|
import * as Sharing from "expo-sharing";
|
|
9
|
-
import type { UseResultActionsOptions, UseResultActionsReturn } from "../types/result-preview.types";
|
|
10
9
|
import {
|
|
11
10
|
isBase64DataUrl,
|
|
12
11
|
toDataUrl,
|
|
13
12
|
saveBase64ToFile,
|
|
14
13
|
isVideoUrl,
|
|
15
14
|
downloadMediaToFile,
|
|
16
|
-
} from "
|
|
15
|
+
} from "@umituz/react-native-design-system";
|
|
16
|
+
import type { UseResultActionsOptions, UseResultActionsReturn } from "../types/result-preview.types";
|
|
17
17
|
|
|
18
18
|
export const useResultActions = (options: UseResultActionsOptions = {}): UseResultActionsReturn => {
|
|
19
19
|
const { imageUrl, videoUrl, onSaveSuccess, onSaveError, onShareStart, onShareEnd } = options;
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Media File Utilities
|
|
3
|
-
* Utilities for handling media files (base64, downloads, etc.)
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { File, Paths } from "expo-file-system/next";
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Check if a string is a base64 data URL
|
|
10
|
-
*/
|
|
11
|
-
export const isBase64DataUrl = (str: string): boolean => {
|
|
12
|
-
return str.startsWith("data:image/");
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Check if a string is raw base64 (not a URL and not a data URL)
|
|
17
|
-
*/
|
|
18
|
-
export const isRawBase64 = (str: string): boolean => {
|
|
19
|
-
return !str.startsWith("http") && !str.startsWith("data:image/") && !str.startsWith("file://");
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Convert raw base64 to data URL format
|
|
24
|
-
*/
|
|
25
|
-
export const toDataUrl = (str: string): string => {
|
|
26
|
-
if (isBase64DataUrl(str)) return str;
|
|
27
|
-
if (isRawBase64(str)) return `data:image/jpeg;base64,${str}`;
|
|
28
|
-
return str;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Save base64 image to file system
|
|
33
|
-
*/
|
|
34
|
-
export const saveBase64ToFile = async (base64Data: string): Promise<string> => {
|
|
35
|
-
const timestamp = Date.now();
|
|
36
|
-
const filename = `ai_generation_${timestamp}.jpg`;
|
|
37
|
-
const file = new File(Paths.cache, filename);
|
|
38
|
-
|
|
39
|
-
const pureBase64 = base64Data.replace(/^data:image\/\w+;base64,/, "");
|
|
40
|
-
const binaryString = atob(pureBase64);
|
|
41
|
-
const bytes = new Uint8Array(binaryString.length);
|
|
42
|
-
for (let i = 0; i < binaryString.length; i++) {
|
|
43
|
-
bytes[i] = binaryString.charCodeAt(i);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
file.write(bytes);
|
|
47
|
-
return file.uri;
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Determine if URL is a video
|
|
52
|
-
*/
|
|
53
|
-
export const isVideoUrl = (url: string): boolean => {
|
|
54
|
-
const videoExtensions = [".mp4", ".mov", ".avi", ".webm", ".m4v"];
|
|
55
|
-
const lowerUrl = url.toLowerCase();
|
|
56
|
-
return videoExtensions.some((ext) => lowerUrl.includes(ext));
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Download media from URL to file
|
|
61
|
-
*/
|
|
62
|
-
export const downloadMediaToFile = async (url: string, isVideo: boolean): Promise<string> => {
|
|
63
|
-
const timestamp = Date.now();
|
|
64
|
-
const extension = isVideo ? "mp4" : "jpg";
|
|
65
|
-
const filename = `ai_generation_${timestamp}.${extension}`;
|
|
66
|
-
const file = new File(Paths.cache, filename);
|
|
67
|
-
|
|
68
|
-
const response = await fetch(url);
|
|
69
|
-
if (!response.ok) {
|
|
70
|
-
throw new Error(`Failed to download media: ${response.statusText}`);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const arrayBuffer = await response.arrayBuffer();
|
|
74
|
-
const bytes = new Uint8Array(arrayBuffer);
|
|
75
|
-
file.write(bytes);
|
|
76
|
-
|
|
77
|
-
return file.uri;
|
|
78
|
-
};
|