@umituz/react-native-ai-generation-content 1.17.159 → 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 +1 -1
- package/src/features/anime-selfie/domain/types/anime-selfie.types.ts +8 -2
- package/src/features/anime-selfie/domain/types/index.ts +1 -0
- package/src/features/anime-selfie/index.ts +1 -0
- package/src/features/anime-selfie/presentation/hooks/useAnimeSelfieFeature.ts +10 -5
- package/src/infrastructure/services/image-feature-executor.service.ts +26 -5
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
|
|
|
@@ -45,17 +45,38 @@ export interface ImageFeatureRequest {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Default result extractor - handles common response formats
|
|
48
|
+
* Supports both direct response and data-wrapped response (fal.ai)
|
|
48
49
|
*/
|
|
49
50
|
function defaultExtractImageResult(result: unknown): string | undefined {
|
|
50
51
|
if (typeof result !== "object" || result === null) return undefined;
|
|
51
52
|
|
|
52
53
|
const r = result as Record<string, unknown>;
|
|
53
54
|
|
|
54
|
-
if (typeof
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
56
|
+
console.log("[ImageExtractor] Result keys:", Object.keys(r));
|
|
57
|
+
console.log("[ImageExtractor] Has data:", !!r.data);
|
|
58
|
+
console.log("[ImageExtractor] Has images:", !!r.images);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Handle fal.ai data wrapper
|
|
62
|
+
const data = (r.data as Record<string, unknown>) ?? r;
|
|
63
|
+
|
|
64
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
65
|
+
console.log("[ImageExtractor] Data keys:", Object.keys(data));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (typeof data.image === "string") return data.image;
|
|
69
|
+
if (typeof data.imageUrl === "string") return data.imageUrl;
|
|
70
|
+
if (typeof data.output === "string") return data.output;
|
|
71
|
+
if (Array.isArray(data.images) && typeof data.images[0]?.url === "string") {
|
|
72
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
73
|
+
console.log("[ImageExtractor] Found images[0].url:", data.images[0].url);
|
|
74
|
+
}
|
|
75
|
+
return data.images[0].url;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
79
|
+
console.log("[ImageExtractor] No image URL found in result");
|
|
59
80
|
}
|
|
60
81
|
|
|
61
82
|
return undefined;
|