magic-hour 0.41.0 → 0.43.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 +1 -0
- package/dist/environment.d.ts +1 -1
- package/dist/environment.js +1 -1
- package/dist/helpers/generate-type.d.ts +1 -1
- package/dist/resources/v1/ai-gif-generator/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-gif-generator/resource-client.js +1 -1
- package/dist/resources/v1/ai-headshot-generator/resource-client.d.ts +1 -1
- package/dist/resources/v1/ai-headshot-generator/resource-client.js +1 -1
- package/dist/resources/v1/ai-image-editor/resource-client.d.ts +12 -2
- package/dist/resources/v1/ai-image-editor/resource-client.js +13 -7
- package/dist/resources/v1/ai-image-generator/resource-client.d.ts +2 -2
- package/dist/resources/v1/ai-image-generator/resource-client.js +2 -2
- package/dist/resources/v1/ai-qr-code-generator/resource-client.d.ts +2 -2
- package/dist/resources/v1/ai-qr-code-generator/resource-client.js +2 -2
- package/dist/resources/v1/ai-voice-generator/resource-client.d.ts +29 -0
- package/dist/resources/v1/ai-voice-generator/resource-client.js +60 -0
- package/dist/resources/v1/audio-projects/resource-client.d.ts +23 -1
- package/dist/resources/v1/audio-projects/resource-client.js +68 -0
- package/dist/resources/v1/audio-projects/resource-client.test.d.ts +1 -0
- package/dist/resources/v1/audio-projects/resource-client.test.js +552 -0
- package/dist/resources/v1/face-swap/resource-client.d.ts +1 -1
- package/dist/resources/v1/face-swap/resource-client.js +1 -1
- package/dist/resources/v1/files/upload-urls/resource-client.d.ts +3 -2
- package/dist/resources/v1/files/upload-urls/resource-client.js +3 -2
- package/dist/types/index.d.ts +2 -0
- package/dist/types/v1-ai-image-editor-create-body-assets.d.ts +13 -3
- package/dist/types/v1-ai-image-editor-create-body-assets.js +6 -2
- package/dist/types/v1-ai-image-editor-create-body-style-model-enum.d.ts +6 -0
- package/dist/types/v1-ai-image-editor-create-body-style-model-enum.js +2 -0
- package/dist/types/v1-ai-image-editor-create-body-style.d.ts +7 -0
- package/dist/types/v1-ai-image-editor-create-body-style.js +4 -0
- package/dist/types/v1-ai-image-generator-create-body-style-quality-mode-enum.d.ts +10 -0
- package/dist/types/v1-ai-image-generator-create-body-style-quality-mode-enum.js +2 -0
- package/dist/types/v1-ai-image-generator-create-body-style.d.ts +11 -0
- package/dist/types/v1-ai-image-generator-create-body-style.js +4 -0
- package/dist/types/v1-ai-voice-generator-create-body-style-voice-name-enum.d.ts +2 -2
- package/dist/types/v1-ai-voice-generator-create-body-style.d.ts +4 -4
- package/dist/types/v1-ai-voice-generator-create-body-style.js +380 -0
- package/dist/types/v1-audio-projects-get-response.d.ts +1 -1
- package/dist/types/v1-face-swap-create-body-style-version-enum.d.ts +1 -1
- package/dist/types/v1-face-swap-create-body-style.d.ts +1 -1
- package/dist/types/v1-files-upload-urls-create-body-items-item.d.ts +1 -1
- package/dist/types/v1-video-projects-get-response.d.ts +1 -1
- package/dist/types/v1-video-to-video-create-body-style-art-style-enum.d.ts +1 -1
- package/dist/types/v1-video-to-video-create-body-style-model-enum.d.ts +1 -1
- package/dist/types/v1-video-to-video-create-body-style.d.ts +4 -4
- package/dist/types/v1-video-to-video-create-body-style.js +34 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -260,6 +260,7 @@ Valid values are: `none`, `error`, `warn`, `info`, `debug` (case insensitive). I
|
|
|
260
260
|
### [v1.aiVoiceGenerator](src/resources/v1/ai-voice-generator/README.md)
|
|
261
261
|
|
|
262
262
|
* [create](src/resources/v1/ai-voice-generator/README.md#create) - AI Voice Generator
|
|
263
|
+
* [generate](src/resources/v1/ai-voice-generator/README.md#generate) - AI Voice Generator Generate Workflow
|
|
263
264
|
|
|
264
265
|
### [v1.animation](src/resources/v1/animation/README.md)
|
|
265
266
|
|
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.42.1";
|
|
8
8
|
})(Environment || (exports.Environment = Environment = {}));
|
|
@@ -22,7 +22,7 @@ export type GenerateOptions = RequestOptions & {
|
|
|
22
22
|
*/
|
|
23
23
|
downloadDirectory?: string | undefined;
|
|
24
24
|
};
|
|
25
|
-
type FilePathKeys<T> = Extract<keyof T, `${string}FilePath`>;
|
|
25
|
+
type FilePathKeys<T> = Extract<keyof T, `${string}FilePath` | `${string}FilePaths`>;
|
|
26
26
|
type FilePathProps<T> = Pick<T, FilePathKeys<T>>;
|
|
27
27
|
/**
|
|
28
28
|
* A type that allows you to override the `${string}FilePath` fields of the assets object.
|
|
@@ -32,7 +32,7 @@ export declare class AiGifGeneratorClient extends CoreResourceClient {
|
|
|
32
32
|
*/
|
|
33
33
|
generate(request: GenerateRequest, opts?: GenerateOptions): Promise<import("../image-projects/resource-client").V1ImageProjectsGetResponseWithDownloads>;
|
|
34
34
|
/**
|
|
35
|
-
* AI
|
|
35
|
+
* AI GIF Generator
|
|
36
36
|
*
|
|
37
37
|
* Create an AI GIF. Each GIF costs 50 credits.
|
|
38
38
|
*
|
|
@@ -41,7 +41,7 @@ export declare class AiHeadshotGeneratorClient extends CoreResourceClient {
|
|
|
41
41
|
*/
|
|
42
42
|
generate(request: GenerateRequest, opts?: GenerateOptions): Promise<import("../image-projects/resource-client").V1ImageProjectsGetResponseWithDownloads>;
|
|
43
43
|
/**
|
|
44
|
-
* AI
|
|
44
|
+
* AI Headshot Generator
|
|
45
45
|
*
|
|
46
46
|
* Create an AI headshot. Each headshot costs 50 credits.
|
|
47
47
|
*
|
|
@@ -9,8 +9,18 @@ type GenerateRequest = GenerateRequestType<requests.CreateRequest, {
|
|
|
9
9
|
* - a path to a local file
|
|
10
10
|
*
|
|
11
11
|
* Note: if the path begins with `api-assets`, it will be assumed to already be uploaded to Magic Hour's storage, and will not be uploaded again.
|
|
12
|
+
*
|
|
13
|
+
* @deprecated Please use `imageFilePaths` instead as edits with multiple images are now supported.
|
|
14
|
+
*/
|
|
15
|
+
imageFilePath?: string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The image(s) used in the edit. The values in the list are either
|
|
18
|
+
* - a direct URL to the image file
|
|
19
|
+
* - a path to a local file
|
|
20
|
+
*
|
|
21
|
+
* Note: if the path begins with `api-assets`, it will be assumed to already be uploaded to Magic Hour's storage, and will not be uploaded again.
|
|
12
22
|
*/
|
|
13
|
-
|
|
23
|
+
imageFilePaths?: string[] | undefined;
|
|
14
24
|
}>;
|
|
15
25
|
export declare class AiImageEditorClient extends CoreResourceClient {
|
|
16
26
|
constructor(coreClient: CoreClient, opts: ResourceClientOptions);
|
|
@@ -28,7 +38,7 @@ export declare class AiImageEditorClient extends CoreResourceClient {
|
|
|
28
38
|
* const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
29
39
|
* const res = await client.v1.aiImageEditor.generate(
|
|
30
40
|
* {
|
|
31
|
-
* assets: {
|
|
41
|
+
* assets: { imageFilePaths: ["/path/to/1234.png", "/path/to/5678.png"] },
|
|
32
42
|
* name: "Ai Image Editor image",
|
|
33
43
|
* style: { prompt: "Give me sunglasses" },
|
|
34
44
|
* },
|
|
@@ -45,7 +45,7 @@ class AiImageEditorClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
45
45
|
* const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
46
46
|
* const res = await client.v1.aiImageEditor.generate(
|
|
47
47
|
* {
|
|
48
|
-
* assets: {
|
|
48
|
+
* assets: { imageFilePaths: ["/path/to/1234.png", "/path/to/5678.png"] },
|
|
49
49
|
* name: "Ai Image Editor image",
|
|
50
50
|
* style: { prompt: "Give me sunglasses" },
|
|
51
51
|
* },
|
|
@@ -61,13 +61,19 @@ class AiImageEditorClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
61
61
|
return __awaiter(this, arguments, void 0, function* (request, opts = {}) {
|
|
62
62
|
const { waitForCompletion = true, downloadOutputs = true, downloadDirectory = undefined } = opts, createOpts = __rest(opts, ["waitForCompletion", "downloadOutputs", "downloadDirectory"]);
|
|
63
63
|
const fileClient = new files_1.FilesClient(this._client, this._opts);
|
|
64
|
-
const _a = request.assets, { imageFilePath } = _a, restAssets = __rest(_a, ["imageFilePath"]);
|
|
64
|
+
const _a = request.assets, { imageFilePath, imageFilePaths } = _a, restAssets = __rest(_a, ["imageFilePath", "imageFilePaths"]);
|
|
65
65
|
(0, logger_1.getLogger)().debug(`Uploading file ${imageFilePath} to Magic Hour's storage`);
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
66
|
+
let imageFilePathsForApi = [];
|
|
67
|
+
if (imageFilePath) {
|
|
68
|
+
const uploadedImageFilePath = yield fileClient.uploadFile(imageFilePath);
|
|
69
|
+
imageFilePathsForApi.push(uploadedImageFilePath);
|
|
70
|
+
}
|
|
71
|
+
if (imageFilePaths) {
|
|
72
|
+
const uploadedImageFilePaths = yield Promise.all(imageFilePaths.map((filePath) => fileClient.uploadFile(filePath)));
|
|
73
|
+
imageFilePathsForApi.push(...uploadedImageFilePaths);
|
|
74
|
+
}
|
|
75
|
+
(0, logger_1.getLogger)().info(`Uploaded file ${imageFilePath} to Magic Hour's storage as ${imageFilePathsForApi.join(",")}`);
|
|
76
|
+
const createResponse = yield this.create(Object.assign(Object.assign({}, request), { assets: Object.assign(Object.assign({}, restAssets), { imageFilePaths: imageFilePathsForApi }) }), createOpts);
|
|
71
77
|
(0, logger_1.getLogger)().info(`Created AiImageEditorClient project ${createResponse.id}`);
|
|
72
78
|
const projectsClient = new image_projects_1.ImageProjectsClient(this._client, this._opts);
|
|
73
79
|
(0, logger_1.getLogger)().debug(`Checking result for AiImageEditorClient project ${createResponse.id}`);
|
|
@@ -34,9 +34,9 @@ export declare class AiImageGeneratorClient extends CoreResourceClient {
|
|
|
34
34
|
*/
|
|
35
35
|
generate(request: GenerateRequest, opts?: GenerateOptions): Promise<import("../image-projects/resource-client").V1ImageProjectsGetResponseWithDownloads>;
|
|
36
36
|
/**
|
|
37
|
-
* AI
|
|
37
|
+
* AI Image Generator
|
|
38
38
|
*
|
|
39
|
-
* Create an AI image. Each image costs 5 credits.
|
|
39
|
+
* Create an AI image. Each standard image costs 5 credits. Pro quality images cost 30 credits.
|
|
40
40
|
*
|
|
41
41
|
* POST /v1/ai-image-generator
|
|
42
42
|
*/
|
|
@@ -71,9 +71,9 @@ class AiImageGeneratorClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
73
|
/**
|
|
74
|
-
* AI
|
|
74
|
+
* AI Image Generator
|
|
75
75
|
*
|
|
76
|
-
* Create an AI image. Each image costs 5 credits.
|
|
76
|
+
* Create an AI image. Each standard image costs 5 credits. Pro quality images cost 30 credits.
|
|
77
77
|
*
|
|
78
78
|
* POST /v1/ai-image-generator
|
|
79
79
|
*/
|
|
@@ -33,9 +33,9 @@ export declare class AiQrCodeGeneratorClient extends CoreResourceClient {
|
|
|
33
33
|
*/
|
|
34
34
|
generate(request: GenerateRequest, opts?: GenerateOptions): Promise<import("../image-projects/resource-client").V1ImageProjectsGetResponseWithDownloads>;
|
|
35
35
|
/**
|
|
36
|
-
* AI QR Code
|
|
36
|
+
* AI QR Code Generator
|
|
37
37
|
*
|
|
38
|
-
* Create an AI QR code. Each QR code costs
|
|
38
|
+
* Create an AI QR code. Each QR code costs 0 credits.
|
|
39
39
|
*
|
|
40
40
|
* POST /v1/ai-qr-code-generator
|
|
41
41
|
*/
|
|
@@ -70,9 +70,9 @@ class AiQrCodeGeneratorClient extends make_api_request_js_1.CoreResourceClient {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
/**
|
|
73
|
-
* AI QR Code
|
|
73
|
+
* AI QR Code Generator
|
|
74
74
|
*
|
|
75
|
-
* Create an AI QR code. Each QR code costs
|
|
75
|
+
* Create an AI QR code. Each QR code costs 0 credits.
|
|
76
76
|
*
|
|
77
77
|
* POST /v1/ai-qr-code-generator
|
|
78
78
|
*/
|
|
@@ -1,8 +1,36 @@
|
|
|
1
1
|
import { ApiPromise, CoreClient, CoreResourceClient, RequestOptions, ResourceClientOptions } from "make-api-request-js";
|
|
2
|
+
import { GenerateOptions, GenerateRequestType } from "../../../helpers/generate-type";
|
|
2
3
|
import * as requests from "../../../resources/v1/ai-voice-generator/request-types";
|
|
3
4
|
import * as types from "../../../types";
|
|
5
|
+
type GenerateRequest = GenerateRequestType<requests.CreateRequest, {}>;
|
|
4
6
|
export declare class AiVoiceGeneratorClient extends CoreResourceClient {
|
|
5
7
|
constructor(coreClient: CoreClient, opts: ResourceClientOptions);
|
|
8
|
+
/**
|
|
9
|
+
* AI Voice Generator
|
|
10
|
+
*
|
|
11
|
+
* Generate speech from text
|
|
12
|
+
*
|
|
13
|
+
* This method provides a convenient way to create a request and automatically wait for completion and download outputs.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* ```typescript
|
|
17
|
+
* import Client from "../../../index.js";
|
|
18
|
+
*
|
|
19
|
+
* const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
20
|
+
* const res = await client.v1.aiVoiceGenerator.generate(
|
|
21
|
+
* {
|
|
22
|
+
* name: "Voice Generator audio",
|
|
23
|
+
* style: { prompt: "Hello, how are you?", voiceName: "Elon Musk" },
|
|
24
|
+
* },
|
|
25
|
+
* {
|
|
26
|
+
* waitForCompletion: true,
|
|
27
|
+
* downloadOutputs: true,
|
|
28
|
+
* downloadDirectory: "outputs",
|
|
29
|
+
* },
|
|
30
|
+
* );
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
generate(request: GenerateRequest, opts?: GenerateOptions): Promise<import("../image-projects/resource-client").V1ImageProjectsGetResponseWithDownloads>;
|
|
6
34
|
/**
|
|
7
35
|
* AI Voice Generator
|
|
8
36
|
*
|
|
@@ -12,3 +40,4 @@ export declare class AiVoiceGeneratorClient extends CoreResourceClient {
|
|
|
12
40
|
*/
|
|
13
41
|
create(request: requests.CreateRequest, opts?: RequestOptions): ApiPromise<types.V1AiVoiceGeneratorCreateResponse>;
|
|
14
42
|
}
|
|
43
|
+
export {};
|
|
@@ -1,13 +1,73 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
2
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
23
|
exports.AiVoiceGeneratorClient = void 0;
|
|
4
24
|
const make_api_request_js_1 = require("make-api-request-js");
|
|
25
|
+
const logger_1 = require("../../../logger");
|
|
26
|
+
const image_projects_1 = require("../../../resources/v1/image-projects");
|
|
5
27
|
const v1_ai_voice_generator_create_body_1 = require("../../../types/v1-ai-voice-generator-create-body");
|
|
6
28
|
const v1_ai_voice_generator_create_response_1 = require("../../../types/v1-ai-voice-generator-create-response");
|
|
7
29
|
class AiVoiceGeneratorClient extends make_api_request_js_1.CoreResourceClient {
|
|
8
30
|
constructor(coreClient, opts) {
|
|
9
31
|
super(coreClient, opts);
|
|
10
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* AI Voice Generator
|
|
35
|
+
*
|
|
36
|
+
* Generate speech from text
|
|
37
|
+
*
|
|
38
|
+
* This method provides a convenient way to create a request and automatically wait for completion and download outputs.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import Client from "../../../index.js";
|
|
43
|
+
*
|
|
44
|
+
* const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
45
|
+
* const res = await client.v1.aiVoiceGenerator.generate(
|
|
46
|
+
* {
|
|
47
|
+
* name: "Voice Generator audio",
|
|
48
|
+
* style: { prompt: "Hello, how are you?", voiceName: "Elon Musk" },
|
|
49
|
+
* },
|
|
50
|
+
* {
|
|
51
|
+
* waitForCompletion: true,
|
|
52
|
+
* downloadOutputs: true,
|
|
53
|
+
* downloadDirectory: "outputs",
|
|
54
|
+
* },
|
|
55
|
+
* );
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
generate(request_1) {
|
|
59
|
+
return __awaiter(this, arguments, void 0, function* (request, opts = {}) {
|
|
60
|
+
const { waitForCompletion = true, downloadOutputs = true, downloadDirectory = undefined } = opts, createOpts = __rest(opts, ["waitForCompletion", "downloadOutputs", "downloadDirectory"]);
|
|
61
|
+
const createResponse = yield this.create(request, createOpts);
|
|
62
|
+
(0, logger_1.getLogger)().info(`Created AiVoiceGeneratorClient project ${createResponse.id}`);
|
|
63
|
+
const projectsClient = new image_projects_1.ImageProjectsClient(this._client, this._opts);
|
|
64
|
+
(0, logger_1.getLogger)().debug(`Checking result for AiVoiceGeneratorClient project ${createResponse.id}`);
|
|
65
|
+
const result = yield projectsClient.checkResult({ id: createResponse.id }, Object.assign({ waitForCompletion,
|
|
66
|
+
downloadOutputs,
|
|
67
|
+
downloadDirectory }, createOpts));
|
|
68
|
+
return result;
|
|
69
|
+
});
|
|
70
|
+
}
|
|
11
71
|
/**
|
|
12
72
|
* AI Voice Generator
|
|
13
73
|
*
|
|
@@ -1,8 +1,30 @@
|
|
|
1
1
|
import { ApiPromise, CoreClient, CoreResourceClient, RequestOptions, ResourceClientOptions } from "make-api-request-js";
|
|
2
|
+
import { types } from "../../../index.js";
|
|
3
|
+
import { GenerateOptions } from "../../../helpers/generate-type";
|
|
2
4
|
import * as requests from "../../../resources/v1/audio-projects/request-types";
|
|
3
|
-
|
|
5
|
+
/**
|
|
6
|
+
* Extended response interface that includes downloaded paths
|
|
7
|
+
*/
|
|
8
|
+
export interface V1AudioProjectsGetResponseWithDownloads extends types.V1AudioProjectsGetResponse {
|
|
9
|
+
/**
|
|
10
|
+
* The paths to the downloaded files.
|
|
11
|
+
* This field is only populated if `download_outputs` is True and the audio project is complete.
|
|
12
|
+
*/
|
|
13
|
+
downloadedPaths?: string[];
|
|
14
|
+
}
|
|
4
15
|
export declare class AudioProjectsClient extends CoreResourceClient {
|
|
5
16
|
constructor(coreClient: CoreClient, opts: ResourceClientOptions);
|
|
17
|
+
/**
|
|
18
|
+
* Check the result of an audio project with optional waiting and downloading.
|
|
19
|
+
*
|
|
20
|
+
* This method retrieves the status of an audio project and optionally waits for completion
|
|
21
|
+
* and downloads the output files.
|
|
22
|
+
*
|
|
23
|
+
* @param request - Request object containing the audio project ID
|
|
24
|
+
* @param opts - Additional request options
|
|
25
|
+
* @returns The audio project response with optional downloaded file paths included
|
|
26
|
+
*/
|
|
27
|
+
checkResult(request: requests.GetRequest, opts?: GenerateOptions): Promise<V1AudioProjectsGetResponseWithDownloads>;
|
|
6
28
|
/**
|
|
7
29
|
* Delete audio
|
|
8
30
|
*
|
|
@@ -1,12 +1,80 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
2
22
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
23
|
exports.AudioProjectsClient = void 0;
|
|
4
24
|
const make_api_request_js_1 = require("make-api-request-js");
|
|
25
|
+
const download_1 = require("../../../helpers/download");
|
|
26
|
+
const sleep_1 = require("../../../helpers/sleep");
|
|
27
|
+
const logger_1 = require("../../../logger");
|
|
5
28
|
const v1_audio_projects_get_response_1 = require("../../../types/v1-audio-projects-get-response");
|
|
6
29
|
class AudioProjectsClient extends make_api_request_js_1.CoreResourceClient {
|
|
7
30
|
constructor(coreClient, opts) {
|
|
8
31
|
super(coreClient, opts);
|
|
9
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Check the result of an audio project with optional waiting and downloading.
|
|
35
|
+
*
|
|
36
|
+
* This method retrieves the status of an audio project and optionally waits for completion
|
|
37
|
+
* and downloads the output files.
|
|
38
|
+
*
|
|
39
|
+
* @param request - Request object containing the audio project ID
|
|
40
|
+
* @param opts - Additional request options
|
|
41
|
+
* @returns The audio project response with optional downloaded file paths included
|
|
42
|
+
*/
|
|
43
|
+
checkResult(request, opts) {
|
|
44
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
var _a, _b;
|
|
46
|
+
const _c = opts || {}, { waitForCompletion = true, downloadOutputs = true, downloadDirectory = undefined } = _c, requestOpts = __rest(_c, ["waitForCompletion", "downloadOutputs", "downloadDirectory"]);
|
|
47
|
+
let apiResponse = yield this.get({ id: request.id }, requestOpts);
|
|
48
|
+
if (!waitForCompletion) {
|
|
49
|
+
return Object.assign({}, apiResponse);
|
|
50
|
+
}
|
|
51
|
+
const pollInterval = parseFloat(process.env["MAGIC_HOUR_POLL_INTERVAL"] || "0.5");
|
|
52
|
+
(0, logger_1.getLogger)().debug(`Polling audio project ${request.id} every ${pollInterval} seconds`);
|
|
53
|
+
while (!["complete", "error", "canceled"].includes(apiResponse.status)) {
|
|
54
|
+
yield (0, sleep_1.sleep)(pollInterval * 1000); // Convert seconds to milliseconds
|
|
55
|
+
(0, logger_1.getLogger)().info(`Audio project ${request.id} status: ${apiResponse.status}, waiting for ${pollInterval} seconds and checking again`);
|
|
56
|
+
apiResponse = yield this.get({ id: request.id }, requestOpts);
|
|
57
|
+
}
|
|
58
|
+
if (apiResponse.status !== "complete") {
|
|
59
|
+
if (apiResponse.status === "error") {
|
|
60
|
+
const message = `Audio project ${request.id} has status ${apiResponse.status}: [${(_a = apiResponse.error) === null || _a === void 0 ? void 0 : _a.code}] ${(_b = apiResponse.error) === null || _b === void 0 ? void 0 : _b.message}`;
|
|
61
|
+
(0, logger_1.getLogger)().error(message);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
(0, logger_1.getLogger)().info(`Audio project ${request.id} has status ${apiResponse.status}. Stopping polling.`);
|
|
65
|
+
}
|
|
66
|
+
return Object.assign({}, apiResponse);
|
|
67
|
+
}
|
|
68
|
+
if (!downloadOutputs) {
|
|
69
|
+
(0, logger_1.getLogger)().info(`Download outputs is disabled. Returning audio project ${request.id} with status ${apiResponse.status}`);
|
|
70
|
+
return Object.assign({}, apiResponse);
|
|
71
|
+
}
|
|
72
|
+
(0, logger_1.getLogger)().debug(`Downloading outputs for audio project ${request.id} to ${downloadDirectory !== null && downloadDirectory !== void 0 ? downloadDirectory : "current directory"}`);
|
|
73
|
+
const downloadedPaths = yield (0, download_1.downloadFiles)(apiResponse.downloads, downloadDirectory);
|
|
74
|
+
(0, logger_1.getLogger)().info(`Downloaded outputs for audio project ${request.id} to ${downloadedPaths}`);
|
|
75
|
+
return Object.assign(Object.assign({}, apiResponse), { downloadedPaths });
|
|
76
|
+
});
|
|
77
|
+
}
|
|
10
78
|
/**
|
|
11
79
|
* Delete audio
|
|
12
80
|
*
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|