magic-hour 0.44.0 → 0.45.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/dist/environment.d.ts +1 -1
- package/dist/environment.js +1 -1
- package/dist/resources/v1/ai-clothes-changer/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-face-editor/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-gif-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-headshot-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-image-editor/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-image-editor/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-image-editor/resource-client.js +1 -1
- package/dist/resources/v1/ai-image-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-image-upscaler/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-photo-editor/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-qr-code-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-talking-photo/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-voice-cloner/request-types.d.ts +1 -1
- package/dist/resources/v1/ai-voice-generator/request-types.d.ts +1 -1
- package/dist/resources/v1/animation/request-types.d.ts +1 -1
- package/dist/resources/v1/audio-projects/resource-client.d.ts +9 -10
- package/dist/resources/v1/audio-projects/resource-client.js +8 -9
- package/dist/resources/v1/auto-subtitle-generator/request-types.d.ts +3 -3
- package/dist/resources/v1/face-swap/request-types.d.ts +3 -3
- package/dist/resources/v1/face-swap/resource-client.d.ts +20 -2
- package/dist/resources/v1/face-swap/resource-client.js +20 -2
- package/dist/resources/v1/face-swap-photo/request-types.d.ts +1 -1
- package/dist/resources/v1/files/resource-client.d.ts +13 -3
- package/dist/resources/v1/files/resource-client.js +54 -3
- package/dist/resources/v1/files/resource-client.test.js +45 -0
- package/dist/resources/v1/image-background-remover/request-types.d.ts +1 -1
- package/dist/resources/v1/image-projects/resource-client.d.ts +9 -10
- package/dist/resources/v1/image-projects/resource-client.js +8 -9
- package/dist/resources/v1/image-to-video/request-types.d.ts +1 -1
- package/dist/resources/v1/image-to-video/resource-client.d.ts +20 -2
- package/dist/resources/v1/image-to-video/resource-client.js +20 -2
- package/dist/resources/v1/lip-sync/request-types.d.ts +3 -3
- package/dist/resources/v1/lip-sync/resource-client.d.ts +20 -2
- package/dist/resources/v1/lip-sync/resource-client.js +20 -2
- package/dist/resources/v1/photo-colorizer/request-types.d.ts +1 -1
- package/dist/resources/v1/photo-colorizer/resource-client.d.ts +1 -1
- package/dist/resources/v1/photo-colorizer/resource-client.js +1 -1
- package/dist/resources/v1/text-to-video/request-types.d.ts +1 -1
- package/dist/resources/v1/text-to-video/resource-client.d.ts +20 -2
- package/dist/resources/v1/text-to-video/resource-client.js +20 -2
- package/dist/resources/v1/video-projects/resource-client.d.ts +9 -10
- package/dist/resources/v1/video-projects/resource-client.js +8 -9
- package/dist/resources/v1/video-to-video/request-types.d.ts +3 -3
- package/dist/resources/v1/video-to-video/resource-client.d.ts +20 -2
- package/dist/resources/v1/video-to-video/resource-client.js +20 -2
- package/dist/types/v1-ai-clothes-changer-create-body-assets-garment-type-enum.d.ts +6 -2
- package/dist/types/v1-ai-clothes-changer-create-body-assets.d.ts +9 -5
- package/dist/types/v1-ai-clothes-changer-create-body-assets.js +6 -2
- package/dist/types/v1-ai-clothes-changer-create-body.d.ts +1 -1
- package/dist/types/v1-ai-clothes-changer-create-response.d.ts +1 -1
- package/dist/types/v1-ai-face-editor-create-body-assets.d.ts +1 -1
- package/dist/types/v1-ai-face-editor-create-body.d.ts +1 -1
- package/dist/types/v1-ai-face-editor-create-response.d.ts +1 -1
- package/dist/types/v1-ai-gif-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-gif-generator-create-response.d.ts +1 -1
- package/dist/types/v1-ai-headshot-generator-create-body-assets.d.ts +1 -1
- package/dist/types/v1-ai-headshot-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-headshot-generator-create-response.d.ts +1 -1
- package/dist/types/v1-ai-image-editor-create-body-assets.d.ts +2 -2
- package/dist/types/v1-ai-image-editor-create-body.d.ts +1 -1
- package/dist/types/v1-ai-image-editor-create-response.d.ts +1 -1
- package/dist/types/v1-ai-image-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-image-generator-create-response.d.ts +1 -1
- package/dist/types/v1-ai-image-upscaler-create-body-assets.d.ts +1 -1
- package/dist/types/v1-ai-image-upscaler-create-body.d.ts +1 -1
- package/dist/types/v1-ai-image-upscaler-create-response.d.ts +1 -1
- package/dist/types/v1-ai-meme-generator-create-response.d.ts +1 -1
- package/dist/types/v1-ai-photo-editor-create-body-assets.d.ts +1 -1
- package/dist/types/v1-ai-photo-editor-create-body.d.ts +1 -1
- package/dist/types/v1-ai-photo-editor-create-response.d.ts +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-response.d.ts +1 -1
- package/dist/types/v1-ai-talking-photo-create-body-assets.d.ts +2 -2
- package/dist/types/v1-ai-talking-photo-create-body.d.ts +1 -1
- package/dist/types/v1-ai-talking-photo-create-response.d.ts +1 -1
- package/dist/types/v1-ai-voice-cloner-create-body-assets.d.ts +1 -1
- package/dist/types/v1-ai-voice-cloner-create-body.d.ts +1 -1
- package/dist/types/v1-ai-voice-cloner-create-response.d.ts +1 -1
- package/dist/types/v1-ai-voice-generator-create-body.d.ts +1 -1
- package/dist/types/v1-ai-voice-generator-create-response.d.ts +1 -1
- package/dist/types/v1-animation-create-body-assets.d.ts +2 -2
- package/dist/types/v1-animation-create-body.d.ts +1 -1
- package/dist/types/v1-animation-create-response.d.ts +1 -1
- package/dist/types/v1-audio-projects-get-response.d.ts +2 -2
- package/dist/types/v1-auto-subtitle-generator-create-body-assets.d.ts +1 -1
- package/dist/types/v1-auto-subtitle-generator-create-body.d.ts +3 -3
- package/dist/types/v1-auto-subtitle-generator-create-response.d.ts +1 -1
- package/dist/types/v1-face-detection-create-body-assets.d.ts +1 -1
- package/dist/types/v1-face-swap-create-body-assets-face-mappings-item.d.ts +1 -1
- package/dist/types/v1-face-swap-create-body-assets-face-swap-mode-enum.d.ts +3 -3
- package/dist/types/v1-face-swap-create-body-assets-video-source-enum.d.ts +1 -1
- package/dist/types/v1-face-swap-create-body-assets.d.ts +10 -7
- package/dist/types/v1-face-swap-create-body.d.ts +3 -3
- package/dist/types/v1-face-swap-create-response.d.ts +1 -1
- package/dist/types/v1-face-swap-photo-create-body-assets-face-mappings-item.d.ts +1 -1
- package/dist/types/v1-face-swap-photo-create-body-assets-face-swap-mode-enum.d.ts +3 -3
- package/dist/types/v1-face-swap-photo-create-body-assets.d.ts +5 -5
- package/dist/types/v1-face-swap-photo-create-body.d.ts +1 -1
- package/dist/types/v1-face-swap-photo-create-response.d.ts +1 -1
- package/dist/types/v1-image-background-remover-create-body-assets.d.ts +2 -2
- package/dist/types/v1-image-background-remover-create-body.d.ts +1 -1
- package/dist/types/v1-image-background-remover-create-response.d.ts +1 -1
- package/dist/types/v1-image-projects-get-response.d.ts +2 -2
- package/dist/types/v1-image-to-video-create-body-assets.d.ts +1 -1
- package/dist/types/v1-image-to-video-create-body.d.ts +1 -1
- package/dist/types/v1-image-to-video-create-response.d.ts +1 -1
- package/dist/types/v1-lip-sync-create-body-assets-video-source-enum.d.ts +1 -1
- package/dist/types/v1-lip-sync-create-body-assets.d.ts +7 -4
- package/dist/types/v1-lip-sync-create-body.d.ts +3 -3
- package/dist/types/v1-lip-sync-create-response.d.ts +1 -1
- package/dist/types/v1-photo-colorizer-create-body-assets.d.ts +1 -1
- package/dist/types/v1-photo-colorizer-create-body.d.ts +1 -1
- package/dist/types/v1-photo-colorizer-create-response.d.ts +1 -1
- package/dist/types/v1-text-to-video-create-body.d.ts +1 -1
- package/dist/types/v1-text-to-video-create-response.d.ts +1 -1
- package/dist/types/v1-video-projects-get-response.d.ts +4 -4
- package/dist/types/v1-video-to-video-create-body-assets-video-source-enum.d.ts +1 -1
- package/dist/types/v1-video-to-video-create-body-assets.d.ts +6 -3
- package/dist/types/v1-video-to-video-create-body.d.ts +3 -3
- package/dist/types/v1-video-to-video-create-response.d.ts +1 -1
- package/package.json +2 -2
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.45.0";
|
|
8
8
|
})(Environment || (exports.Environment = Environment = {}));
|
|
@@ -9,7 +9,7 @@ export type CreateRequest = {
|
|
|
9
9
|
*/
|
|
10
10
|
assets: V1AiClothesChangerCreateBodyAssets;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Give your image a custom name for easy identification.
|
|
13
13
|
*/
|
|
14
14
|
name?: string | undefined;
|
|
15
15
|
};
|
|
@@ -10,7 +10,7 @@ export type CreateRequest = {
|
|
|
10
10
|
*/
|
|
11
11
|
assets: V1AiFaceEditorCreateBodyAssets;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Give your image a custom name for easy identification.
|
|
14
14
|
*/
|
|
15
15
|
name?: string | undefined;
|
|
16
16
|
/**
|
|
@@ -5,7 +5,7 @@ import { External$V1AiGifGeneratorCreateBodyStyle, V1AiGifGeneratorCreateBodySty
|
|
|
5
5
|
*/
|
|
6
6
|
export type CreateRequest = {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Give your gif a custom name for easy identification.
|
|
9
9
|
*/
|
|
10
10
|
name?: string | undefined;
|
|
11
11
|
/**
|
|
@@ -10,7 +10,7 @@ export type CreateRequest = {
|
|
|
10
10
|
*/
|
|
11
11
|
assets: V1AiHeadshotGeneratorCreateBodyAssets;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Give your image a custom name for easy identification.
|
|
14
14
|
*/
|
|
15
15
|
name?: string | undefined;
|
|
16
16
|
style?: V1AiHeadshotGeneratorCreateBodyStyle | undefined;
|
|
@@ -10,7 +10,7 @@ export type CreateRequest = {
|
|
|
10
10
|
*/
|
|
11
11
|
assets: V1AiImageEditorCreateBodyAssets;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Give your image a custom name for easy identification.
|
|
14
14
|
*/
|
|
15
15
|
name?: string | undefined;
|
|
16
16
|
style: V1AiImageEditorCreateBodyStyle;
|
|
@@ -10,7 +10,7 @@ export type CreateRequest = {
|
|
|
10
10
|
*/
|
|
11
11
|
assets: V1AiImageUpscalerCreateBodyAssets;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Give your image a custom name for easy identification.
|
|
14
14
|
*/
|
|
15
15
|
name?: string | undefined;
|
|
16
16
|
/**
|
|
@@ -10,7 +10,7 @@ export type CreateRequest = {
|
|
|
10
10
|
*/
|
|
11
11
|
assets: V1AiPhotoEditorCreateBodyAssets;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Give your image a custom name for easy identification.
|
|
14
14
|
*/
|
|
15
15
|
name?: string | undefined;
|
|
16
16
|
/**
|
|
@@ -9,7 +9,7 @@ export type CreateRequest = {
|
|
|
9
9
|
*/
|
|
10
10
|
content: string;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Give your image a custom name for easy identification.
|
|
13
13
|
*/
|
|
14
14
|
name?: string | undefined;
|
|
15
15
|
style: V1AiQrCodeGeneratorCreateBodyStyle;
|
|
@@ -14,7 +14,7 @@ export type CreateRequest = {
|
|
|
14
14
|
*/
|
|
15
15
|
endSeconds: number;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Give your image a custom name for easy identification.
|
|
18
18
|
*/
|
|
19
19
|
name?: string | undefined;
|
|
20
20
|
/**
|
|
@@ -10,7 +10,7 @@ export type CreateRequest = {
|
|
|
10
10
|
*/
|
|
11
11
|
assets: V1AiVoiceClonerCreateBodyAssets;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* Give your audio a custom name for easy identification.
|
|
14
14
|
*/
|
|
15
15
|
name?: string | undefined;
|
|
16
16
|
style: V1AiVoiceClonerCreateBodyStyle;
|
|
@@ -5,7 +5,7 @@ import { External$V1AiVoiceGeneratorCreateBodyStyle, V1AiVoiceGeneratorCreateBod
|
|
|
5
5
|
*/
|
|
6
6
|
export type CreateRequest = {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Give your audio a custom name for easy identification.
|
|
9
9
|
*/
|
|
10
10
|
name?: string | undefined;
|
|
11
11
|
/**
|
|
@@ -36,16 +36,15 @@ export declare class AudioProjectsClient extends CoreResourceClient {
|
|
|
36
36
|
/**
|
|
37
37
|
* Get audio details
|
|
38
38
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* - `
|
|
43
|
-
* - `
|
|
44
|
-
* - `
|
|
45
|
-
* - `
|
|
46
|
-
* - `
|
|
47
|
-
* - `
|
|
48
|
-
*
|
|
39
|
+
* Check the progress of a audio project. The `downloads` field is populated after a successful render.
|
|
40
|
+
*
|
|
41
|
+
* **Statuses**
|
|
42
|
+
* - `queued` — waiting to start
|
|
43
|
+
* - `rendering` — in progress
|
|
44
|
+
* - `complete` — ready; see `downloads`
|
|
45
|
+
* - `error` — a failure occurred (see `error`)
|
|
46
|
+
* - `canceled` — user canceled
|
|
47
|
+
* - `draft` — not used
|
|
49
48
|
*
|
|
50
49
|
* GET /v1/audio-projects/{id}
|
|
51
50
|
*/
|
|
@@ -93,16 +93,15 @@ class AudioProjectsClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
93
93
|
/**
|
|
94
94
|
* Get audio details
|
|
95
95
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* The audio can be one of the following status
|
|
99
|
-
* - `draft` - not currently used
|
|
100
|
-
* - `queued` - the job is queued and waiting for a GPU
|
|
101
|
-
* - `rendering` - the generation is in progress
|
|
102
|
-
* - `complete` - the audio is successful created
|
|
103
|
-
* - `error` - an error occurred during rendering
|
|
104
|
-
* - `canceled` - audio render is canceled by the user
|
|
96
|
+
* Check the progress of a audio project. The `downloads` field is populated after a successful render.
|
|
105
97
|
*
|
|
98
|
+
* **Statuses**
|
|
99
|
+
* - `queued` — waiting to start
|
|
100
|
+
* - `rendering` — in progress
|
|
101
|
+
* - `complete` — ready; see `downloads`
|
|
102
|
+
* - `error` — a failure occurred (see `error`)
|
|
103
|
+
* - `canceled` — user canceled
|
|
104
|
+
* - `draft` — not used
|
|
106
105
|
*
|
|
107
106
|
* GET /v1/audio-projects/{id}
|
|
108
107
|
*/
|
|
@@ -10,15 +10,15 @@ export type CreateRequest = {
|
|
|
10
10
|
*/
|
|
11
11
|
assets: V1AutoSubtitleGeneratorCreateBodyAssets;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* End time of your clip (seconds). Must be greater than start_seconds.
|
|
14
14
|
*/
|
|
15
15
|
endSeconds: number;
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* Give your video a custom name for easy identification.
|
|
18
18
|
*/
|
|
19
19
|
name?: string | undefined;
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
21
|
+
* Start time of your clip (seconds). Must be ≥ 0.
|
|
22
22
|
*/
|
|
23
23
|
startSeconds: number;
|
|
24
24
|
/**
|
|
@@ -10,7 +10,7 @@ export type CreateRequest = {
|
|
|
10
10
|
*/
|
|
11
11
|
assets: V1FaceSwapCreateBodyAssets;
|
|
12
12
|
/**
|
|
13
|
-
*
|
|
13
|
+
* End time of your clip (seconds). Must be greater than start_seconds.
|
|
14
14
|
*/
|
|
15
15
|
endSeconds: number;
|
|
16
16
|
/**
|
|
@@ -24,11 +24,11 @@ export type CreateRequest = {
|
|
|
24
24
|
*/
|
|
25
25
|
height?: number | null | undefined;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Give your video a custom name for easy identification.
|
|
28
28
|
*/
|
|
29
29
|
name?: string | undefined;
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Start time of your clip (seconds). Must be ≥ 0.
|
|
32
32
|
*/
|
|
33
33
|
startSeconds: number;
|
|
34
34
|
/**
|
|
@@ -82,10 +82,28 @@ export declare class FaceSwapClient extends CoreResourceClient {
|
|
|
82
82
|
/**
|
|
83
83
|
* Face Swap Video
|
|
84
84
|
*
|
|
85
|
-
*
|
|
85
|
+
* **What this API does**
|
|
86
86
|
*
|
|
87
|
-
*
|
|
87
|
+
* Create the same Face Swap you can make in the browser, but programmatically, so you can automate it, run it at scale, or connect it to your own app or workflow.
|
|
88
88
|
*
|
|
89
|
+
* **Good for**
|
|
90
|
+
* - Automation and batch processing
|
|
91
|
+
* - Adding face swap into apps, pipelines, or tools
|
|
92
|
+
*
|
|
93
|
+
* **How it works (3 steps)**
|
|
94
|
+
* 1) Upload your inputs (video, image, or audio) with [Generate Upload URLs](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls) and copy the `file_path`.
|
|
95
|
+
* 2) Send a request to create a face swap job with the basic fields.
|
|
96
|
+
* 3) Check the job status until it's `complete`, then download the result from `downloads`.
|
|
97
|
+
*
|
|
98
|
+
* **Key options**
|
|
99
|
+
* - Inputs: usually a file, sometimes a YouTube link, depending on project type
|
|
100
|
+
* - Resolution: free users are limited to 576px; higher plans unlock HD and larger sizes
|
|
101
|
+
* - Extra fields: e.g. `face_swap_mode`, `start_seconds`/`end_seconds`, or a text prompt
|
|
102
|
+
*
|
|
103
|
+
* **Cost**
|
|
104
|
+
* Credits are only charged for the frames that actually render. You'll see an estimate when the job is queued, and the final total after it's done.
|
|
105
|
+
*
|
|
106
|
+
* For detailed examples, see the [product page](https://magichour.ai/products/face-swap).
|
|
89
107
|
*
|
|
90
108
|
* POST /v1/face-swap
|
|
91
109
|
*/
|
|
@@ -136,10 +136,28 @@ class FaceSwapClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
136
136
|
/**
|
|
137
137
|
* Face Swap Video
|
|
138
138
|
*
|
|
139
|
-
*
|
|
139
|
+
* **What this API does**
|
|
140
140
|
*
|
|
141
|
-
*
|
|
141
|
+
* Create the same Face Swap you can make in the browser, but programmatically, so you can automate it, run it at scale, or connect it to your own app or workflow.
|
|
142
142
|
*
|
|
143
|
+
* **Good for**
|
|
144
|
+
* - Automation and batch processing
|
|
145
|
+
* - Adding face swap into apps, pipelines, or tools
|
|
146
|
+
*
|
|
147
|
+
* **How it works (3 steps)**
|
|
148
|
+
* 1) Upload your inputs (video, image, or audio) with [Generate Upload URLs](https://docs.magichour.ai/api-reference/files/generate-asset-upload-urls) and copy the `file_path`.
|
|
149
|
+
* 2) Send a request to create a face swap job with the basic fields.
|
|
150
|
+
* 3) Check the job status until it's `complete`, then download the result from `downloads`.
|
|
151
|
+
*
|
|
152
|
+
* **Key options**
|
|
153
|
+
* - Inputs: usually a file, sometimes a YouTube link, depending on project type
|
|
154
|
+
* - Resolution: free users are limited to 576px; higher plans unlock HD and larger sizes
|
|
155
|
+
* - Extra fields: e.g. `face_swap_mode`, `start_seconds`/`end_seconds`, or a text prompt
|
|
156
|
+
*
|
|
157
|
+
* **Cost**
|
|
158
|
+
* Credits are only charged for the frames that actually render. You'll see an estimate when the job is queued, and the final total after it's done.
|
|
159
|
+
*
|
|
160
|
+
* For detailed examples, see the [product page](https://magichour.ai/products/face-swap).
|
|
143
161
|
*
|
|
144
162
|
* POST /v1/face-swap
|
|
145
163
|
*/
|
|
@@ -9,7 +9,7 @@ export type CreateRequest = {
|
|
|
9
9
|
*/
|
|
10
10
|
assets: V1FaceSwapPhotoCreateBodyAssets;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Give your image a custom name for easy identification.
|
|
13
13
|
*/
|
|
14
14
|
name?: string | undefined;
|
|
15
15
|
};
|
|
@@ -13,14 +13,20 @@ export declare class FilesClient extends CoreResourceClient {
|
|
|
13
13
|
* a file path that can be used as input for other Magic Hour API endpoints.
|
|
14
14
|
* The file type is automatically detected from the file extension.
|
|
15
15
|
*
|
|
16
|
+
* If a URL (http:// or https://) or an already-uploaded path (api-assets/...)
|
|
17
|
+
* is provided, it will be returned as-is without uploading.
|
|
18
|
+
*
|
|
16
19
|
* @param file - The file to upload. Can be:
|
|
17
|
-
* - **string**: Path to a local file (e.g., "/path/to/image.jpg")
|
|
20
|
+
* - **string**: Path to a local file (e.g., "/path/to/image.jpg"),
|
|
21
|
+
* a URL (e.g., "https://example.com/image.jpg"), or
|
|
22
|
+
* an already-uploaded path (e.g., "api-assets/id/1234.png")
|
|
18
23
|
* - **Buffer**: File content as buffer (requires extension detection via other means)
|
|
19
24
|
* - **Readable**: Node.js readable stream (must have a 'path' property)
|
|
20
25
|
* - **File**: File object (browser environment)
|
|
21
26
|
*
|
|
22
|
-
* @returns The
|
|
23
|
-
*
|
|
27
|
+
* @returns The file path that can be used as input for other API endpoints.
|
|
28
|
+
* For local files, this will be the uploaded path in Magic Hour's storage.
|
|
29
|
+
* For URLs and already-uploaded paths, this will be the input string as-is.
|
|
24
30
|
*
|
|
25
31
|
* @throws {Error} If the specified local file doesn't exist.
|
|
26
32
|
* @throws {Error} If the file type is not supported.
|
|
@@ -36,6 +42,10 @@ export declare class FilesClient extends CoreResourceClient {
|
|
|
36
42
|
* const filePath = await client.v1.files.uploadFile("/path/to/your/image.jpg");
|
|
37
43
|
* console.log(`Uploaded file: ${filePath}`);
|
|
38
44
|
*
|
|
45
|
+
* // URLs are returned as-is (no upload needed)
|
|
46
|
+
* const urlPath = await client.v1.files.uploadFile("https://example.com/image.jpg");
|
|
47
|
+
* console.log(urlPath); // "https://example.com/image.jpg"
|
|
48
|
+
*
|
|
39
49
|
* // Use the uploaded file in other API calls
|
|
40
50
|
* const result = await client.v1.aiImageUpscaler.create({
|
|
41
51
|
* assets: { imageFilePath: filePath },
|
|
@@ -54,6 +54,25 @@ const fs = __importStar(require("fs"));
|
|
|
54
54
|
const make_api_request_js_1 = require("make-api-request-js");
|
|
55
55
|
const path = __importStar(require("path"));
|
|
56
56
|
const stream_1 = require("stream");
|
|
57
|
+
const logger_1 = require("../../../logger");
|
|
58
|
+
/**
|
|
59
|
+
* Check if the given string is a valid HTTP/HTTPS URL.
|
|
60
|
+
*/
|
|
61
|
+
function isUrl(str) {
|
|
62
|
+
try {
|
|
63
|
+
const url = new URL(str);
|
|
64
|
+
return url.protocol === "http:" || url.protocol === "https:";
|
|
65
|
+
}
|
|
66
|
+
catch (_a) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Check if the given string is an already-uploaded path (api-assets/).
|
|
72
|
+
*/
|
|
73
|
+
function isAlreadyUploaded(str) {
|
|
74
|
+
return str.startsWith("api-assets/");
|
|
75
|
+
}
|
|
57
76
|
/**
|
|
58
77
|
* Determine file type and extension from file path or name.
|
|
59
78
|
*/
|
|
@@ -144,14 +163,20 @@ class FilesClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
144
163
|
* a file path that can be used as input for other Magic Hour API endpoints.
|
|
145
164
|
* The file type is automatically detected from the file extension.
|
|
146
165
|
*
|
|
166
|
+
* If a URL (http:// or https://) or an already-uploaded path (api-assets/...)
|
|
167
|
+
* is provided, it will be returned as-is without uploading.
|
|
168
|
+
*
|
|
147
169
|
* @param file - The file to upload. Can be:
|
|
148
|
-
* - **string**: Path to a local file (e.g., "/path/to/image.jpg")
|
|
170
|
+
* - **string**: Path to a local file (e.g., "/path/to/image.jpg"),
|
|
171
|
+
* a URL (e.g., "https://example.com/image.jpg"), or
|
|
172
|
+
* an already-uploaded path (e.g., "api-assets/id/1234.png")
|
|
149
173
|
* - **Buffer**: File content as buffer (requires extension detection via other means)
|
|
150
174
|
* - **Readable**: Node.js readable stream (must have a 'path' property)
|
|
151
175
|
* - **File**: File object (browser environment)
|
|
152
176
|
*
|
|
153
|
-
* @returns The
|
|
154
|
-
*
|
|
177
|
+
* @returns The file path that can be used as input for other API endpoints.
|
|
178
|
+
* For local files, this will be the uploaded path in Magic Hour's storage.
|
|
179
|
+
* For URLs and already-uploaded paths, this will be the input string as-is.
|
|
155
180
|
*
|
|
156
181
|
* @throws {Error} If the specified local file doesn't exist.
|
|
157
182
|
* @throws {Error} If the file type is not supported.
|
|
@@ -167,6 +192,10 @@ class FilesClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
167
192
|
* const filePath = await client.v1.files.uploadFile("/path/to/your/image.jpg");
|
|
168
193
|
* console.log(`Uploaded file: ${filePath}`);
|
|
169
194
|
*
|
|
195
|
+
* // URLs are returned as-is (no upload needed)
|
|
196
|
+
* const urlPath = await client.v1.files.uploadFile("https://example.com/image.jpg");
|
|
197
|
+
* console.log(urlPath); // "https://example.com/image.jpg"
|
|
198
|
+
*
|
|
170
199
|
* // Use the uploaded file in other API calls
|
|
171
200
|
* const result = await client.v1.aiImageUpscaler.create({
|
|
172
201
|
* assets: { imageFilePath: filePath },
|
|
@@ -177,7 +206,23 @@ class FilesClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
177
206
|
uploadFile(file) {
|
|
178
207
|
return __awaiter(this, void 0, void 0, function* () {
|
|
179
208
|
var _a, e_1, _b, _c;
|
|
209
|
+
const logger = (0, logger_1.getLogger)();
|
|
210
|
+
// If the input is a URL or already-uploaded path, return it as-is
|
|
211
|
+
if (typeof file === "string") {
|
|
212
|
+
if (isUrl(file)) {
|
|
213
|
+
logger.debug(`Skipping upload for ${file} since it is a valid URL`);
|
|
214
|
+
return file;
|
|
215
|
+
}
|
|
216
|
+
else if (isAlreadyUploaded(file)) {
|
|
217
|
+
logger.debug(`Skipping upload for ${file} since it is a valid already-uploaded path`);
|
|
218
|
+
return file;
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
logger.debug(`Processing file input for upload ${file} as a local file`);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
180
224
|
const { filePath, fileData, fileType, extension } = processFileInput(file);
|
|
225
|
+
logger.debug(`File processed: type=${fileType}, extension=${extension}, source=${filePath ? "path" : "data"}`);
|
|
181
226
|
// Create upload URL
|
|
182
227
|
const response = yield this.uploadUrls.create({
|
|
183
228
|
items: [
|
|
@@ -194,14 +239,17 @@ class FilesClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
194
239
|
if (!uploadInfo) {
|
|
195
240
|
throw new Error("Upload info is missing from server response");
|
|
196
241
|
}
|
|
242
|
+
logger.debug(`Received upload URL, target path: ${uploadInfo.filePath}`);
|
|
197
243
|
// Prepare file content
|
|
198
244
|
let content;
|
|
199
245
|
if (filePath) {
|
|
200
246
|
content = fs.readFileSync(filePath);
|
|
247
|
+
logger.debug(`Read ${content.length} bytes from local file: ${filePath}`);
|
|
201
248
|
}
|
|
202
249
|
else if (fileData) {
|
|
203
250
|
if (Buffer.isBuffer(fileData)) {
|
|
204
251
|
content = fileData;
|
|
252
|
+
logger.debug(`Using buffer data: ${content.length} bytes`);
|
|
205
253
|
}
|
|
206
254
|
else if (fileData instanceof stream_1.Readable) {
|
|
207
255
|
// For streams, read all data into buffer
|
|
@@ -222,11 +270,13 @@ class FilesClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
222
270
|
finally { if (e_1) throw e_1.error; }
|
|
223
271
|
}
|
|
224
272
|
content = Buffer.concat(chunks);
|
|
273
|
+
logger.debug(`Read ${content.length} bytes from stream`);
|
|
225
274
|
}
|
|
226
275
|
else if (typeof File !== "undefined" && fileData instanceof File) {
|
|
227
276
|
// File object - convert to buffer
|
|
228
277
|
const arrayBuffer = yield fileData.arrayBuffer();
|
|
229
278
|
content = Buffer.from(arrayBuffer);
|
|
279
|
+
logger.debug(`Read ${content.length} bytes from File object: ${fileData.name}`);
|
|
230
280
|
}
|
|
231
281
|
else {
|
|
232
282
|
throw new Error("Unsupported file data type");
|
|
@@ -246,6 +296,7 @@ class FilesClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
246
296
|
if (!uploadResponse.ok) {
|
|
247
297
|
throw new Error(`Upload failed with status ${uploadResponse.status}: ${uploadResponse.statusText}`);
|
|
248
298
|
}
|
|
299
|
+
logger.debug(`Upload complete: ${uploadInfo.filePath}`);
|
|
249
300
|
return uploadInfo.filePath;
|
|
250
301
|
});
|
|
251
302
|
}
|
|
@@ -100,6 +100,51 @@ describe("FilesClient.uploadFile", () => {
|
|
|
100
100
|
mockFs.existsSync.mockReturnValue(true);
|
|
101
101
|
mockFs.readFileSync.mockReturnValue(Buffer.from("mock file content"));
|
|
102
102
|
});
|
|
103
|
+
describe("URL and already-uploaded path handling", () => {
|
|
104
|
+
test("should return HTTP URL as-is without uploading", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
105
|
+
const url = "http://example.com/image.jpg";
|
|
106
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
107
|
+
const result = yield client.v1.files.uploadFile(url);
|
|
108
|
+
expect(result).toBe(url);
|
|
109
|
+
expect(createSpy).not.toHaveBeenCalled();
|
|
110
|
+
expect(mockFs.existsSync).not.toHaveBeenCalled();
|
|
111
|
+
createSpy.mockRestore();
|
|
112
|
+
}));
|
|
113
|
+
test("should return HTTPS URL as-is without uploading", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
114
|
+
const url = "https://example.com/path/to/video.mp4";
|
|
115
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
116
|
+
const result = yield client.v1.files.uploadFile(url);
|
|
117
|
+
expect(result).toBe(url);
|
|
118
|
+
expect(createSpy).not.toHaveBeenCalled();
|
|
119
|
+
expect(mockFs.existsSync).not.toHaveBeenCalled();
|
|
120
|
+
createSpy.mockRestore();
|
|
121
|
+
}));
|
|
122
|
+
test("should return already-uploaded api-assets path as-is without uploading", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
123
|
+
const apiAssetsPath = "api-assets/12345/image.jpg";
|
|
124
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
125
|
+
const result = yield client.v1.files.uploadFile(apiAssetsPath);
|
|
126
|
+
expect(result).toBe(apiAssetsPath);
|
|
127
|
+
expect(createSpy).not.toHaveBeenCalled();
|
|
128
|
+
expect(mockFs.existsSync).not.toHaveBeenCalled();
|
|
129
|
+
createSpy.mockRestore();
|
|
130
|
+
}));
|
|
131
|
+
test("should handle URLs with query parameters", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
132
|
+
const url = "https://example.com/image.jpg?token=abc123&expires=12345";
|
|
133
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
134
|
+
const result = yield client.v1.files.uploadFile(url);
|
|
135
|
+
expect(result).toBe(url);
|
|
136
|
+
expect(createSpy).not.toHaveBeenCalled();
|
|
137
|
+
createSpy.mockRestore();
|
|
138
|
+
}));
|
|
139
|
+
test("should upload local file paths that look similar to URLs but are not", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
140
|
+
const filePath = "/http/example.com/image.jpg";
|
|
141
|
+
const createSpy = jest.spyOn(client.v1.files.uploadUrls, "create");
|
|
142
|
+
const result = yield client.v1.files.uploadFile(filePath);
|
|
143
|
+
expect(result).toBe("api-assets/12345/image.jpg");
|
|
144
|
+
expect(createSpy).toHaveBeenCalled();
|
|
145
|
+
createSpy.mockRestore();
|
|
146
|
+
}));
|
|
147
|
+
});
|
|
103
148
|
describe("File type detection", () => {
|
|
104
149
|
// MSW handles the uploadUrls.create call automatically
|
|
105
150
|
test("should detect video file types correctly", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -9,7 +9,7 @@ export type CreateRequest = {
|
|
|
9
9
|
*/
|
|
10
10
|
assets: V1ImageBackgroundRemoverCreateBodyAssets;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Give your image a custom name for easy identification.
|
|
13
13
|
*/
|
|
14
14
|
name?: string | undefined;
|
|
15
15
|
};
|
|
@@ -36,16 +36,15 @@ export declare class ImageProjectsClient extends CoreResourceClient {
|
|
|
36
36
|
/**
|
|
37
37
|
* Get image details
|
|
38
38
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* - `
|
|
43
|
-
* - `
|
|
44
|
-
* - `
|
|
45
|
-
* - `
|
|
46
|
-
* - `
|
|
47
|
-
* - `
|
|
48
|
-
*
|
|
39
|
+
* Check the progress of a image project. The `downloads` field is populated after a successful render.
|
|
40
|
+
*
|
|
41
|
+
* **Statuses**
|
|
42
|
+
* - `queued` — waiting to start
|
|
43
|
+
* - `rendering` — in progress
|
|
44
|
+
* - `complete` — ready; see `downloads`
|
|
45
|
+
* - `error` — a failure occurred (see `error`)
|
|
46
|
+
* - `canceled` — user canceled
|
|
47
|
+
* - `draft` — not used
|
|
49
48
|
*
|
|
50
49
|
* GET /v1/image-projects/{id}
|
|
51
50
|
*/
|
|
@@ -93,16 +93,15 @@ class ImageProjectsClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
93
93
|
/**
|
|
94
94
|
* Get image details
|
|
95
95
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* The image can be one of the following status
|
|
99
|
-
* - `draft` - not currently used
|
|
100
|
-
* - `queued` - the job is queued and waiting for a GPU
|
|
101
|
-
* - `rendering` - the generation is in progress
|
|
102
|
-
* - `complete` - the image is successful created
|
|
103
|
-
* - `error` - an error occurred during rendering
|
|
104
|
-
* - `canceled` - image render is canceled by the user
|
|
96
|
+
* Check the progress of a image project. The `downloads` field is populated after a successful render.
|
|
105
97
|
*
|
|
98
|
+
* **Statuses**
|
|
99
|
+
* - `queued` — waiting to start
|
|
100
|
+
* - `rendering` — in progress
|
|
101
|
+
* - `complete` — ready; see `downloads`
|
|
102
|
+
* - `error` — a failure occurred (see `error`)
|
|
103
|
+
* - `canceled` — user canceled
|
|
104
|
+
* - `draft` — not used
|
|
106
105
|
*
|
|
107
106
|
* GET /v1/image-projects/{id}
|
|
108
107
|
*/
|
|
@@ -24,7 +24,7 @@ export type CreateRequest = {
|
|
|
24
24
|
*/
|
|
25
25
|
height?: number | null | undefined;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Give your video a custom name for easy identification.
|
|
28
28
|
*/
|
|
29
29
|
name?: string | undefined;
|
|
30
30
|
/**
|