@umituz/react-native-ai-generation-content 1.17.115 → 1.17.116
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
|
@@ -20,36 +20,12 @@ export interface ExecuteTextToImageOptions {
|
|
|
20
20
|
onProgress?: (progress: number) => void;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
|
-
function
|
|
24
|
-
|
|
25
|
-
):
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (typeof result !== "object" || result === null) {
|
|
32
|
-
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
33
|
-
// eslint-disable-next-line no-console
|
|
34
|
-
console.log("[TextToImage] Result is not an object");
|
|
35
|
-
}
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const r = result as Record<string, unknown>;
|
|
40
|
-
|
|
41
|
-
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
42
|
-
// eslint-disable-next-line no-console
|
|
43
|
-
console.log("[TextToImage] Result keys:", Object.keys(r));
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// Check for 'images' array first (most common response format)
|
|
47
|
-
if (Array.isArray(r.images)) {
|
|
48
|
-
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
49
|
-
// eslint-disable-next-line no-console
|
|
50
|
-
console.log("[TextToImage] Found images array:", r.images.length, "items");
|
|
51
|
-
}
|
|
52
|
-
const urls = r.images
|
|
23
|
+
function extractImagesFromObject(
|
|
24
|
+
obj: Record<string, unknown>,
|
|
25
|
+
): string[] | null {
|
|
26
|
+
// Direct images array
|
|
27
|
+
if (Array.isArray(obj.images)) {
|
|
28
|
+
const urls = obj.images
|
|
53
29
|
.map((img) => {
|
|
54
30
|
if (typeof img === "string") return img;
|
|
55
31
|
if (img && typeof img === "object" && "url" in img) {
|
|
@@ -59,15 +35,35 @@ function defaultExtractResult(
|
|
|
59
35
|
})
|
|
60
36
|
.filter((url): url is string => url !== null);
|
|
61
37
|
|
|
62
|
-
if (urls.length > 0)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
38
|
+
if (urls.length > 0) return urls;
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function defaultExtractResult(
|
|
44
|
+
result: unknown,
|
|
45
|
+
): { imageUrl?: string; imageUrls?: string[] } | undefined {
|
|
46
|
+
if (typeof result !== "object" || result === null) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const r = result as Record<string, unknown>;
|
|
51
|
+
|
|
52
|
+
// Check nested 'data' object first (common API wrapper format)
|
|
53
|
+
if (r.data && typeof r.data === "object") {
|
|
54
|
+
const dataObj = r.data as Record<string, unknown>;
|
|
55
|
+
const urls = extractImagesFromObject(dataObj);
|
|
56
|
+
if (urls) {
|
|
67
57
|
return { imageUrl: urls[0], imageUrls: urls };
|
|
68
58
|
}
|
|
69
59
|
}
|
|
70
60
|
|
|
61
|
+
// Check direct 'images' array
|
|
62
|
+
const directUrls = extractImagesFromObject(r);
|
|
63
|
+
if (directUrls) {
|
|
64
|
+
return { imageUrl: directUrls[0], imageUrls: directUrls };
|
|
65
|
+
}
|
|
66
|
+
|
|
71
67
|
// Check for imageUrl (data URL)
|
|
72
68
|
if (typeof r.imageUrl === "string") {
|
|
73
69
|
return { imageUrl: r.imageUrl, imageUrls: [r.imageUrl] };
|
|
@@ -85,11 +81,6 @@ function defaultExtractResult(
|
|
|
85
81
|
return { imageUrl: r.image, imageUrls: [r.image] };
|
|
86
82
|
}
|
|
87
83
|
|
|
88
|
-
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
89
|
-
// eslint-disable-next-line no-console
|
|
90
|
-
console.log("[TextToImage] No image found in result");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
84
|
return undefined;
|
|
94
85
|
}
|
|
95
86
|
|