@umituz/react-native-ai-generation-content 1.17.176 → 1.17.178
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
|
@@ -8,6 +8,7 @@ import { useCallback, useMemo } from "react";
|
|
|
8
8
|
import { useQueryClient } from "@tanstack/react-query";
|
|
9
9
|
import { useAuth } from "@umituz/react-native-auth";
|
|
10
10
|
import { createCreationsRepository } from "../../infrastructure/adapters";
|
|
11
|
+
import { getCreditService, isAppServicesConfigured } from "../../../../infrastructure/config/app-services.config";
|
|
11
12
|
import type { Creation } from "../../domain/entities/Creation";
|
|
12
13
|
|
|
13
14
|
declare const __DEV__: boolean;
|
|
@@ -20,6 +21,8 @@ export interface UseCreationPersistenceConfig {
|
|
|
20
21
|
readonly type: string;
|
|
21
22
|
/** Collection name in Firestore (defaults to "creations") */
|
|
22
23
|
readonly collectionName?: string;
|
|
24
|
+
/** Credit cost to deduct on success (optional, defaults to 0 = no deduction) */
|
|
25
|
+
readonly creditCost?: number;
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
/**
|
|
@@ -118,6 +121,7 @@ export function useCreationPersistence(
|
|
|
118
121
|
creationId: result.creationId,
|
|
119
122
|
hasImageUrl: !!result.imageUrl,
|
|
120
123
|
hasVideoUrl: !!result.videoUrl,
|
|
124
|
+
creditCost: config.creditCost,
|
|
121
125
|
});
|
|
122
126
|
}
|
|
123
127
|
|
|
@@ -146,8 +150,23 @@ export function useCreationPersistence(
|
|
|
146
150
|
output,
|
|
147
151
|
});
|
|
148
152
|
queryClient.invalidateQueries({ queryKey: ["creations"] });
|
|
153
|
+
|
|
154
|
+
// Deduct credits on successful completion
|
|
155
|
+
if (config.creditCost && config.creditCost > 0 && isAppServicesConfigured()) {
|
|
156
|
+
const creditService = getCreditService();
|
|
157
|
+
if (creditService) {
|
|
158
|
+
if (__DEV__) {
|
|
159
|
+
console.log("[useCreationPersistence] Deducting credits", { cost: config.creditCost });
|
|
160
|
+
}
|
|
161
|
+
creditService.deductCredits(config.creditCost).catch((err) => {
|
|
162
|
+
if (__DEV__) {
|
|
163
|
+
console.error("[useCreationPersistence] Credit deduction failed", err);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
}
|
|
149
168
|
},
|
|
150
|
-
[userId, repository, queryClient],
|
|
169
|
+
[userId, repository, queryClient, config.creditCost],
|
|
151
170
|
);
|
|
152
171
|
|
|
153
172
|
const onError = useCallback(
|
|
@@ -45,17 +45,51 @@ export interface VideoFeatureRequest {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* Default result extractor - handles common response formats
|
|
48
|
+
* Supports FAL data wrapper and nested object formats
|
|
48
49
|
*/
|
|
49
50
|
function defaultExtractVideoResult(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("[VideoExtractor] Result keys:", Object.keys(r));
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Handle fal.ai data wrapper
|
|
60
|
+
const data = (r.data as Record<string, unknown>) ?? r;
|
|
61
|
+
|
|
62
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
63
|
+
console.log("[VideoExtractor] Data keys:", Object.keys(data));
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Direct string values
|
|
67
|
+
if (typeof data.video === "string") return data.video;
|
|
68
|
+
if (typeof data.videoUrl === "string") return data.videoUrl;
|
|
69
|
+
if (typeof data.video_url === "string") return data.video_url;
|
|
70
|
+
if (typeof data.output === "string") return data.output;
|
|
71
|
+
if (typeof data.url === "string") return data.url;
|
|
72
|
+
|
|
73
|
+
// Object with url property (e.g., { video: { url: "..." } })
|
|
74
|
+
const videoObj = data.video as Record<string, unknown> | undefined;
|
|
75
|
+
if (videoObj && typeof videoObj === "object" && typeof videoObj.url === "string") {
|
|
76
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
77
|
+
console.log("[VideoExtractor] Found data.video.url:", videoObj.url);
|
|
78
|
+
}
|
|
79
|
+
return videoObj.url;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// Array format (e.g., { videos: [{ url: "..." }] })
|
|
83
|
+
if (Array.isArray(data.videos) && typeof data.videos[0]?.url === "string") {
|
|
84
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
85
|
+
console.log("[VideoExtractor] Found videos[0].url:", data.videos[0].url);
|
|
86
|
+
}
|
|
87
|
+
return data.videos[0].url;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) {
|
|
91
|
+
console.log("[VideoExtractor] No video URL found in result");
|
|
92
|
+
}
|
|
59
93
|
|
|
60
94
|
return undefined;
|
|
61
95
|
}
|