@umituz/react-native-ai-generation-content 1.16.0 → 1.17.1
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 +13 -14
- package/src/domains/creations/domain/entities/Creation.ts +33 -2
- package/src/domains/creations/domain/entities/index.ts +1 -1
- package/src/domains/creations/domain/types/creation-categories.ts +133 -0
- package/src/domains/creations/domain/types/creation-filter.ts +131 -0
- package/src/domains/creations/domain/types/creation-types.ts +63 -0
- package/src/domains/creations/domain/types/index.ts +44 -0
- package/src/domains/creations/domain/utils/creation-helpers.ts +134 -0
- package/src/domains/creations/domain/utils/index.ts +8 -0
- package/src/domains/creations/domain/utils/preview-helpers.ts +84 -0
- package/src/domains/creations/domain/utils/status-helpers.ts +90 -0
- package/src/domains/creations/index.ts +95 -21
- package/src/domains/creations/infrastructure/repositories/CreationsRepository.ts +14 -1
- package/src/domains/creations/presentation/components/CreationActions.tsx +120 -0
- package/src/domains/creations/presentation/components/CreationBadges.tsx +111 -0
- package/src/domains/creations/presentation/components/CreationCard.tsx +201 -102
- package/src/domains/creations/presentation/components/CreationPreview.tsx +117 -0
- package/src/domains/creations/presentation/components/CreationsFilterBar.tsx +254 -0
- package/src/domains/creations/presentation/components/CreationsGrid.tsx +121 -68
- package/src/domains/creations/presentation/components/index.ts +23 -3
- package/src/domains/creations/presentation/hooks/index.ts +1 -0
- package/src/domains/creations/presentation/hooks/useAdvancedFilter.ts +262 -0
- package/src/domains/creations/presentation/screens/CreationsGalleryScreen.tsx +5 -6
- package/src/features/ai-hug/domain/index.ts +5 -0
- package/src/features/ai-hug/domain/types/ai-hug.types.ts +72 -0
- package/src/features/ai-hug/domain/types/index.ts +14 -0
- package/src/features/ai-hug/index.ts +27 -0
- package/src/features/ai-hug/infrastructure/index.ts +5 -0
- package/src/features/ai-hug/infrastructure/services/ai-hug-executor.ts +96 -0
- package/src/features/ai-hug/infrastructure/services/index.ts +6 -0
- package/src/features/ai-hug/presentation/hooks/index.ts +9 -0
- package/src/features/ai-hug/presentation/hooks/useAIHugFeature.ts +157 -0
- package/src/features/ai-hug/presentation/index.ts +5 -0
- package/src/features/ai-kiss/domain/index.ts +5 -0
- package/src/features/ai-kiss/domain/types/ai-kiss.types.ts +72 -0
- package/src/features/ai-kiss/domain/types/index.ts +14 -0
- package/src/features/ai-kiss/index.ts +27 -0
- package/src/features/ai-kiss/infrastructure/index.ts +5 -0
- package/src/features/ai-kiss/infrastructure/services/ai-kiss-executor.ts +96 -0
- package/src/features/ai-kiss/infrastructure/services/index.ts +6 -0
- package/src/features/ai-kiss/presentation/hooks/index.ts +9 -0
- package/src/features/ai-kiss/presentation/hooks/useAIKissFeature.ts +157 -0
- package/src/features/ai-kiss/presentation/index.ts +5 -0
- package/src/features/anime-selfie/domain/index.ts +5 -0
- package/src/features/anime-selfie/domain/types/anime-selfie.types.ts +72 -0
- package/src/features/anime-selfie/domain/types/index.ts +15 -0
- package/src/features/anime-selfie/index.ts +28 -0
- package/src/features/anime-selfie/infrastructure/index.ts +5 -0
- package/src/features/anime-selfie/infrastructure/services/anime-selfie-executor.ts +95 -0
- package/src/features/anime-selfie/infrastructure/services/index.ts +6 -0
- package/src/features/anime-selfie/presentation/hooks/index.ts +9 -0
- package/src/features/anime-selfie/presentation/hooks/useAnimeSelfieFeature.ts +138 -0
- package/src/features/anime-selfie/presentation/index.ts +5 -0
- package/src/features/background/domain/types/index.ts +15 -0
- package/src/features/background/domain/types/replace-background.types.ts +82 -0
- package/src/features/background/index.ts +31 -3
- package/src/features/background/infrastructure/index.ts +5 -0
- package/src/features/background/infrastructure/services/index.ts +6 -0
- package/src/features/background/infrastructure/services/replace-background-executor.ts +95 -0
- package/src/features/background/presentation/hooks/index.ts +6 -1
- package/src/features/background/presentation/hooks/useReplaceBackgroundFeature.ts +160 -0
- package/src/features/face-swap/domain/index.ts +5 -0
- package/src/features/face-swap/domain/types/face-swap.types.ts +72 -0
- package/src/features/face-swap/domain/types/index.ts +14 -0
- package/src/features/face-swap/index.ts +27 -1
- package/src/features/face-swap/infrastructure/index.ts +5 -0
- package/src/features/face-swap/infrastructure/services/face-swap-executor.ts +96 -0
- package/src/features/face-swap/infrastructure/services/index.ts +6 -0
- package/src/features/face-swap/presentation/hooks/index.ts +9 -0
- package/src/features/face-swap/presentation/hooks/useFaceSwapFeature.ts +157 -0
- package/src/features/face-swap/presentation/index.ts +5 -0
- package/src/features/photo-restoration/domain/index.ts +1 -0
- package/src/features/photo-restoration/domain/types/index.ts +10 -0
- package/src/features/photo-restoration/domain/types/photo-restore.types.ts +71 -0
- package/src/features/photo-restoration/index.ts +34 -1
- package/src/features/photo-restoration/infrastructure/index.ts +1 -0
- package/src/features/photo-restoration/infrastructure/services/index.ts +2 -0
- package/src/features/photo-restoration/infrastructure/services/photo-restore-executor.ts +98 -0
- package/src/features/photo-restoration/presentation/components/PhotoRestoreFeature.tsx +175 -0
- package/src/features/photo-restoration/presentation/components/PhotoRestoreResultView.tsx +98 -0
- package/src/features/photo-restoration/presentation/components/index.ts +4 -0
- package/src/features/photo-restoration/presentation/hooks/index.ts +5 -0
- package/src/features/photo-restoration/presentation/hooks/usePhotoRestoreFeature.ts +137 -0
- package/src/features/photo-restoration/presentation/index.ts +2 -0
- package/src/features/remove-background/domain/index.ts +5 -0
- package/src/features/remove-background/domain/types/index.ts +14 -0
- package/src/features/remove-background/domain/types/remove-background.types.ts +69 -0
- package/src/features/remove-background/index.ts +27 -0
- package/src/features/remove-background/infrastructure/index.ts +5 -0
- package/src/features/remove-background/infrastructure/services/index.ts +6 -0
- package/src/features/remove-background/infrastructure/services/remove-background-executor.ts +95 -0
- package/src/features/remove-background/presentation/hooks/index.ts +9 -0
- package/src/features/remove-background/presentation/hooks/useRemoveBackgroundFeature.ts +137 -0
- package/src/features/remove-background/presentation/index.ts +5 -0
- package/src/features/remove-object/domain/index.ts +5 -0
- package/src/features/remove-object/domain/types/index.ts +14 -0
- package/src/features/remove-object/domain/types/remove-object.types.ts +77 -0
- package/src/features/remove-object/index.ts +27 -0
- package/src/features/remove-object/infrastructure/index.ts +5 -0
- package/src/features/remove-object/infrastructure/services/index.ts +6 -0
- package/src/features/remove-object/infrastructure/services/remove-object-executor.ts +99 -0
- package/src/features/remove-object/presentation/hooks/index.ts +9 -0
- package/src/features/remove-object/presentation/hooks/useRemoveObjectFeature.ts +168 -0
- package/src/features/remove-object/presentation/index.ts +5 -0
- package/src/features/upscaling/domain/types/index.ts +0 -1
- package/src/features/upscaling/domain/types/upscale.types.ts +14 -0
- package/src/features/upscaling/index.ts +3 -11
- package/src/features/upscaling/infrastructure/services/index.ts +1 -6
- package/src/features/upscaling/infrastructure/services/upscale-executor.ts +64 -30
- package/src/features/upscaling/presentation/hooks/useUpscaleFeature.ts +12 -7
- package/src/index.ts +45 -0
- package/src/types/jsx.d.ts +19 -0
- package/src/features/face-swap/domain/entities.ts +0 -48
- package/src/features/photo-restoration/domain/entities.ts +0 -48
- package/src/features/upscaling/domain/types/provider.types.ts +0 -23
- package/src/features/upscaling/infrastructure/services/upscale-provider-registry.ts +0 -77
|
@@ -1,64 +1,98 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Upscale Executor
|
|
3
|
-
*
|
|
3
|
+
* Provider-agnostic upscale execution using active AI provider
|
|
4
|
+
* Model and input format are provided via options from app level
|
|
5
|
+
*
|
|
6
|
+
* Note: imageBase64 must be provided in the request. Image URI to base64
|
|
7
|
+
* conversion should be handled at the app level before calling this executor.
|
|
4
8
|
*/
|
|
5
9
|
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
10
|
+
import { providerRegistry } from "../../../../infrastructure/services";
|
|
11
|
+
import { cleanBase64 } from "../../../../infrastructure/utils";
|
|
12
|
+
import type {
|
|
13
|
+
UpscaleRequest,
|
|
14
|
+
UpscaleResult,
|
|
15
|
+
UpscaleInputBuilder,
|
|
16
|
+
UpscaleResultExtractor,
|
|
17
|
+
} from "../../domain/types";
|
|
8
18
|
|
|
9
19
|
declare const __DEV__: boolean;
|
|
10
20
|
|
|
11
21
|
export interface ExecuteUpscaleOptions {
|
|
12
|
-
|
|
22
|
+
model: string;
|
|
23
|
+
buildInput: UpscaleInputBuilder;
|
|
24
|
+
extractResult?: UpscaleResultExtractor;
|
|
13
25
|
onProgress?: (progress: number) => void;
|
|
14
26
|
}
|
|
15
27
|
|
|
28
|
+
function defaultExtractResult(result: unknown): string | undefined {
|
|
29
|
+
if (typeof result !== "object" || result === null) return undefined;
|
|
30
|
+
|
|
31
|
+
const r = result as Record<string, unknown>;
|
|
32
|
+
|
|
33
|
+
if (typeof r.image === "string") return r.image;
|
|
34
|
+
if (Array.isArray(r.images) && r.images[0]?.url) return r.images[0].url;
|
|
35
|
+
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
|
|
16
39
|
export async function executeUpscale(
|
|
17
40
|
request: UpscaleRequest,
|
|
18
|
-
options
|
|
41
|
+
options: ExecuteUpscaleOptions,
|
|
19
42
|
): Promise<UpscaleResult> {
|
|
20
|
-
const provider =
|
|
43
|
+
const provider = providerRegistry.getActiveProvider();
|
|
21
44
|
|
|
22
45
|
if (!provider) {
|
|
23
|
-
return {
|
|
24
|
-
success: false,
|
|
25
|
-
error: "No upscale provider available",
|
|
26
|
-
};
|
|
46
|
+
return { success: false, error: "No AI provider configured" };
|
|
27
47
|
}
|
|
28
48
|
|
|
29
|
-
if (!provider.
|
|
30
|
-
return {
|
|
31
|
-
success: false,
|
|
32
|
-
error: `Provider ${provider.providerId} is not available`,
|
|
33
|
-
};
|
|
49
|
+
if (!provider.isInitialized()) {
|
|
50
|
+
return { success: false, error: "AI provider not initialized" };
|
|
34
51
|
}
|
|
35
52
|
|
|
53
|
+
if (!request.imageBase64) {
|
|
54
|
+
return { success: false, error: "Image base64 is required" };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const { model, buildInput, extractResult, onProgress } = options;
|
|
58
|
+
|
|
36
59
|
if (__DEV__) {
|
|
37
60
|
// eslint-disable-next-line no-console
|
|
38
|
-
console.log(`[
|
|
61
|
+
console.log(`[Upscale] Provider: ${provider.providerId}, Model: ${model}`);
|
|
39
62
|
}
|
|
40
63
|
|
|
41
64
|
try {
|
|
42
|
-
|
|
65
|
+
onProgress?.(10);
|
|
66
|
+
|
|
67
|
+
const base64 = cleanBase64(request.imageBase64);
|
|
68
|
+
onProgress?.(30);
|
|
69
|
+
|
|
70
|
+
const input = buildInput(base64, request.options);
|
|
71
|
+
onProgress?.(40);
|
|
72
|
+
|
|
73
|
+
const result = await provider.run(model, input);
|
|
74
|
+
onProgress?.(90);
|
|
75
|
+
|
|
76
|
+
const extractor = extractResult || defaultExtractResult;
|
|
77
|
+
const imageUrl = extractor(result);
|
|
78
|
+
onProgress?.(100);
|
|
79
|
+
|
|
80
|
+
if (!imageUrl) {
|
|
81
|
+
return { success: false, error: "No image in response" };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return { success: true, imageUrl };
|
|
43
85
|
} catch (error) {
|
|
44
86
|
const message = error instanceof Error ? error.message : String(error);
|
|
45
|
-
|
|
46
87
|
if (__DEV__) {
|
|
47
88
|
// eslint-disable-next-line no-console
|
|
48
|
-
console.error("[
|
|
89
|
+
console.error("[Upscale] Error:", message);
|
|
49
90
|
}
|
|
50
|
-
|
|
51
|
-
return {
|
|
52
|
-
success: false,
|
|
53
|
-
error: message,
|
|
54
|
-
};
|
|
91
|
+
return { success: false, error: message };
|
|
55
92
|
}
|
|
56
93
|
}
|
|
57
94
|
|
|
58
|
-
export function
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
export function hasUpscaleProvider(providerId: string): boolean {
|
|
63
|
-
return upscaleProviderRegistry.hasProvider(providerId);
|
|
95
|
+
export function hasUpscaleSupport(): boolean {
|
|
96
|
+
const provider = providerRegistry.getActiveProvider();
|
|
97
|
+
return provider !== null && provider.isInitialized();
|
|
64
98
|
}
|
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
declare const __DEV__: boolean;
|
|
15
15
|
|
|
16
16
|
export interface UseUpscaleFeatureProps {
|
|
17
|
-
config
|
|
17
|
+
config: UpscaleFeatureConfig;
|
|
18
18
|
userId: string;
|
|
19
19
|
onSelectImage: () => Promise<string | null>;
|
|
20
20
|
onSaveImage: (imageUrl: string) => Promise<void>;
|
|
@@ -46,7 +46,7 @@ export function useUpscaleFeature(
|
|
|
46
46
|
const uri = await onSelectImage();
|
|
47
47
|
if (uri) {
|
|
48
48
|
setState((prev) => ({ ...prev, imageUri: uri, error: null }));
|
|
49
|
-
config
|
|
49
|
+
config.onImageSelect?.(uri);
|
|
50
50
|
}
|
|
51
51
|
} catch (error) {
|
|
52
52
|
const message = error instanceof Error ? error.message : String(error);
|
|
@@ -68,21 +68,26 @@ export function useUpscaleFeature(
|
|
|
68
68
|
error: null,
|
|
69
69
|
}));
|
|
70
70
|
|
|
71
|
-
config
|
|
71
|
+
config.onProcessingStart?.();
|
|
72
72
|
|
|
73
73
|
if (__DEV__) {
|
|
74
74
|
// eslint-disable-next-line no-console
|
|
75
75
|
console.log("[useUpscaleFeature] Starting upscale process");
|
|
76
76
|
}
|
|
77
77
|
|
|
78
|
+
const imageBase64 = await config.prepareImage(state.imageUri);
|
|
79
|
+
|
|
78
80
|
const result: UpscaleResult = await executeUpscale(
|
|
79
81
|
{
|
|
80
82
|
imageUri: state.imageUri,
|
|
83
|
+
imageBase64,
|
|
81
84
|
userId,
|
|
82
|
-
options: { scaleFactor: config
|
|
85
|
+
options: { scaleFactor: config.defaultScaleFactor || 2 },
|
|
83
86
|
},
|
|
84
87
|
{
|
|
85
|
-
|
|
88
|
+
model: config.model,
|
|
89
|
+
buildInput: config.buildInput,
|
|
90
|
+
extractResult: config.extractResult,
|
|
86
91
|
onProgress: handleProgress,
|
|
87
92
|
},
|
|
88
93
|
);
|
|
@@ -95,7 +100,7 @@ export function useUpscaleFeature(
|
|
|
95
100
|
processedUrl: url,
|
|
96
101
|
progress: 100,
|
|
97
102
|
}));
|
|
98
|
-
config
|
|
103
|
+
config.onProcessingComplete?.(result);
|
|
99
104
|
} else {
|
|
100
105
|
const errorMessage = result.error || "Processing failed";
|
|
101
106
|
setState((prev) => ({
|
|
@@ -104,7 +109,7 @@ export function useUpscaleFeature(
|
|
|
104
109
|
error: errorMessage,
|
|
105
110
|
progress: 0,
|
|
106
111
|
}));
|
|
107
|
-
config
|
|
112
|
+
config.onError?.(errorMessage);
|
|
108
113
|
}
|
|
109
114
|
}, [state.imageUri, userId, config, handleProgress]);
|
|
110
115
|
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
* } from '@umituz/react-native-ai-generation-content';
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
|
+
// eslint-disable-next-line no-console
|
|
14
|
+
if (typeof __DEV__ !== "undefined" && __DEV__) console.log("📍 [LIFECYCLE] @umituz/react-native-ai-generation-content/index.ts - Module loading");
|
|
15
|
+
|
|
13
16
|
// =============================================================================
|
|
14
17
|
// DOMAIN LAYER - Types & Interfaces
|
|
15
18
|
// =============================================================================
|
|
@@ -308,3 +311,45 @@ export * from "./features/background";
|
|
|
308
311
|
|
|
309
312
|
export * from "./features/upscaling";
|
|
310
313
|
|
|
314
|
+
// =============================================================================
|
|
315
|
+
// FEATURES - Photo Restoration
|
|
316
|
+
// =============================================================================
|
|
317
|
+
|
|
318
|
+
export * from "./features/photo-restoration";
|
|
319
|
+
|
|
320
|
+
// =============================================================================
|
|
321
|
+
// FEATURES - AI Hug
|
|
322
|
+
// =============================================================================
|
|
323
|
+
|
|
324
|
+
export * from "./features/ai-hug";
|
|
325
|
+
|
|
326
|
+
// =============================================================================
|
|
327
|
+
// FEATURES - AI Kiss
|
|
328
|
+
// =============================================================================
|
|
329
|
+
|
|
330
|
+
export * from "./features/ai-kiss";
|
|
331
|
+
|
|
332
|
+
// =============================================================================
|
|
333
|
+
// FEATURES - Face Swap
|
|
334
|
+
// =============================================================================
|
|
335
|
+
|
|
336
|
+
export * from "./features/face-swap";
|
|
337
|
+
|
|
338
|
+
// =============================================================================
|
|
339
|
+
// FEATURES - Anime Selfie
|
|
340
|
+
// =============================================================================
|
|
341
|
+
|
|
342
|
+
export * from "./features/anime-selfie";
|
|
343
|
+
|
|
344
|
+
// =============================================================================
|
|
345
|
+
// FEATURES - Remove Background
|
|
346
|
+
// =============================================================================
|
|
347
|
+
|
|
348
|
+
export * from "./features/remove-background";
|
|
349
|
+
|
|
350
|
+
// =============================================================================
|
|
351
|
+
// FEATURES - Remove Object
|
|
352
|
+
// =============================================================================
|
|
353
|
+
|
|
354
|
+
export * from "./features/remove-object";
|
|
355
|
+
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* React 19 JSX Compatibility for React Native
|
|
3
|
+
* Fixes JSX namespace issues between React 19 and react-native
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { JSX as ReactJSX } from 'react';
|
|
7
|
+
|
|
8
|
+
declare global {
|
|
9
|
+
namespace JSX {
|
|
10
|
+
interface Element extends ReactJSX.Element {}
|
|
11
|
+
interface ElementClass extends ReactJSX.ElementClass {}
|
|
12
|
+
interface ElementAttributesProperty extends ReactJSX.ElementAttributesProperty {}
|
|
13
|
+
interface ElementChildrenAttribute extends ReactJSX.ElementChildrenAttribute {}
|
|
14
|
+
interface IntrinsicAttributes extends ReactJSX.IntrinsicAttributes {}
|
|
15
|
+
interface IntrinsicClassAttributes<T> extends ReactJSX.IntrinsicClassAttributes<T> {}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export {};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Face Swap Domain Entities
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export interface FaceSwapConfig {
|
|
6
|
-
/**
|
|
7
|
-
* Enhance the face details after swapping
|
|
8
|
-
* @default true
|
|
9
|
-
*/
|
|
10
|
-
enhanceFace?: boolean;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Preserve the skin tone of the target image
|
|
14
|
-
* @default true
|
|
15
|
-
*/
|
|
16
|
-
preserveSkinTone?: boolean;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface FaceSwapRequest {
|
|
20
|
-
/**
|
|
21
|
-
* The target image where the face will be swapped TO.
|
|
22
|
-
* Can be a Base64 string or a remote URL.
|
|
23
|
-
*/
|
|
24
|
-
targetImage: string;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* The source image containing the face to swap FROM.
|
|
28
|
-
* Can be a Base64 string or a remote URL.
|
|
29
|
-
*/
|
|
30
|
-
sourceImage: string;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Optional configuration for the swap process
|
|
34
|
-
*/
|
|
35
|
-
options?: FaceSwapConfig;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface FaceSwapResult {
|
|
39
|
-
/**
|
|
40
|
-
* URL or Base64 of the resulting image
|
|
41
|
-
*/
|
|
42
|
-
imageUrl: string;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Metadata about the generation
|
|
46
|
-
*/
|
|
47
|
-
metadata?: Record<string, unknown>;
|
|
48
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Photo Restoration Domain Entities
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export interface PhotoRestorationConfig {
|
|
6
|
-
/**
|
|
7
|
-
* Whether to fix scratches and creases
|
|
8
|
-
* @default true
|
|
9
|
-
*/
|
|
10
|
-
fixScratches?: boolean;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Whether to enhance faces in the photo
|
|
14
|
-
* @default true
|
|
15
|
-
*/
|
|
16
|
-
enhanceFaces?: boolean;
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Upscale factor for the result
|
|
20
|
-
* @default 2
|
|
21
|
-
*/
|
|
22
|
-
upscaleFactor?: 1 | 2 | 4;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
export interface PhotoRestorationRequest {
|
|
26
|
-
/**
|
|
27
|
-
* The image to restore.
|
|
28
|
-
* Can be a Base64 string or a remote URL.
|
|
29
|
-
*/
|
|
30
|
-
image: string;
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Optional configuration
|
|
34
|
-
*/
|
|
35
|
-
options?: PhotoRestorationConfig;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface PhotoRestorationResult {
|
|
39
|
-
/**
|
|
40
|
-
* The restored image URL or Base64
|
|
41
|
-
*/
|
|
42
|
-
imageUrl: string;
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Metadata about the generation
|
|
46
|
-
*/
|
|
47
|
-
metadata?: Record<string, unknown>;
|
|
48
|
-
}
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Upscale Provider Types
|
|
3
|
-
* Interface for provider implementations
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { UpscaleRequest, UpscaleResult } from "./upscale.types";
|
|
7
|
-
|
|
8
|
-
export interface IUpscaleProvider {
|
|
9
|
-
readonly providerId: string;
|
|
10
|
-
readonly providerName: string;
|
|
11
|
-
|
|
12
|
-
isAvailable(): boolean;
|
|
13
|
-
|
|
14
|
-
upscale(
|
|
15
|
-
request: UpscaleRequest,
|
|
16
|
-
onProgress?: (progress: number) => void,
|
|
17
|
-
): Promise<UpscaleResult>;
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface UpscaleProviderEntry {
|
|
21
|
-
provider: IUpscaleProvider;
|
|
22
|
-
priority: number;
|
|
23
|
-
}
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Upscale Provider Registry
|
|
3
|
-
* Manages registered upscale providers
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type {
|
|
7
|
-
IUpscaleProvider,
|
|
8
|
-
UpscaleProviderEntry,
|
|
9
|
-
} from "../../domain/types";
|
|
10
|
-
|
|
11
|
-
declare const __DEV__: boolean;
|
|
12
|
-
|
|
13
|
-
class UpscaleProviderRegistry {
|
|
14
|
-
private providers: Map<string, UpscaleProviderEntry> = new Map();
|
|
15
|
-
private defaultProviderId: string | null = null;
|
|
16
|
-
|
|
17
|
-
register(provider: IUpscaleProvider, priority = 0): void {
|
|
18
|
-
this.providers.set(provider.providerId, { provider, priority });
|
|
19
|
-
|
|
20
|
-
if (__DEV__) {
|
|
21
|
-
// eslint-disable-next-line no-console
|
|
22
|
-
console.log(
|
|
23
|
-
`[UpscaleRegistry] Registered provider: ${provider.providerId}`,
|
|
24
|
-
);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
unregister(providerId: string): void {
|
|
29
|
-
this.providers.delete(providerId);
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
setDefault(providerId: string): void {
|
|
33
|
-
if (!this.providers.has(providerId)) {
|
|
34
|
-
throw new Error(`Provider ${providerId} not registered`);
|
|
35
|
-
}
|
|
36
|
-
this.defaultProviderId = providerId;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
get(providerId?: string): IUpscaleProvider | null {
|
|
40
|
-
const id = providerId || this.defaultProviderId;
|
|
41
|
-
if (!id) return this.getHighestPriority();
|
|
42
|
-
|
|
43
|
-
const entry = this.providers.get(id);
|
|
44
|
-
return entry?.provider || null;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getAvailable(): IUpscaleProvider | null {
|
|
48
|
-
const sorted = this.getSortedProviders();
|
|
49
|
-
return sorted.find((p) => p.isAvailable()) || null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
hasProvider(providerId: string): boolean {
|
|
53
|
-
return this.providers.has(providerId);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
getProviderIds(): string[] {
|
|
57
|
-
return Array.from(this.providers.keys());
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
private getHighestPriority(): IUpscaleProvider | null {
|
|
61
|
-
const sorted = this.getSortedProviders();
|
|
62
|
-
return sorted[0] || null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
private getSortedProviders(): IUpscaleProvider[] {
|
|
66
|
-
return Array.from(this.providers.values())
|
|
67
|
-
.sort((a, b) => b.priority - a.priority)
|
|
68
|
-
.map((entry) => entry.provider);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
reset(): void {
|
|
72
|
-
this.providers.clear();
|
|
73
|
-
this.defaultProviderId = null;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export const upscaleProviderRegistry = new UpscaleProviderRegistry();
|