@umituz/react-native-ai-generation-content 1.17.160 → 1.17.161
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
|
@@ -24,6 +24,12 @@ export interface AnimeSelfieResult {
|
|
|
24
24
|
imageBase64?: string;
|
|
25
25
|
error?: string;
|
|
26
26
|
requestId?: string;
|
|
27
|
+
creationId?: string;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface AnimeSelfieProcessingStartData {
|
|
31
|
+
creationId: string;
|
|
32
|
+
imageUri: string;
|
|
27
33
|
}
|
|
28
34
|
|
|
29
35
|
export interface AnimeSelfieFeatureState {
|
|
@@ -58,7 +64,7 @@ export interface AnimeSelfieFeatureConfig {
|
|
|
58
64
|
extractResult?: AnimeSelfieResultExtractor;
|
|
59
65
|
prepareImage: (imageUri: string) => Promise<string>;
|
|
60
66
|
onImageSelect?: (uri: string) => void;
|
|
61
|
-
onProcessingStart?: () => void;
|
|
67
|
+
onProcessingStart?: (data: AnimeSelfieProcessingStartData) => void;
|
|
62
68
|
onProcessingComplete?: (result: AnimeSelfieResult) => void;
|
|
63
|
-
onError?: (error: string) => void;
|
|
69
|
+
onError?: (error: string, creationId?: string) => void;
|
|
64
70
|
}
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
* Manages anime selfie feature state and actions
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { useState, useCallback } from "react";
|
|
6
|
+
import { useState, useCallback, useRef } from "react";
|
|
7
|
+
import { generateUUID } from "@umituz/react-native-uuid";
|
|
7
8
|
import { executeImageFeature } from "../../../../infrastructure/services";
|
|
8
9
|
import type {
|
|
9
10
|
AnimeSelfieFeatureState,
|
|
@@ -38,6 +39,7 @@ export function useAnimeSelfieFeature(
|
|
|
38
39
|
): UseAnimeSelfieFeatureReturn {
|
|
39
40
|
const { config, onSelectImage, onSaveImage, onBeforeProcess } = props;
|
|
40
41
|
const [state, setState] = useState<AnimeSelfieFeatureState>(initialState);
|
|
42
|
+
const creationIdRef = useRef<string | null>(null);
|
|
41
43
|
|
|
42
44
|
const selectImage = useCallback(async () => {
|
|
43
45
|
try {
|
|
@@ -64,6 +66,9 @@ export function useAnimeSelfieFeature(
|
|
|
64
66
|
if (!canProceed) return;
|
|
65
67
|
}
|
|
66
68
|
|
|
69
|
+
const creationId = generateUUID();
|
|
70
|
+
creationIdRef.current = creationId;
|
|
71
|
+
|
|
67
72
|
setState((prev) => ({
|
|
68
73
|
...prev,
|
|
69
74
|
isProcessing: true,
|
|
@@ -71,7 +76,7 @@ export function useAnimeSelfieFeature(
|
|
|
71
76
|
error: null,
|
|
72
77
|
}));
|
|
73
78
|
|
|
74
|
-
config.onProcessingStart?.();
|
|
79
|
+
config.onProcessingStart?.({ creationId, imageUri: state.imageUri });
|
|
75
80
|
|
|
76
81
|
try {
|
|
77
82
|
const imageBase64 = await config.prepareImage(state.imageUri);
|
|
@@ -89,7 +94,7 @@ export function useAnimeSelfieFeature(
|
|
|
89
94
|
processedUrl: result.imageUrl!,
|
|
90
95
|
progress: 100,
|
|
91
96
|
}));
|
|
92
|
-
config.onProcessingComplete?.(result as AnimeSelfieResult);
|
|
97
|
+
config.onProcessingComplete?.({ ...result, creationId } as AnimeSelfieResult);
|
|
93
98
|
} else {
|
|
94
99
|
const errorMessage = result.error || "Processing failed";
|
|
95
100
|
setState((prev) => ({
|
|
@@ -98,7 +103,7 @@ export function useAnimeSelfieFeature(
|
|
|
98
103
|
error: errorMessage,
|
|
99
104
|
progress: 0,
|
|
100
105
|
}));
|
|
101
|
-
config.onError?.(errorMessage);
|
|
106
|
+
config.onError?.(errorMessage, creationId);
|
|
102
107
|
}
|
|
103
108
|
} catch (error) {
|
|
104
109
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
@@ -108,7 +113,7 @@ export function useAnimeSelfieFeature(
|
|
|
108
113
|
error: errorMessage,
|
|
109
114
|
progress: 0,
|
|
110
115
|
}));
|
|
111
|
-
config.onError?.(errorMessage);
|
|
116
|
+
config.onError?.(errorMessage, creationIdRef.current ?? undefined);
|
|
112
117
|
}
|
|
113
118
|
}, [state.imageUri, config, handleProgress, onBeforeProcess]);
|
|
114
119
|
|