magic-hour 0.35.0 → 0.37.0
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/README.md +208 -10
- package/dist/client.js +2 -2
- package/dist/core/api-error.d.ts +1 -1
- package/dist/core/api-promise.d.ts +2 -2
- package/dist/core/api-promise.js +2 -1
- package/dist/core/auth.d.ts +1 -1
- package/dist/core/auth.js +1 -1
- package/dist/core/binary-response.d.ts +1 -1
- package/dist/core/core-client.d.ts +5 -5
- package/dist/core/core-client.js +2 -5
- package/dist/core/form-data.d.ts +1 -1
- package/dist/core/zod.d.ts +1 -1
- package/dist/core/zod.js +1 -1
- package/dist/environment.d.ts +1 -1
- package/dist/environment.js +1 -1
- package/dist/helpers/download.d.ts +5 -0
- package/dist/helpers/download.js +88 -0
- package/dist/helpers/generate-type.d.ts +51 -0
- package/dist/helpers/generate-type.js +2 -0
- package/dist/helpers/sleep.d.ts +4 -0
- package/dist/helpers/sleep.js +9 -0
- package/dist/logger.d.ts +48 -0
- package/dist/logger.js +97 -0
- package/dist/resources/v1/ai-clothes-changer/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-clothes-changer/request-types.js +1 -1
- package/dist/resources/v1/ai-clothes-changer/resource-client.d.ts +50 -0
- package/dist/resources/v1/ai-clothes-changer/resource-client.js +75 -0
- package/dist/resources/v1/ai-face-editor/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-face-editor/request-types.js +1 -1
- package/dist/resources/v1/ai-face-editor/resource-client.d.ts +55 -0
- package/dist/resources/v1/ai-face-editor/resource-client.js +85 -0
- package/dist/resources/v1/ai-gif-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-gif-generator/request-types.js +1 -1
- package/dist/resources/v1/ai-gif-generator/resource-client.d.ts +29 -0
- package/dist/resources/v1/ai-gif-generator/resource-client.js +60 -0
- package/dist/resources/v1/ai-headshot-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-headshot-generator/request-types.js +1 -1
- package/dist/resources/v1/ai-headshot-generator/resource-client.d.ts +38 -0
- package/dist/resources/v1/ai-headshot-generator/resource-client.js +68 -0
- package/dist/resources/v1/ai-image-editor/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-image-editor/request-types.js +1 -1
- package/dist/resources/v1/ai-image-editor/resource-client.d.ts +39 -0
- package/dist/resources/v1/ai-image-editor/resource-client.js +69 -0
- package/dist/resources/v1/ai-image-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-image-generator/request-types.js +1 -1
- package/dist/resources/v1/ai-image-generator/resource-client.d.ts +31 -0
- package/dist/resources/v1/ai-image-generator/resource-client.js +62 -0
- package/dist/resources/v1/ai-image-upscaler/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-image-upscaler/request-types.js +1 -1
- package/dist/resources/v1/ai-image-upscaler/resource-client.d.ts +40 -0
- package/dist/resources/v1/ai-image-upscaler/resource-client.js +70 -0
- package/dist/resources/v1/ai-meme-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-meme-generator/request-types.js +1 -1
- package/dist/resources/v1/ai-meme-generator/resource-client.d.ts +33 -0
- package/dist/resources/v1/ai-meme-generator/resource-client.js +64 -0
- package/dist/resources/v1/ai-photo-editor/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-photo-editor/request-types.js +1 -1
- package/dist/resources/v1/ai-photo-editor/resource-client.d.ts +49 -0
- package/dist/resources/v1/ai-photo-editor/resource-client.js +79 -0
- package/dist/resources/v1/ai-qr-code-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-qr-code-generator/request-types.js +1 -1
- package/dist/resources/v1/ai-qr-code-generator/resource-client.d.ts +30 -0
- package/dist/resources/v1/ai-qr-code-generator/resource-client.js +61 -0
- package/dist/resources/v1/ai-talking-photo/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-talking-photo/request-types.js +1 -1
- package/dist/resources/v1/ai-talking-photo/resource-client.d.ts +51 -0
- package/dist/resources/v1/ai-talking-photo/resource-client.js +76 -0
- package/dist/resources/v1/animation/request-types.d.ts +1 -1
- package/dist/resources/v1/animation/request-types.js +1 -1
- package/dist/resources/v1/animation/resource-client.d.ts +61 -0
- package/dist/resources/v1/animation/resource-client.js +98 -0
- package/dist/resources/v1/auto-subtitle-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/auto-subtitle-generator/request-types.js +1 -1
- package/dist/resources/v1/auto-subtitle-generator/resource-client.d.ts +41 -0
- package/dist/resources/v1/auto-subtitle-generator/resource-client.js +71 -0
- package/dist/resources/v1/face-detection/request-types.d.ts +1 -1
- package/dist/resources/v1/face-detection/request-types.js +1 -1
- package/dist/resources/v1/face-detection/resource-client.d.ts +30 -0
- package/dist/resources/v1/face-detection/resource-client.js +75 -0
- package/dist/resources/v1/face-swap/request-types.d.ts +7 -1
- package/dist/resources/v1/face-swap/request-types.js +6 -1
- package/dist/resources/v1/face-swap/resource-client.d.ts +77 -0
- package/dist/resources/v1/face-swap/resource-client.js +125 -0
- package/dist/resources/v1/face-swap-photo/request-types.d.ts +1 -1
- package/dist/resources/v1/face-swap-photo/request-types.js +1 -1
- package/dist/resources/v1/face-swap-photo/resource-client.d.ts +73 -0
- package/dist/resources/v1/face-swap-photo/resource-client.js +117 -0
- package/dist/resources/v1/files/resource-client.d.ts +40 -0
- package/dist/resources/v1/files/resource-client.js +236 -0
- package/dist/resources/v1/files/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/files/resource-client.test.js +422 -0
- package/dist/resources/v1/files/upload-urls/request-types.d.ts +1 -1
- package/dist/resources/v1/files/upload-urls/request-types.js +1 -1
- package/dist/resources/v1/image-background-remover/request-types.d.ts +1 -1
- package/dist/resources/v1/image-background-remover/request-types.js +1 -1
- package/dist/resources/v1/image-background-remover/resource-client.d.ts +49 -0
- package/dist/resources/v1/image-background-remover/resource-client.js +82 -0
- package/dist/resources/v1/image-projects/request-types.js +1 -1
- package/dist/resources/v1/image-projects/resource-client.d.ts +22 -0
- package/dist/resources/v1/image-projects/resource-client.js +68 -0
- package/dist/resources/v1/image-projects/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/image-projects/resource-client.test.js +538 -0
- package/dist/resources/v1/image-to-video/request-types.d.ts +1 -1
- package/dist/resources/v1/image-to-video/request-types.js +1 -1
- package/dist/resources/v1/image-to-video/resource-client.d.ts +40 -0
- package/dist/resources/v1/image-to-video/resource-client.js +70 -0
- package/dist/resources/v1/lip-sync/request-types.d.ts +1 -1
- package/dist/resources/v1/lip-sync/request-types.js +1 -1
- package/dist/resources/v1/lip-sync/resource-client.d.ts +53 -0
- package/dist/resources/v1/lip-sync/resource-client.js +84 -0
- package/dist/resources/v1/photo-colorizer/request-types.d.ts +1 -1
- package/dist/resources/v1/photo-colorizer/request-types.js +1 -1
- package/dist/resources/v1/photo-colorizer/resource-client.d.ts +38 -0
- package/dist/resources/v1/photo-colorizer/resource-client.js +68 -0
- package/dist/resources/v1/resource-client.js +3 -3
- package/dist/resources/v1/text-to-video/request-types.d.ts +1 -1
- package/dist/resources/v1/text-to-video/request-types.js +1 -1
- package/dist/resources/v1/text-to-video/resource-client.d.ts +32 -0
- package/dist/resources/v1/text-to-video/resource-client.js +63 -0
- package/dist/resources/v1/video-projects/request-types.js +1 -1
- package/dist/resources/v1/video-projects/resource-client.d.ts +22 -0
- package/dist/resources/v1/video-projects/resource-client.js +68 -0
- package/dist/resources/v1/video-projects/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/video-projects/resource-client.test.js +713 -0
- package/dist/resources/v1/video-to-video/request-types.d.ts +1 -1
- package/dist/resources/v1/video-to-video/request-types.js +1 -1
- package/dist/resources/v1/video-to-video/resource-client.d.ts +48 -0
- package/dist/resources/v1/video-to-video/resource-client.js +84 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/v1-ai-clothes-changer-create-body-assets.js +1 -1
- package/dist/types/v1-ai-clothes-changer-create-body.d.ts +1 -1
- package/dist/types/v1-ai-clothes-changer-create-body.js +2 -2
- package/dist/types/v1-ai-clothes-changer-create-response.js +1 -1
- package/dist/types/v1-ai-face-editor-create-body-assets.js +1 -1
- package/dist/types/v1-ai-face-editor-create-body-style.js +1 -1
- package/dist/types/v1-ai-face-editor-create-body.d.ts +1 -1
- package/dist/types/v1-ai-face-editor-create-body.js +2 -2
- package/dist/types/v1-ai-face-editor-create-response.js +1 -1
- package/dist/types/v1-ai-gif-generator-create-body-style.js +1 -1
- package/dist/types/v1-ai-gif-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-gif-generator-create-body.js +2 -2
- package/dist/types/v1-ai-gif-generator-create-response.js +1 -1
- package/dist/types/v1-ai-headshot-generator-create-body-assets.js +1 -1
- package/dist/types/v1-ai-headshot-generator-create-body-style.js +1 -1
- package/dist/types/v1-ai-headshot-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-headshot-generator-create-body.js +2 -2
- package/dist/types/v1-ai-headshot-generator-create-response.js +1 -1
- package/dist/types/v1-ai-image-editor-create-body-assets.js +1 -1
- package/dist/types/v1-ai-image-editor-create-body-style.js +1 -1
- package/dist/types/v1-ai-image-editor-create-body.d.ts +1 -1
- package/dist/types/v1-ai-image-editor-create-body.js +2 -2
- package/dist/types/v1-ai-image-editor-create-response.js +1 -1
- package/dist/types/v1-ai-image-generator-create-body-style.js +1 -1
- package/dist/types/v1-ai-image-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-image-generator-create-body.js +2 -2
- package/dist/types/v1-ai-image-generator-create-response.js +1 -1
- package/dist/types/v1-ai-image-upscaler-create-body-assets.js +1 -1
- package/dist/types/v1-ai-image-upscaler-create-body-style.js +1 -1
- package/dist/types/v1-ai-image-upscaler-create-body.d.ts +1 -1
- package/dist/types/v1-ai-image-upscaler-create-body.js +2 -2
- package/dist/types/v1-ai-image-upscaler-create-response.js +1 -1
- package/dist/types/v1-ai-meme-generator-create-body-style.js +1 -1
- package/dist/types/v1-ai-meme-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-meme-generator-create-body.js +2 -2
- package/dist/types/v1-ai-meme-generator-create-response.js +1 -1
- package/dist/types/v1-ai-photo-editor-create-body-assets.js +1 -1
- package/dist/types/v1-ai-photo-editor-create-body-style.js +1 -1
- package/dist/types/v1-ai-photo-editor-create-body.d.ts +1 -1
- package/dist/types/v1-ai-photo-editor-create-body.js +2 -2
- package/dist/types/v1-ai-photo-editor-create-response.js +1 -1
- package/dist/types/v1-ai-qr-code-generator-create-body-style.js +1 -1
- package/dist/types/v1-ai-qr-code-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-qr-code-generator-create-body.js +2 -2
- package/dist/types/v1-ai-qr-code-generator-create-response.js +1 -1
- package/dist/types/v1-ai-talking-photo-create-body-assets.js +1 -1
- package/dist/types/v1-ai-talking-photo-create-body-style.js +1 -1
- package/dist/types/v1-ai-talking-photo-create-body.d.ts +1 -1
- package/dist/types/v1-ai-talking-photo-create-body.js +2 -2
- package/dist/types/v1-ai-talking-photo-create-response.js +1 -1
- package/dist/types/v1-animation-create-body-assets.js +1 -1
- package/dist/types/v1-animation-create-body-style.js +1 -1
- package/dist/types/v1-animation-create-body.d.ts +1 -1
- package/dist/types/v1-animation-create-body.js +2 -2
- package/dist/types/v1-animation-create-response.js +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body-assets.js +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body-style-custom-config.js +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body-style.d.ts +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body-style.js +2 -2
- package/dist/types/v1-auto-subtitle-generator-create-body.d.ts +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body.js +2 -2
- package/dist/types/v1-auto-subtitle-generator-create-response.js +1 -1
- package/dist/types/v1-face-detection-create-body-assets.js +1 -1
- package/dist/types/v1-face-detection-create-body.d.ts +1 -1
- package/dist/types/v1-face-detection-create-body.js +2 -2
- package/dist/types/v1-face-detection-create-response.js +1 -1
- package/dist/types/v1-face-detection-get-response-faces-item.js +1 -1
- package/dist/types/v1-face-detection-get-response.d.ts +1 -1
- package/dist/types/v1-face-detection-get-response.js +2 -2
- package/dist/types/v1-face-swap-create-body-assets-face-mappings-item.js +1 -1
- package/dist/types/v1-face-swap-create-body-assets.d.ts +1 -1
- package/dist/types/v1-face-swap-create-body-assets.js +2 -2
- package/dist/types/v1-face-swap-create-body-style-version-enum.d.ts +6 -0
- package/dist/types/v1-face-swap-create-body-style-version-enum.js +2 -0
- package/dist/types/v1-face-swap-create-body-style.d.ts +24 -0
- package/dist/types/v1-face-swap-create-body-style.js +67 -0
- package/dist/types/v1-face-swap-create-body.d.ts +7 -1
- package/dist/types/v1-face-swap-create-body.js +7 -2
- package/dist/types/v1-face-swap-create-response.js +1 -1
- package/dist/types/v1-face-swap-photo-create-body-assets-face-mappings-item.js +1 -1
- package/dist/types/v1-face-swap-photo-create-body-assets.d.ts +1 -1
- package/dist/types/v1-face-swap-photo-create-body-assets.js +2 -2
- package/dist/types/v1-face-swap-photo-create-body.d.ts +1 -1
- package/dist/types/v1-face-swap-photo-create-body.js +2 -2
- package/dist/types/v1-face-swap-photo-create-response.js +1 -1
- package/dist/types/v1-files-upload-urls-create-body-items-item.js +1 -1
- package/dist/types/v1-files-upload-urls-create-body.d.ts +1 -1
- package/dist/types/v1-files-upload-urls-create-body.js +2 -2
- package/dist/types/v1-files-upload-urls-create-response-items-item.js +1 -1
- package/dist/types/v1-files-upload-urls-create-response.d.ts +1 -1
- package/dist/types/v1-files-upload-urls-create-response.js +2 -2
- package/dist/types/v1-image-background-remover-create-body-assets.js +1 -1
- package/dist/types/v1-image-background-remover-create-body.d.ts +1 -1
- package/dist/types/v1-image-background-remover-create-body.js +2 -2
- package/dist/types/v1-image-background-remover-create-response.js +1 -1
- package/dist/types/v1-image-projects-get-response-downloads-item.js +1 -1
- package/dist/types/v1-image-projects-get-response-error.js +1 -1
- package/dist/types/v1-image-projects-get-response.d.ts +1 -1
- package/dist/types/v1-image-projects-get-response.js +2 -2
- package/dist/types/v1-image-to-video-create-body-assets.js +1 -1
- package/dist/types/v1-image-to-video-create-body-style.js +1 -1
- package/dist/types/v1-image-to-video-create-body.d.ts +1 -1
- package/dist/types/v1-image-to-video-create-body.js +2 -2
- package/dist/types/v1-image-to-video-create-response.js +1 -1
- package/dist/types/v1-lip-sync-create-body-assets.js +1 -1
- package/dist/types/v1-lip-sync-create-body.d.ts +1 -1
- package/dist/types/v1-lip-sync-create-body.js +2 -2
- package/dist/types/v1-lip-sync-create-response.js +1 -1
- package/dist/types/v1-photo-colorizer-create-body-assets.js +1 -1
- package/dist/types/v1-photo-colorizer-create-body.d.ts +1 -1
- package/dist/types/v1-photo-colorizer-create-body.js +2 -2
- package/dist/types/v1-photo-colorizer-create-response.js +1 -1
- package/dist/types/v1-text-to-video-create-body-style.js +1 -1
- package/dist/types/v1-text-to-video-create-body.d.ts +1 -1
- package/dist/types/v1-text-to-video-create-body.js +2 -2
- package/dist/types/v1-text-to-video-create-response.js +1 -1
- package/dist/types/v1-video-projects-get-response-download.js +1 -1
- package/dist/types/v1-video-projects-get-response-downloads-item.js +1 -1
- package/dist/types/v1-video-projects-get-response-error.js +1 -1
- package/dist/types/v1-video-projects-get-response.d.ts +1 -1
- package/dist/types/v1-video-projects-get-response.js +2 -2
- package/dist/types/v1-video-to-video-create-body-assets.js +1 -1
- package/dist/types/v1-video-to-video-create-body-style.js +1 -1
- package/dist/types/v1-video-to-video-create-body.d.ts +1 -1
- package/dist/types/v1-video-to-video-create-body.js +2 -2
- package/dist/types/v1-video-to-video-create-response.js +1 -1
- package/package.json +14 -9
package/README.md
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
-
# Magic Hour
|
|
1
|
+
# Magic Hour Node SDK
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/magic-hour)
|
|
4
4
|
|
|
5
|
-
Magic Hour
|
|
5
|
+
The Magic Hour Node SDK provides convenient access to the Magic Hour API via server-side TypeScript or JavaScript.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
## Documentation
|
|
8
|
+
|
|
9
|
+
For full documentation of all APIs, please visit https://docs.magichour.ai
|
|
8
10
|
|
|
9
11
|
If you have any questions, please reach out to us via [discord](https://discord.gg/JX5rgsZaJp).
|
|
10
12
|
|
|
@@ -16,86 +18,274 @@ npm install magic-hour
|
|
|
16
18
|
|
|
17
19
|
## Usage
|
|
18
20
|
|
|
19
|
-
Initialize the client
|
|
20
|
-
|
|
21
21
|
```ts
|
|
22
22
|
import Client from "magic-hour";
|
|
23
|
-
|
|
24
23
|
// generate your API Key at https://magichour.ai/developer
|
|
25
|
-
const client = new Client({
|
|
26
|
-
|
|
24
|
+
const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
25
|
+
const res = await client.v1.faceSwapPhoto.generate(
|
|
26
|
+
{
|
|
27
|
+
assets: {
|
|
28
|
+
faceSwapMode: "all-faces",
|
|
29
|
+
sourceFilePath: "/path/to/source/image.png",
|
|
30
|
+
targetFilePath: "/path/to/target/image.png",
|
|
31
|
+
},
|
|
32
|
+
name: "Face Swap image",
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
waitForCompletion: true,
|
|
36
|
+
downloadOutputs: true,
|
|
37
|
+
downloadDirectory: "outputs",
|
|
38
|
+
},
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
console.log(`Project ID: ${response.id}`)
|
|
42
|
+
console.log(`Status: ${response.status}`)
|
|
43
|
+
console.log(`Downloaded files: ${response.downloaded_paths}`)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Client Functions
|
|
47
|
+
|
|
48
|
+
Most resources that generate media content support two methods:
|
|
49
|
+
|
|
50
|
+
- **`generate()`** - A high-level convenience method that handles the entire workflow
|
|
51
|
+
- **`create()`** - A low-level method that only initiates the generation process
|
|
52
|
+
|
|
53
|
+
### Generate Function
|
|
54
|
+
|
|
55
|
+
The `generate()` function provides a complete end-to-end solution:
|
|
56
|
+
|
|
57
|
+
- Uploads local files to Magic Hour storage
|
|
58
|
+
- Calls the API to start generation
|
|
59
|
+
- Automatically polls for completion
|
|
60
|
+
- Downloads generated files to your local machine
|
|
61
|
+
- Returns both API response data and local file paths
|
|
62
|
+
|
|
63
|
+
**Additional Parameters:**
|
|
64
|
+
|
|
65
|
+
- `waitForCompletion` (boolean, default true): Whether to wait for the project to complete
|
|
66
|
+
- `downloadOutputs` (boolean, default true): Whether to download the generated files
|
|
67
|
+
- `downloadDirectory` (string, optional): Directory to save downloaded files (defaults to current directory)
|
|
68
|
+
|
|
69
|
+
```ts
|
|
70
|
+
const response = await client.v1.faceSwapPhoto.generate(
|
|
71
|
+
{
|
|
72
|
+
assets: {
|
|
73
|
+
faceSwapMode: "all-faces",
|
|
74
|
+
sourceFilePath: "/path/to/source/image.png",
|
|
75
|
+
targetFilePath: "/path/to/target/image.png",
|
|
76
|
+
},
|
|
77
|
+
name: "Face Swap image",
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
waitForCompletion: true, // Wait for status to be complete/error/canceled
|
|
81
|
+
downloadOutputs: true, // Download files automatically
|
|
82
|
+
downloadDirectory: "./outputs/" // Where to save files
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
|
|
86
|
+
// You get both the API response AND downloaded file paths
|
|
87
|
+
console.log(`Project ID: ${response.id}`);
|
|
88
|
+
console.log(`Status: ${response.status}`);
|
|
89
|
+
console.log(`Downloaded files: ${response.downloadedPaths}`);
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
### Create Function
|
|
93
|
+
|
|
94
|
+
The `create()` function provides granular control:
|
|
95
|
+
|
|
96
|
+
- Only calls the API to start the generation process
|
|
97
|
+
- Returns immediately with a project ID and amount of credits used
|
|
98
|
+
- Requires manual status checking and file downloading
|
|
99
|
+
|
|
100
|
+
```ts
|
|
101
|
+
// upload the files to Magic Hour's storage or you can use direct URLs
|
|
102
|
+
const sourceFilePath = await client.v1.files.uploadFile("/path/to/source/image.png")
|
|
103
|
+
const targetFilePath = await client.v1.files.uploadFile("/path/to/target/image.png")
|
|
104
|
+
|
|
105
|
+
// Create function - only starts the process
|
|
106
|
+
const createResponse = await client.v1.faceSwapPhoto.create({
|
|
107
|
+
assets: {
|
|
108
|
+
faceSwapMode: "all-faces",
|
|
109
|
+
sourceFilePath: sourceFilePath,
|
|
110
|
+
targetFilePath: targetFilePath,
|
|
111
|
+
},
|
|
112
|
+
name: "Face Swap image"
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// You get just the project ID and initial response
|
|
116
|
+
const projectId = createResponse.id;
|
|
117
|
+
console.log(`Started project: ${projectId}`);
|
|
118
|
+
|
|
119
|
+
// You must handle the rest:
|
|
120
|
+
// 1. Poll for completion using the image/video projects API
|
|
121
|
+
const result = await client.v1.imageProjects.checkResults(projectId, {
|
|
122
|
+
waitForCompletion: true,
|
|
123
|
+
downloadOutputs: false,
|
|
27
124
|
});
|
|
125
|
+
|
|
126
|
+
// 2. Download files using the download URLs
|
|
127
|
+
const downloadUrls = result.downloads;
|
|
128
|
+
// Download the files using your preferred method
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
### Choosing Between Which Function to Use
|
|
132
|
+
|
|
133
|
+
**Use `generate()` when:**
|
|
134
|
+
|
|
135
|
+
- You want a simple, one-call solution
|
|
136
|
+
- You're building a straightforward application
|
|
137
|
+
- You don't need custom polling or download logic
|
|
138
|
+
|
|
139
|
+
**Use `create()` when:**
|
|
140
|
+
|
|
141
|
+
- You need custom status checking logic
|
|
142
|
+
- You're integrating with existing job processing systems
|
|
143
|
+
- You want to separate generation initiation from completion handling
|
|
144
|
+
- You need fine-grained control over the entire workflow
|
|
145
|
+
|
|
146
|
+
## Error Handling
|
|
147
|
+
|
|
148
|
+
The Magic Hour SDK includes the `ApiError` class, which includes the request and response data.
|
|
149
|
+
|
|
150
|
+
### Basic Error Handling
|
|
151
|
+
|
|
152
|
+
```ts
|
|
153
|
+
try {
|
|
154
|
+
await client.v1.imageToVideo.generate(
|
|
155
|
+
{
|
|
156
|
+
assets: {
|
|
157
|
+
imageFilePath: "/Users/dhu/Desktop/test-files/suit.jpg",
|
|
158
|
+
},
|
|
159
|
+
endSeconds: 0,
|
|
160
|
+
},
|
|
161
|
+
);
|
|
162
|
+
} catch (error) {
|
|
163
|
+
if (error instanceof ApiError) {
|
|
164
|
+
console.error(`API Error: ${error.message}`); // API Error: 400 was returned from post /v1/image-to-video
|
|
165
|
+
|
|
166
|
+
try {
|
|
167
|
+
const errorData = await error.response.json();
|
|
168
|
+
console.error(`Error Message: ${errorData.message}`); // Error Message: end_seconds must be at least 5
|
|
169
|
+
} catch (parseError) {
|
|
170
|
+
console.error("Could not parse error response");
|
|
171
|
+
}
|
|
172
|
+
} else {
|
|
173
|
+
console.error("Unexpected error:", error);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
28
176
|
```
|
|
29
177
|
|
|
30
|
-
|
|
31
|
-
|
|
178
|
+
## Logging
|
|
179
|
+
|
|
180
|
+
### Logging Levels
|
|
181
|
+
|
|
182
|
+
- `none` - Disable all logging
|
|
183
|
+
- `error` - Only error messages
|
|
184
|
+
- `warn` - Warnings and errors
|
|
185
|
+
- `info` - Info, warnings, and errors
|
|
186
|
+
- `debug` - All messages including request/response details
|
|
187
|
+
|
|
188
|
+
### Environment Variable Configuration
|
|
189
|
+
|
|
190
|
+
You can also configure the logging level using the `MAGIC_HOUR_LOG_LEVEL` environment variable:
|
|
191
|
+
|
|
192
|
+
```bash
|
|
193
|
+
export MAGIC_HOUR_LOG_LEVEL=debug # Enable debug logging
|
|
194
|
+
# or
|
|
195
|
+
export MAGIC_HOUR_LOG_LEVEL=error # Only show errors
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Valid values are: `none`, `error`, `warn`, `info`, `debug` (case insensitive). If not set, defaults to `info`.
|
|
32
199
|
|
|
33
200
|
## Module Documentation and Snippets
|
|
34
201
|
|
|
202
|
+
### [v1](src/resources/v1/README.md)
|
|
203
|
+
|
|
204
|
+
|
|
35
205
|
### [v1.aiClothesChanger](src/resources/v1/ai-clothes-changer/README.md)
|
|
36
206
|
|
|
37
207
|
* [create](src/resources/v1/ai-clothes-changer/README.md#create) - AI Clothes Changer
|
|
208
|
+
* [generate](src/resources/v1/ai-clothes-changer/README.md#generate) - AI Clothes Changer Generate Workflow
|
|
38
209
|
|
|
39
210
|
### [v1.aiFaceEditor](src/resources/v1/ai-face-editor/README.md)
|
|
40
211
|
|
|
41
212
|
* [create](src/resources/v1/ai-face-editor/README.md#create) - AI Face Editor
|
|
213
|
+
* [generate](src/resources/v1/ai-face-editor/README.md#generate) - AI Face Editor Generate Workflow
|
|
42
214
|
|
|
43
215
|
### [v1.aiGifGenerator](src/resources/v1/ai-gif-generator/README.md)
|
|
44
216
|
|
|
45
217
|
* [create](src/resources/v1/ai-gif-generator/README.md#create) - AI GIFs
|
|
218
|
+
* [generate](src/resources/v1/ai-gif-generator/README.md#generate) - AI Gif Generator Generate Workflow
|
|
46
219
|
|
|
47
220
|
### [v1.aiHeadshotGenerator](src/resources/v1/ai-headshot-generator/README.md)
|
|
48
221
|
|
|
49
222
|
* [create](src/resources/v1/ai-headshot-generator/README.md#create) - AI Headshots
|
|
223
|
+
* [generate](src/resources/v1/ai-headshot-generator/README.md#generate) - AI Headshot Generator Generate Workflow
|
|
50
224
|
|
|
51
225
|
### [v1.aiImageEditor](src/resources/v1/ai-image-editor/README.md)
|
|
52
226
|
|
|
53
227
|
* [create](src/resources/v1/ai-image-editor/README.md#create) - AI Image Editor
|
|
228
|
+
* [generate](src/resources/v1/ai-image-editor/README.md#generate) - AI Image Editor Generate Workflow
|
|
54
229
|
|
|
55
230
|
### [v1.aiImageGenerator](src/resources/v1/ai-image-generator/README.md)
|
|
56
231
|
|
|
57
232
|
* [create](src/resources/v1/ai-image-generator/README.md#create) - AI Images
|
|
233
|
+
* [generate](src/resources/v1/ai-image-generator/README.md#generate) - AI Image Generator Generate Workflow
|
|
58
234
|
|
|
59
235
|
### [v1.aiImageUpscaler](src/resources/v1/ai-image-upscaler/README.md)
|
|
60
236
|
|
|
61
237
|
* [create](src/resources/v1/ai-image-upscaler/README.md#create) - AI Image Upscaler
|
|
238
|
+
* [generate](src/resources/v1/ai-image-upscaler/README.md#generate) - AI Image Upscaler Generate Workflow
|
|
62
239
|
|
|
63
240
|
### [v1.aiMemeGenerator](src/resources/v1/ai-meme-generator/README.md)
|
|
64
241
|
|
|
65
242
|
* [create](src/resources/v1/ai-meme-generator/README.md#create) - AI Meme Generator
|
|
243
|
+
* [generate](src/resources/v1/ai-meme-generator/README.md#generate) - AI Meme Generator Generate Workflow
|
|
66
244
|
|
|
67
245
|
### [v1.aiPhotoEditor](src/resources/v1/ai-photo-editor/README.md)
|
|
68
246
|
|
|
69
247
|
* [create](src/resources/v1/ai-photo-editor/README.md#create) - AI Photo Editor
|
|
248
|
+
* [generate](src/resources/v1/ai-photo-editor/README.md#generate) - AI Photo Editor Generate Workflow
|
|
70
249
|
|
|
71
250
|
### [v1.aiQrCodeGenerator](src/resources/v1/ai-qr-code-generator/README.md)
|
|
72
251
|
|
|
73
252
|
* [create](src/resources/v1/ai-qr-code-generator/README.md#create) - AI QR Code
|
|
253
|
+
* [generate](src/resources/v1/ai-qr-code-generator/README.md#generate) - AI Qr Code Generator Generate Workflow
|
|
74
254
|
|
|
75
255
|
### [v1.aiTalkingPhoto](src/resources/v1/ai-talking-photo/README.md)
|
|
76
256
|
|
|
77
257
|
* [create](src/resources/v1/ai-talking-photo/README.md#create) - AI Talking Photo
|
|
258
|
+
* [generate](src/resources/v1/ai-talking-photo/README.md#generate) - AI Talking Photo Generate Workflow
|
|
78
259
|
|
|
79
260
|
### [v1.animation](src/resources/v1/animation/README.md)
|
|
80
261
|
|
|
81
262
|
* [create](src/resources/v1/animation/README.md#create) - Animation
|
|
263
|
+
* [generate](src/resources/v1/animation/README.md#generate) - Animation Generate Workflow
|
|
82
264
|
|
|
83
265
|
### [v1.autoSubtitleGenerator](src/resources/v1/auto-subtitle-generator/README.md)
|
|
84
266
|
|
|
85
267
|
* [create](src/resources/v1/auto-subtitle-generator/README.md#create) - Auto Subtitle Generator
|
|
268
|
+
* [generate](src/resources/v1/auto-subtitle-generator/README.md#generate) - Auto Subtitle Generator Generate Workflow
|
|
86
269
|
|
|
87
270
|
### [v1.faceDetection](src/resources/v1/face-detection/README.md)
|
|
88
271
|
|
|
89
272
|
* [create](src/resources/v1/face-detection/README.md#create) - Face Detection
|
|
273
|
+
* [generate](src/resources/v1/face-detection/README.md#generate) - Face Detection Generate Workflow
|
|
90
274
|
* [get](src/resources/v1/face-detection/README.md#get) - Get face detection details
|
|
91
275
|
|
|
92
276
|
### [v1.faceSwap](src/resources/v1/face-swap/README.md)
|
|
93
277
|
|
|
94
278
|
* [create](src/resources/v1/face-swap/README.md#create) - Face Swap video
|
|
279
|
+
* [generate](src/resources/v1/face-swap/README.md#generate) - Face Swap Generate Workflow
|
|
95
280
|
|
|
96
281
|
### [v1.faceSwapPhoto](src/resources/v1/face-swap-photo/README.md)
|
|
97
282
|
|
|
98
283
|
* [create](src/resources/v1/face-swap-photo/README.md#create) - Face Swap Photo
|
|
284
|
+
* [generate](src/resources/v1/face-swap-photo/README.md#generate) - Face Swap Photo Generate Workflow
|
|
285
|
+
|
|
286
|
+
### [v1.files](src/resources/v1/files/README.md)
|
|
287
|
+
|
|
288
|
+
* [upload-file](src/resources/v1/files/README.md#upload-file) - Upload File
|
|
99
289
|
|
|
100
290
|
### [v1.files.uploadUrls](src/resources/v1/files/upload-urls/README.md)
|
|
101
291
|
|
|
@@ -104,35 +294,43 @@ const client = new Client({
|
|
|
104
294
|
### [v1.imageBackgroundRemover](src/resources/v1/image-background-remover/README.md)
|
|
105
295
|
|
|
106
296
|
* [create](src/resources/v1/image-background-remover/README.md#create) - Image Background Remover
|
|
297
|
+
* [generate](src/resources/v1/image-background-remover/README.md#generate) - Image Background Remover Generate Workflow
|
|
107
298
|
|
|
108
299
|
### [v1.imageProjects](src/resources/v1/image-projects/README.md)
|
|
109
300
|
|
|
301
|
+
* [check-result](src/resources/v1/image-projects/README.md#check-result) - Check results
|
|
110
302
|
* [delete](src/resources/v1/image-projects/README.md#delete) - Delete image
|
|
111
303
|
* [get](src/resources/v1/image-projects/README.md#get) - Get image details
|
|
112
304
|
|
|
113
305
|
### [v1.imageToVideo](src/resources/v1/image-to-video/README.md)
|
|
114
306
|
|
|
115
307
|
* [create](src/resources/v1/image-to-video/README.md#create) - Image-to-Video
|
|
308
|
+
* [generate](src/resources/v1/image-to-video/README.md#generate) - Image To Video Generate Workflow
|
|
116
309
|
|
|
117
310
|
### [v1.lipSync](src/resources/v1/lip-sync/README.md)
|
|
118
311
|
|
|
119
312
|
* [create](src/resources/v1/lip-sync/README.md#create) - Lip Sync
|
|
313
|
+
* [generate](src/resources/v1/lip-sync/README.md#generate) - Lip Sync Generate Workflow
|
|
120
314
|
|
|
121
315
|
### [v1.photoColorizer](src/resources/v1/photo-colorizer/README.md)
|
|
122
316
|
|
|
123
317
|
* [create](src/resources/v1/photo-colorizer/README.md#create) - Photo Colorizer
|
|
318
|
+
* [generate](src/resources/v1/photo-colorizer/README.md#generate) - Photo Colorizer Generate Workflow
|
|
124
319
|
|
|
125
320
|
### [v1.textToVideo](src/resources/v1/text-to-video/README.md)
|
|
126
321
|
|
|
127
322
|
* [create](src/resources/v1/text-to-video/README.md#create) - Text-to-Video
|
|
323
|
+
* [generate](src/resources/v1/text-to-video/README.md#generate) - Text To Video Generate Workflow
|
|
128
324
|
|
|
129
325
|
### [v1.videoProjects](src/resources/v1/video-projects/README.md)
|
|
130
326
|
|
|
327
|
+
* [check-result](src/resources/v1/video-projects/README.md#check-result) - Check results
|
|
131
328
|
* [delete](src/resources/v1/video-projects/README.md#delete) - Delete video
|
|
132
329
|
* [get](src/resources/v1/video-projects/README.md#get) - Get video details
|
|
133
330
|
|
|
134
331
|
### [v1.videoToVideo](src/resources/v1/video-to-video/README.md)
|
|
135
332
|
|
|
136
333
|
* [create](src/resources/v1/video-to-video/README.md#create) - Video-to-Video
|
|
334
|
+
* [generate](src/resources/v1/video-to-video/README.md#generate) - Video To Video Generate Workflow
|
|
137
335
|
|
|
138
336
|
<!-- MODULE DOCS END -->
|
package/dist/client.js
CHANGED
|
@@ -9,9 +9,9 @@ class Client {
|
|
|
9
9
|
this._client = new core_1.CoreClient({
|
|
10
10
|
baseUrl: (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.baseUrl) !== null && _a !== void 0 ? _a : opts === null || opts === void 0 ? void 0 : opts.environment) !== null && _b !== void 0 ? _b : environment_1.Environment.Environment,
|
|
11
11
|
timeout: opts === null || opts === void 0 ? void 0 : opts.timeout,
|
|
12
|
+
auths: { bearerAuth: new core_1.AuthBearer(opts === null || opts === void 0 ? void 0 : opts.token) },
|
|
12
13
|
});
|
|
13
|
-
this._opts =
|
|
14
|
-
this._client.registerAuth("bearerAuth", new core_1.AuthBearer(opts === null || opts === void 0 ? void 0 : opts.token));
|
|
14
|
+
this._opts = opts !== null && opts !== void 0 ? opts : {};
|
|
15
15
|
if (this._opts.lazyLoad === false) {
|
|
16
16
|
this.v1;
|
|
17
17
|
}
|
package/dist/core/api-error.d.ts
CHANGED
package/dist/core/api-promise.js
CHANGED
|
@@ -77,9 +77,10 @@ class ApiPromise extends Promise {
|
|
|
77
77
|
}
|
|
78
78
|
const contentType = (_a = response.headers.get("content-type")) !== null && _a !== void 0 ? _a : "";
|
|
79
79
|
switch (this.getResponseType(contentType)) {
|
|
80
|
-
case "json":
|
|
80
|
+
case "json": {
|
|
81
81
|
const rawJson = yield response.json();
|
|
82
82
|
return responseSchema ? responseSchema.parse(rawJson) : rawJson;
|
|
83
|
+
}
|
|
83
84
|
case "text":
|
|
84
85
|
return (yield response.text());
|
|
85
86
|
case "binary":
|
package/dist/core/auth.d.ts
CHANGED
package/dist/core/auth.js
CHANGED
|
@@ -208,7 +208,7 @@ class OAuth2 {
|
|
|
208
208
|
const accessTokenRaw = jsonpointer.get(tokenResJson, accessTokenPointer);
|
|
209
209
|
const accessToken = typeof accessTokenRaw === "string" ? accessTokenRaw : "";
|
|
210
210
|
const expiresInRaw = jsonpointer.get(tokenResJson, expiresInPointer);
|
|
211
|
-
const expiresInSecs = typeof expiresInRaw
|
|
211
|
+
const expiresInSecs = typeof expiresInRaw === "number" ? expiresInRaw : 600;
|
|
212
212
|
const now = new Date();
|
|
213
213
|
const expiresAt = new Date(now.getTime() + expiresInSecs * 1000);
|
|
214
214
|
return { accessToken, expiresAt };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import * as z from "zod";
|
|
2
|
-
import { Response as NodeResponse } from "node-fetch";
|
|
3
|
-
import { AuthProvider } from "./auth";
|
|
1
|
+
import type * as z from "zod";
|
|
2
|
+
import type { Response as NodeResponse } from "node-fetch";
|
|
3
|
+
import type { AuthProvider } from "./auth";
|
|
4
4
|
import { ApiPromise } from "./api-promise";
|
|
5
|
-
import { QueryStyle } from "./query";
|
|
5
|
+
import { type QueryStyle } from "./query";
|
|
6
6
|
export interface CoreClientProps {
|
|
7
7
|
baseUrl: string | Record<string, string | undefined>;
|
|
8
8
|
timeout?: number | undefined;
|
|
9
|
+
auths?: Record<string, AuthProvider>;
|
|
9
10
|
}
|
|
10
11
|
export type ApiResponse = Response | NodeResponse;
|
|
11
12
|
export type HttpMethod = "get" | "post" | "put" | "patch" | "delete";
|
|
@@ -38,7 +39,6 @@ export declare class CoreClient {
|
|
|
38
39
|
private auths;
|
|
39
40
|
private timeout;
|
|
40
41
|
constructor(props: CoreClientProps);
|
|
41
|
-
registerAuth(name: string, provider: AuthProvider): void;
|
|
42
42
|
private applyAuths;
|
|
43
43
|
buildUrl(path: string, serviceName?: string): string;
|
|
44
44
|
private buildUrlFromCfg;
|
package/dist/core/core-client.js
CHANGED
|
@@ -18,18 +18,15 @@ const query_1 = require("./query");
|
|
|
18
18
|
const content_type_1 = require("./content-type");
|
|
19
19
|
const _DEFAULT_SERVICE_NAME = "__default_service__";
|
|
20
20
|
class CoreClient {
|
|
21
|
-
// private agent: any // TODO
|
|
22
21
|
constructor(props) {
|
|
22
|
+
var _a;
|
|
23
23
|
this.baseUrl =
|
|
24
24
|
typeof props.baseUrl === "string"
|
|
25
25
|
? { [_DEFAULT_SERVICE_NAME]: props.baseUrl }
|
|
26
26
|
: props.baseUrl;
|
|
27
|
-
this.auths = {};
|
|
27
|
+
this.auths = (_a = props.auths) !== null && _a !== void 0 ? _a : {};
|
|
28
28
|
this.timeout = props.timeout;
|
|
29
29
|
}
|
|
30
|
-
registerAuth(name, provider) {
|
|
31
|
-
this.auths[name] = provider;
|
|
32
|
-
}
|
|
33
30
|
applyAuths(cfg) {
|
|
34
31
|
return __awaiter(this, void 0, void 0, function* () {
|
|
35
32
|
var _a;
|
package/dist/core/form-data.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { ReadStream as NodeReadStream } from "node:fs";
|
|
2
2
|
export type UploadFile = FileLike | NodeReadStream;
|
|
3
3
|
export declare function isUploadFile(val: any): val is UploadFile;
|
|
4
4
|
export declare function isNodeReadStream(val: any): val is NodeReadStream;
|
package/dist/core/zod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as z from "zod";
|
|
2
|
-
import { UploadFile } from "./form-data";
|
|
2
|
+
import { type UploadFile } from "./form-data";
|
|
3
3
|
/**
|
|
4
4
|
* Generic function to transform an objects keys from one string to another.
|
|
5
5
|
* If the incoming object does not have a transform key, the original key is retained.
|
package/dist/core/zod.js
CHANGED
|
@@ -44,7 +44,7 @@ const form_data_1 = require("./form-data");
|
|
|
44
44
|
* the value is skipped.
|
|
45
45
|
*/
|
|
46
46
|
function zodTransform(input, transformer) {
|
|
47
|
-
|
|
47
|
+
const transformed = {};
|
|
48
48
|
for (const [key, val] of Object.entries(input)) {
|
|
49
49
|
const toKey = transformer[key];
|
|
50
50
|
if (toKey === null) {
|
package/dist/environment.d.ts
CHANGED
package/dist/environment.js
CHANGED
|
@@ -4,5 +4,5 @@ exports.Environment = void 0;
|
|
|
4
4
|
var Environment;
|
|
5
5
|
(function (Environment) {
|
|
6
6
|
Environment["Environment"] = "https://api.magichour.ai";
|
|
7
|
-
Environment["MockServer"] = "https://api.sideko.dev/v1/mock/magichour/magic-hour/0.
|
|
7
|
+
Environment["MockServer"] = "https://api.sideko.dev/v1/mock/magichour/magic-hour/0.36.0";
|
|
8
8
|
})(Environment || (exports.Environment = Environment = {}));
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { types } from "../index.js";
|
|
2
|
+
/**
|
|
3
|
+
* Download files from the given download URLs
|
|
4
|
+
*/
|
|
5
|
+
export declare function downloadFiles(downloads: (types.V1ImageProjectsGetResponseDownloadsItem | types.V1VideoProjectsGetResponseDownloadsItem)[], downloadDirectory?: string): Promise<string[]>;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
36
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
37
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
38
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
39
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
40
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
41
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
45
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
46
|
+
};
|
|
47
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
+
exports.downloadFiles = downloadFiles;
|
|
49
|
+
const fs = __importStar(require("fs"));
|
|
50
|
+
const path = __importStar(require("path"));
|
|
51
|
+
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
52
|
+
const logger_1 = require("../logger");
|
|
53
|
+
/**
|
|
54
|
+
* Download files from the given download URLs
|
|
55
|
+
*/
|
|
56
|
+
function downloadFiles(downloads, downloadDirectory) {
|
|
57
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
const downloadedPaths = [];
|
|
59
|
+
// Use current working directory if no download directory specified
|
|
60
|
+
const baseDir = downloadDirectory || process.cwd();
|
|
61
|
+
// Ensure the download directory exists
|
|
62
|
+
if (!fs.existsSync(baseDir)) {
|
|
63
|
+
fs.mkdirSync(baseDir, { recursive: true });
|
|
64
|
+
}
|
|
65
|
+
(0, logger_1.getLogger)().debug(`Downloading outputs to ${baseDir}`);
|
|
66
|
+
for (const download of downloads) {
|
|
67
|
+
(0, logger_1.getLogger)().debug(`Downloading output from ${download.url}`);
|
|
68
|
+
try {
|
|
69
|
+
const response = yield (0, node_fetch_1.default)(download.url);
|
|
70
|
+
if (!response.ok) {
|
|
71
|
+
throw new Error(`Failed to download from ${download.url}: ${response.statusText}`);
|
|
72
|
+
}
|
|
73
|
+
const buffer = yield response.arrayBuffer();
|
|
74
|
+
// Extract filename from URL or generate one
|
|
75
|
+
const urlPath = new URL(download.url).pathname;
|
|
76
|
+
const filename = path.basename(urlPath) || `download_${Date.now()}`;
|
|
77
|
+
const filePath = path.join(baseDir, filename);
|
|
78
|
+
fs.writeFileSync(filePath, Buffer.from(buffer));
|
|
79
|
+
(0, logger_1.getLogger)().debug(`Downloaded output to ${filePath}`);
|
|
80
|
+
downloadedPaths.push(filePath);
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
(0, logger_1.getLogger)().error(`Error downloading file from ${download.url}: ${error}`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return downloadedPaths;
|
|
87
|
+
});
|
|
88
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { RequestOptions } from "../core";
|
|
2
|
+
/**
|
|
3
|
+
* Options for the `generate` method.
|
|
4
|
+
*/
|
|
5
|
+
export type GenerateOptions = RequestOptions & {
|
|
6
|
+
/**
|
|
7
|
+
* Whether to wait for the generation to complete before returning the result.
|
|
8
|
+
*
|
|
9
|
+
* @default true
|
|
10
|
+
*/
|
|
11
|
+
waitForCompletion?: boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Whether to download the generated outputs to local disk.
|
|
14
|
+
*
|
|
15
|
+
* @default true
|
|
16
|
+
*/
|
|
17
|
+
downloadOutputs?: boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The directory to save the downloaded outputs.
|
|
20
|
+
*
|
|
21
|
+
* @default undefined
|
|
22
|
+
*/
|
|
23
|
+
downloadDirectory?: string | undefined;
|
|
24
|
+
};
|
|
25
|
+
type FilePathKeys<T> = Extract<keyof T, `${string}FilePath`>;
|
|
26
|
+
type FilePathProps<T> = Pick<T, FilePathKeys<T>>;
|
|
27
|
+
/**
|
|
28
|
+
* A type that allows you to override the `${string}FilePath` fields of the assets object.
|
|
29
|
+
*
|
|
30
|
+
* This is necessary to override the jsdoc for the asset fields, which now support local paths.
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```ts
|
|
34
|
+
* type GenerateRequest = GenerateRequestType<requests.CreateRequest, {
|
|
35
|
+
* // custom jsdoc for the asset field
|
|
36
|
+
* garmentFilePath: string;
|
|
37
|
+
* }>;
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
export type GenerateRequestType<CreateRequest, AssetOverrides extends CreateRequest extends {
|
|
41
|
+
assets: Record<string, any>;
|
|
42
|
+
} ? FilePathProps<CreateRequest["assets"]> & {
|
|
43
|
+
[K in Exclude<keyof AssetOverrides, FilePathKeys<CreateRequest["assets"]> | "faceMappings">]: {
|
|
44
|
+
ERROR: `AssetOverrides can only contain ${FilePathKeys<CreateRequest["assets"]>} or faceMappings`;
|
|
45
|
+
};
|
|
46
|
+
} : {}> = CreateRequest extends {
|
|
47
|
+
assets: Record<string, any>;
|
|
48
|
+
} ? Omit<CreateRequest, "assets"> & {
|
|
49
|
+
assets: Omit<CreateRequest["assets"], `${string}FilePath`> & AssetOverrides;
|
|
50
|
+
} : CreateRequest;
|
|
51
|
+
export {};
|