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
|
@@ -1,13 +1,138 @@
|
|
|
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.FaceSwapClient = void 0;
|
|
4
24
|
const core_1 = require("../../../core");
|
|
25
|
+
const files_1 = require("../../../resources/v1/files");
|
|
5
26
|
const v1_face_swap_create_body_1 = require("../../../types/v1-face-swap-create-body");
|
|
6
27
|
const v1_face_swap_create_response_1 = require("../../../types/v1-face-swap-create-response");
|
|
28
|
+
const logger_1 = require("../../../logger");
|
|
29
|
+
const video_projects_1 = require("../../../resources/v1/video-projects");
|
|
7
30
|
class FaceSwapClient extends core_1.CoreResourceClient {
|
|
8
31
|
constructor(coreClient, opts) {
|
|
9
32
|
super(coreClient, opts);
|
|
10
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Face Swap video
|
|
36
|
+
*
|
|
37
|
+
* Create a Face Swap video
|
|
38
|
+
*
|
|
39
|
+
* This method provides a convenient way to create a request and automatically wait for completion and download outputs.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import Client from "../../../index.js";
|
|
44
|
+
*
|
|
45
|
+
* const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
46
|
+
* const res = await client.v1.faceSwap.generate(
|
|
47
|
+
* {
|
|
48
|
+
* assets: {
|
|
49
|
+
* faceMappings: [
|
|
50
|
+
* {
|
|
51
|
+
* newFace: "api-assets/id/1234.png",
|
|
52
|
+
* originalFace: "api-assets/id/0-0.png",
|
|
53
|
+
* },
|
|
54
|
+
* ],
|
|
55
|
+
* faceSwapMode: "all-faces",
|
|
56
|
+
* imageFilePath: "image/id/1234.png",
|
|
57
|
+
* videoFilePath: "/path/to/1234.mp4",
|
|
58
|
+
* videoSource: "file",
|
|
59
|
+
* },
|
|
60
|
+
* endSeconds: 15.0,
|
|
61
|
+
* name: "Face Swap video",
|
|
62
|
+
* startSeconds: 0.0,
|
|
63
|
+
* style: { version: "default" },
|
|
64
|
+
* },
|
|
65
|
+
* {
|
|
66
|
+
* waitForCompletion: true,
|
|
67
|
+
* downloadOutputs: true,
|
|
68
|
+
* downloadDirectory: "outputs",
|
|
69
|
+
* },
|
|
70
|
+
* );
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
generate(request_1) {
|
|
74
|
+
return __awaiter(this, arguments, void 0, function* (request, opts = {}) {
|
|
75
|
+
const { waitForCompletion = true, downloadOutputs = true, downloadDirectory = undefined } = opts, createOpts = __rest(opts, ["waitForCompletion", "downloadOutputs", "downloadDirectory"]);
|
|
76
|
+
const fileClient = new files_1.FilesClient(this._client, this._opts);
|
|
77
|
+
const _a = request.assets, { imageFilePath, videoFilePath, faceMappings } = _a, restAssets = __rest(_a, ["imageFilePath", "videoFilePath", "faceMappings"]);
|
|
78
|
+
// Upload main files
|
|
79
|
+
if (imageFilePath) {
|
|
80
|
+
(0, logger_1.getLogger)().debug(`Uploading file ${imageFilePath} to Magic Hour's storage`);
|
|
81
|
+
}
|
|
82
|
+
if (videoFilePath) {
|
|
83
|
+
(0, logger_1.getLogger)().debug(`Uploading file ${videoFilePath} to Magic Hour's storage`);
|
|
84
|
+
}
|
|
85
|
+
const [uploadedImageFilePath, uploadedVideoFilePath] = yield Promise.all([
|
|
86
|
+
imageFilePath
|
|
87
|
+
? fileClient.uploadFile(imageFilePath)
|
|
88
|
+
: Promise.resolve(imageFilePath),
|
|
89
|
+
videoFilePath
|
|
90
|
+
? fileClient.uploadFile(videoFilePath)
|
|
91
|
+
: Promise.resolve(videoFilePath),
|
|
92
|
+
]);
|
|
93
|
+
if (imageFilePath) {
|
|
94
|
+
(0, logger_1.getLogger)().info(`Uploaded file ${imageFilePath} to Magic Hour's storage as ${uploadedImageFilePath}`);
|
|
95
|
+
}
|
|
96
|
+
if (videoFilePath) {
|
|
97
|
+
(0, logger_1.getLogger)().info(`Uploaded file ${videoFilePath} to Magic Hour's storage as ${uploadedVideoFilePath}`);
|
|
98
|
+
}
|
|
99
|
+
// Upload faceMappings newFace files if they exist
|
|
100
|
+
let updatedFaceMappings = faceMappings;
|
|
101
|
+
if (faceMappings && faceMappings.length > 0) {
|
|
102
|
+
(0, logger_1.getLogger)().debug(`Uploading ${faceMappings.length} newFace files for face mappings`);
|
|
103
|
+
const uploadPromises = faceMappings.map((mapping, index) => __awaiter(this, void 0, void 0, function* () {
|
|
104
|
+
const { newFace, originalFace } = mapping;
|
|
105
|
+
// Check if newFace needs to be uploaded (not already uploaded and not a URL)
|
|
106
|
+
if (newFace &&
|
|
107
|
+
!newFace.startsWith("api-assets/") &&
|
|
108
|
+
!newFace.startsWith("http")) {
|
|
109
|
+
(0, logger_1.getLogger)().debug(`Uploading newFace file ${newFace} for face mapping ${index}`);
|
|
110
|
+
const uploadedNewFace = yield fileClient.uploadFile(newFace);
|
|
111
|
+
(0, logger_1.getLogger)().info(`Uploaded newFace file ${newFace} as ${uploadedNewFace} for face mapping ${index}`);
|
|
112
|
+
return {
|
|
113
|
+
newFace: uploadedNewFace,
|
|
114
|
+
originalFace,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
return {
|
|
119
|
+
newFace,
|
|
120
|
+
originalFace,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}));
|
|
124
|
+
updatedFaceMappings = yield Promise.all(uploadPromises);
|
|
125
|
+
}
|
|
126
|
+
const createResponse = yield this.create(Object.assign(Object.assign({}, request), { assets: Object.assign(Object.assign(Object.assign({}, restAssets), { imageFilePath: imageFilePath ? uploadedImageFilePath : imageFilePath, videoFilePath: videoFilePath ? uploadedVideoFilePath : videoFilePath }), (updatedFaceMappings && { faceMappings: updatedFaceMappings })) }), createOpts);
|
|
127
|
+
(0, logger_1.getLogger)().info(`Created FaceSwapClient project ${createResponse.id}`);
|
|
128
|
+
const projectsClient = new video_projects_1.VideoProjectsClient(this._client, this._opts);
|
|
129
|
+
(0, logger_1.getLogger)().debug(`Checking result for FaceSwapClient project ${createResponse.id}`);
|
|
130
|
+
const result = yield projectsClient.checkResult({ id: createResponse.id }, Object.assign({ waitForCompletion,
|
|
131
|
+
downloadOutputs,
|
|
132
|
+
downloadDirectory }, createOpts));
|
|
133
|
+
return result;
|
|
134
|
+
});
|
|
135
|
+
}
|
|
11
136
|
/**
|
|
12
137
|
* Face Swap video
|
|
13
138
|
*
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { External$V1FaceSwapPhotoCreateBodyAssets, V1FaceSwapPhotoCreateBodyAssets } from "../../../types/v1-face-swap-photo-create-body-assets";
|
|
2
1
|
import * as z from "zod";
|
|
2
|
+
import { External$V1FaceSwapPhotoCreateBodyAssets, V1FaceSwapPhotoCreateBodyAssets } from "../../../types/v1-face-swap-photo-create-body-assets";
|
|
3
3
|
/**
|
|
4
4
|
* CreateRequest
|
|
5
5
|
*/
|
|
@@ -34,9 +34,9 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Schemas$CreateRequest = void 0;
|
|
37
|
+
const z = __importStar(require("zod"));
|
|
37
38
|
const core_1 = require("../../../core");
|
|
38
39
|
const v1_face_swap_photo_create_body_assets_1 = require("../../../types/v1-face-swap-photo-create-body-assets");
|
|
39
|
-
const z = __importStar(require("zod"));
|
|
40
40
|
/**
|
|
41
41
|
* Takes network data, validates it, and transforms keys to match typescript object CreateRequest
|
|
42
42
|
*/
|
|
@@ -1,8 +1,80 @@
|
|
|
1
1
|
import { types } from "../../../index.js";
|
|
2
2
|
import { ApiPromise, CoreClient, CoreResourceClient, RequestOptions, ResourceClientOptions } from "../../../core";
|
|
3
|
+
import { GenerateOptions, GenerateRequestType } from "../../../helpers/generate-type";
|
|
3
4
|
import * as requests from "../../../resources/v1/face-swap-photo/request-types";
|
|
5
|
+
type GenerateRequest = GenerateRequestType<requests.CreateRequest, {
|
|
6
|
+
/**
|
|
7
|
+
* Array of face mappings for individual face swaps. Each newFace will be uploaded if it's a local file path.
|
|
8
|
+
*/
|
|
9
|
+
faceMappings?: {
|
|
10
|
+
/**
|
|
11
|
+
* The face image that will be used to replace the face in the original_face. This value is either
|
|
12
|
+
* - a direct URL to the image file
|
|
13
|
+
* - a path to a local file
|
|
14
|
+
*
|
|
15
|
+
* 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.
|
|
16
|
+
*/
|
|
17
|
+
newFace: string;
|
|
18
|
+
/**
|
|
19
|
+
* The face detected from the target image. This should correspond to the response from the face detection API.
|
|
20
|
+
*/
|
|
21
|
+
originalFace: string;
|
|
22
|
+
}[] | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* This is the image from which the face is extracted. This value is either
|
|
25
|
+
* - a direct URL to the image file
|
|
26
|
+
* - a path to a local file
|
|
27
|
+
*
|
|
28
|
+
* 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.
|
|
29
|
+
*/
|
|
30
|
+
sourceFilePath?: string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* This is the image where the face from the source image will be placed. This value is either
|
|
33
|
+
* - a direct URL to the image file
|
|
34
|
+
* - a path to a local file
|
|
35
|
+
*
|
|
36
|
+
* 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.
|
|
37
|
+
*/
|
|
38
|
+
targetFilePath: string;
|
|
39
|
+
}>;
|
|
4
40
|
export declare class FaceSwapPhotoClient extends CoreResourceClient {
|
|
5
41
|
constructor(coreClient: CoreClient, opts: ResourceClientOptions);
|
|
42
|
+
/**
|
|
43
|
+
* Face Swap Photo
|
|
44
|
+
*
|
|
45
|
+
* Create a face swap photo
|
|
46
|
+
*
|
|
47
|
+
* This method provides a convenient way to create a request and automatically wait for completion and download outputs.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* import Client from "../../../index.js";
|
|
52
|
+
*
|
|
53
|
+
* const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
54
|
+
* const res = await client.v1.faceSwapPhoto.generate(
|
|
55
|
+
* {
|
|
56
|
+
* assets: {
|
|
57
|
+
* faceMappings: [
|
|
58
|
+
* {
|
|
59
|
+
* newFace: "api-assets/id/1234.png",
|
|
60
|
+
* originalFace: "api-assets/id/0-0.png",
|
|
61
|
+
* },
|
|
62
|
+
* ],
|
|
63
|
+
* faceSwapMode: "all-faces",
|
|
64
|
+
* sourceFilePath: "/path/to/1234.png",
|
|
65
|
+
* targetFilePath: "/path/to/1234.png",
|
|
66
|
+
* },
|
|
67
|
+
* name: "Face Swap image",
|
|
68
|
+
* },
|
|
69
|
+
* {
|
|
70
|
+
* waitForCompletion: true,
|
|
71
|
+
* downloadOutputs: true,
|
|
72
|
+
* downloadDirectory: "outputs",
|
|
73
|
+
* },
|
|
74
|
+
* );
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
generate(request: GenerateRequest, opts?: GenerateOptions): Promise<import("../image-projects/resource-client").V1ImageProjectsGetResponseWithDownloads>;
|
|
6
78
|
/**
|
|
7
79
|
* Face Swap Photo
|
|
8
80
|
*
|
|
@@ -12,3 +84,4 @@ export declare class FaceSwapPhotoClient extends CoreResourceClient {
|
|
|
12
84
|
*/
|
|
13
85
|
create(request: requests.CreateRequest, opts?: RequestOptions): ApiPromise<types.V1FaceSwapPhotoCreateResponse>;
|
|
14
86
|
}
|
|
87
|
+
export {};
|
|
@@ -1,13 +1,130 @@
|
|
|
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.FaceSwapPhotoClient = void 0;
|
|
4
24
|
const core_1 = require("../../../core");
|
|
25
|
+
const files_1 = require("../../../resources/v1/files");
|
|
5
26
|
const v1_face_swap_photo_create_body_1 = require("../../../types/v1-face-swap-photo-create-body");
|
|
6
27
|
const v1_face_swap_photo_create_response_1 = require("../../../types/v1-face-swap-photo-create-response");
|
|
28
|
+
const logger_1 = require("../../../logger");
|
|
29
|
+
const image_projects_1 = require("../../../resources/v1/image-projects");
|
|
7
30
|
class FaceSwapPhotoClient extends core_1.CoreResourceClient {
|
|
8
31
|
constructor(coreClient, opts) {
|
|
9
32
|
super(coreClient, opts);
|
|
10
33
|
}
|
|
34
|
+
/**
|
|
35
|
+
* Face Swap Photo
|
|
36
|
+
*
|
|
37
|
+
* Create a face swap photo
|
|
38
|
+
*
|
|
39
|
+
* This method provides a convenient way to create a request and automatically wait for completion and download outputs.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```typescript
|
|
43
|
+
* import Client from "../../../index.js";
|
|
44
|
+
*
|
|
45
|
+
* const client = new Client({ token: process.env["API_TOKEN"]!! });
|
|
46
|
+
* const res = await client.v1.faceSwapPhoto.generate(
|
|
47
|
+
* {
|
|
48
|
+
* assets: {
|
|
49
|
+
* faceMappings: [
|
|
50
|
+
* {
|
|
51
|
+
* newFace: "api-assets/id/1234.png",
|
|
52
|
+
* originalFace: "api-assets/id/0-0.png",
|
|
53
|
+
* },
|
|
54
|
+
* ],
|
|
55
|
+
* faceSwapMode: "all-faces",
|
|
56
|
+
* sourceFilePath: "/path/to/1234.png",
|
|
57
|
+
* targetFilePath: "/path/to/1234.png",
|
|
58
|
+
* },
|
|
59
|
+
* name: "Face Swap image",
|
|
60
|
+
* },
|
|
61
|
+
* {
|
|
62
|
+
* waitForCompletion: true,
|
|
63
|
+
* downloadOutputs: true,
|
|
64
|
+
* downloadDirectory: "outputs",
|
|
65
|
+
* },
|
|
66
|
+
* );
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
generate(request_1) {
|
|
70
|
+
return __awaiter(this, arguments, void 0, function* (request, opts = {}) {
|
|
71
|
+
const { waitForCompletion = true, downloadOutputs = true, downloadDirectory = undefined } = opts, createOpts = __rest(opts, ["waitForCompletion", "downloadOutputs", "downloadDirectory"]);
|
|
72
|
+
const fileClient = new files_1.FilesClient(this._client, this._opts);
|
|
73
|
+
const _a = request.assets, { sourceFilePath, targetFilePath, faceMappings } = _a, restAssets = __rest(_a, ["sourceFilePath", "targetFilePath", "faceMappings"]);
|
|
74
|
+
// Upload main files
|
|
75
|
+
if (sourceFilePath) {
|
|
76
|
+
(0, logger_1.getLogger)().debug(`Uploading file ${sourceFilePath} to Magic Hour's storage`);
|
|
77
|
+
}
|
|
78
|
+
(0, logger_1.getLogger)().debug(`Uploading file ${targetFilePath} to Magic Hour's storage`);
|
|
79
|
+
const [uploadedSourceFilePath, uploadedTargetFilePath] = yield Promise.all([
|
|
80
|
+
sourceFilePath
|
|
81
|
+
? fileClient.uploadFile(sourceFilePath)
|
|
82
|
+
: Promise.resolve(sourceFilePath),
|
|
83
|
+
fileClient.uploadFile(targetFilePath),
|
|
84
|
+
]);
|
|
85
|
+
if (sourceFilePath) {
|
|
86
|
+
(0, logger_1.getLogger)().info(`Uploaded file ${sourceFilePath} to Magic Hour's storage as ${uploadedSourceFilePath}`);
|
|
87
|
+
}
|
|
88
|
+
(0, logger_1.getLogger)().info(`Uploaded file ${targetFilePath} to Magic Hour's storage as ${uploadedTargetFilePath}`);
|
|
89
|
+
// Upload faceMappings newFace files if they exist
|
|
90
|
+
let updatedFaceMappings = faceMappings;
|
|
91
|
+
if (faceMappings && faceMappings.length > 0) {
|
|
92
|
+
(0, logger_1.getLogger)().debug(`Uploading ${faceMappings.length} newFace files for face mappings`);
|
|
93
|
+
const uploadPromises = faceMappings.map((mapping, index) => __awaiter(this, void 0, void 0, function* () {
|
|
94
|
+
const { newFace, originalFace } = mapping;
|
|
95
|
+
// Check if newFace needs to be uploaded (not already uploaded and not a URL)
|
|
96
|
+
if (newFace &&
|
|
97
|
+
!newFace.startsWith("api-assets/") &&
|
|
98
|
+
!newFace.startsWith("http")) {
|
|
99
|
+
(0, logger_1.getLogger)().debug(`Uploading newFace file ${newFace} for face mapping ${index}`);
|
|
100
|
+
const uploadedNewFace = yield fileClient.uploadFile(newFace);
|
|
101
|
+
(0, logger_1.getLogger)().info(`Uploaded newFace file ${newFace} as ${uploadedNewFace} for face mapping ${index}`);
|
|
102
|
+
return {
|
|
103
|
+
newFace: uploadedNewFace,
|
|
104
|
+
originalFace,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
else {
|
|
108
|
+
return {
|
|
109
|
+
newFace,
|
|
110
|
+
originalFace,
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
}));
|
|
114
|
+
updatedFaceMappings = yield Promise.all(uploadPromises);
|
|
115
|
+
}
|
|
116
|
+
const createResponse = yield this.create(Object.assign(Object.assign({}, request), { assets: Object.assign(Object.assign(Object.assign({}, restAssets), { sourceFilePath: sourceFilePath
|
|
117
|
+
? uploadedSourceFilePath
|
|
118
|
+
: sourceFilePath, targetFilePath: uploadedTargetFilePath }), (updatedFaceMappings && { faceMappings: updatedFaceMappings })) }), createOpts);
|
|
119
|
+
(0, logger_1.getLogger)().info(`Created FaceSwapPhotoClient project ${createResponse.id}`);
|
|
120
|
+
const projectsClient = new image_projects_1.ImageProjectsClient(this._client, this._opts);
|
|
121
|
+
(0, logger_1.getLogger)().debug(`Checking result for FaceSwapPhotoClient project ${createResponse.id}`);
|
|
122
|
+
const result = yield projectsClient.checkResult({ id: createResponse.id }, Object.assign({ waitForCompletion,
|
|
123
|
+
downloadOutputs,
|
|
124
|
+
downloadDirectory }, createOpts));
|
|
125
|
+
return result;
|
|
126
|
+
});
|
|
127
|
+
}
|
|
11
128
|
/**
|
|
12
129
|
* Face Swap Photo
|
|
13
130
|
*
|
|
@@ -1,7 +1,47 @@
|
|
|
1
|
+
import { Readable } from "stream";
|
|
1
2
|
import { CoreClient, CoreResourceClient, ResourceClientOptions } from "../../../core";
|
|
2
3
|
import { UploadUrlsClient } from "../../../resources/v1/files/upload-urls";
|
|
4
|
+
export type FileInput = string | Buffer | Readable | File | NodeJS.ReadableStream;
|
|
3
5
|
export declare class FilesClient extends CoreResourceClient {
|
|
4
6
|
private _uploadUrlsLazy?;
|
|
5
7
|
constructor(coreClient: CoreClient, opts: ResourceClientOptions);
|
|
6
8
|
get uploadUrls(): UploadUrlsClient;
|
|
9
|
+
/**
|
|
10
|
+
* Upload a file to Magic Hour's storage.
|
|
11
|
+
*
|
|
12
|
+
* This method uploads a file to Magic Hour's secure cloud storage and returns
|
|
13
|
+
* a file path that can be used as input for other Magic Hour API endpoints.
|
|
14
|
+
* The file type is automatically detected from the file extension.
|
|
15
|
+
*
|
|
16
|
+
* @param file - The file to upload. Can be:
|
|
17
|
+
* - **string**: Path to a local file (e.g., "/path/to/image.jpg")
|
|
18
|
+
* - **Buffer**: File content as buffer (requires extension detection via other means)
|
|
19
|
+
* - **Readable**: Node.js readable stream (must have a 'path' property)
|
|
20
|
+
* - **File**: File object (browser environment)
|
|
21
|
+
*
|
|
22
|
+
* @returns The uploaded file's path in Magic Hour's storage system.
|
|
23
|
+
* This path can be used as input for other API endpoints.
|
|
24
|
+
*
|
|
25
|
+
* @throws {Error} If the specified local file doesn't exist.
|
|
26
|
+
* @throws {Error} If the file type is not supported.
|
|
27
|
+
* @throws {Error} If the upload request fails (network/server errors).
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* import { Client } from "../../../index.js";
|
|
32
|
+
*
|
|
33
|
+
* const client = new Client({ token: process.env.MAGIC_HOUR_API_TOKEN });
|
|
34
|
+
*
|
|
35
|
+
* // Upload from file path
|
|
36
|
+
* const filePath = await client.v1.files.uploadFile("/path/to/your/image.jpg");
|
|
37
|
+
* console.log(`Uploaded file: ${filePath}`);
|
|
38
|
+
*
|
|
39
|
+
* // Use the uploaded file in other API calls
|
|
40
|
+
* const result = await client.v1.aiImageUpscaler.create({
|
|
41
|
+
* assets: { imageFilePath: filePath },
|
|
42
|
+
* style: { upscaleFactor: 2 }
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
uploadFile(file: FileInput): Promise<string>;
|
|
7
47
|
}
|
|
@@ -1,7 +1,131 @@
|
|
|
1
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 __asyncValues = (this && this.__asyncValues) || function (o) {
|
|
45
|
+
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
46
|
+
var m = o[Symbol.asyncIterator], i;
|
|
47
|
+
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
|
|
48
|
+
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
|
|
49
|
+
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
|
|
50
|
+
};
|
|
2
51
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
52
|
exports.FilesClient = void 0;
|
|
53
|
+
const fs = __importStar(require("fs"));
|
|
54
|
+
const path = __importStar(require("path"));
|
|
55
|
+
const stream_1 = require("stream");
|
|
4
56
|
const core_1 = require("../../../core");
|
|
57
|
+
/**
|
|
58
|
+
* Determine file type and extension from file path or name.
|
|
59
|
+
*/
|
|
60
|
+
function getFileTypeAndExtension(fileName) {
|
|
61
|
+
const ext = path.extname(fileName).toLowerCase().slice(1); // Remove the leading dot
|
|
62
|
+
// Video extensions
|
|
63
|
+
const videoExts = ["mp4", "m4v", "mov", "webm"];
|
|
64
|
+
// Audio extensions
|
|
65
|
+
const audioExts = ["mp3", "mpeg", "wav", "aac", "aiff", "flac"];
|
|
66
|
+
// Image extensions
|
|
67
|
+
const imageExts = [
|
|
68
|
+
"png",
|
|
69
|
+
"jpg",
|
|
70
|
+
"jpeg",
|
|
71
|
+
"webp",
|
|
72
|
+
"avif",
|
|
73
|
+
"jp2",
|
|
74
|
+
"tiff",
|
|
75
|
+
"bmp",
|
|
76
|
+
];
|
|
77
|
+
let fileType;
|
|
78
|
+
if (videoExts.includes(ext)) {
|
|
79
|
+
fileType = "video";
|
|
80
|
+
}
|
|
81
|
+
else if (audioExts.includes(ext)) {
|
|
82
|
+
fileType = "audio";
|
|
83
|
+
}
|
|
84
|
+
else if (imageExts.includes(ext)) {
|
|
85
|
+
fileType = "image";
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
throw new Error(`Unsupported file extension: ${ext}. ` +
|
|
89
|
+
"Supported types: video (mp4, m4v, mov, webm), " +
|
|
90
|
+
"audio (mp3, mpeg, wav, aac, aiff, flac), " +
|
|
91
|
+
"image (png, jpg, jpeg, webp, avif, jp2, tiff, bmp)");
|
|
92
|
+
}
|
|
93
|
+
return { fileType, extension: ext };
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Process different file input types and return standardized information.
|
|
97
|
+
*/
|
|
98
|
+
function processFileInput(file) {
|
|
99
|
+
if (typeof file === "string") {
|
|
100
|
+
// File path
|
|
101
|
+
if (!fs.existsSync(file)) {
|
|
102
|
+
throw new Error(`File not found: ${file}`);
|
|
103
|
+
}
|
|
104
|
+
const { fileType, extension } = getFileTypeAndExtension(file);
|
|
105
|
+
return { filePath: file, fileType, extension };
|
|
106
|
+
}
|
|
107
|
+
else if (Buffer.isBuffer(file)) {
|
|
108
|
+
throw new Error("Buffer input requires a file name for extension detection. " +
|
|
109
|
+
"Please use a file path, File object, or stream with a name property.");
|
|
110
|
+
}
|
|
111
|
+
else if (file instanceof stream_1.Readable) {
|
|
112
|
+
// Stream with path property
|
|
113
|
+
const filePath = file.path;
|
|
114
|
+
if (typeof filePath !== "string") {
|
|
115
|
+
throw new Error("Stream must have a 'path' property for extension detection.");
|
|
116
|
+
}
|
|
117
|
+
const { fileType, extension } = getFileTypeAndExtension(filePath);
|
|
118
|
+
return { fileData: file, fileType, extension };
|
|
119
|
+
}
|
|
120
|
+
else if (typeof File !== "undefined" && file instanceof File) {
|
|
121
|
+
// File object (browser)
|
|
122
|
+
const { fileType, extension } = getFileTypeAndExtension(file.name);
|
|
123
|
+
return { fileData: file, fileType, extension };
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
throw new Error("Unsupported file input type");
|
|
127
|
+
}
|
|
128
|
+
}
|
|
5
129
|
class FilesClient extends core_1.CoreResourceClient {
|
|
6
130
|
constructor(coreClient, opts) {
|
|
7
131
|
super(coreClient, opts);
|
|
@@ -13,5 +137,117 @@ class FilesClient extends core_1.CoreResourceClient {
|
|
|
13
137
|
var _a;
|
|
14
138
|
return ((_a = this._uploadUrlsLazy) !== null && _a !== void 0 ? _a : (this._uploadUrlsLazy = new (require("./upload-urls").UploadUrlsClient)(this._client, this._opts)));
|
|
15
139
|
}
|
|
140
|
+
/**
|
|
141
|
+
* Upload a file to Magic Hour's storage.
|
|
142
|
+
*
|
|
143
|
+
* This method uploads a file to Magic Hour's secure cloud storage and returns
|
|
144
|
+
* a file path that can be used as input for other Magic Hour API endpoints.
|
|
145
|
+
* The file type is automatically detected from the file extension.
|
|
146
|
+
*
|
|
147
|
+
* @param file - The file to upload. Can be:
|
|
148
|
+
* - **string**: Path to a local file (e.g., "/path/to/image.jpg")
|
|
149
|
+
* - **Buffer**: File content as buffer (requires extension detection via other means)
|
|
150
|
+
* - **Readable**: Node.js readable stream (must have a 'path' property)
|
|
151
|
+
* - **File**: File object (browser environment)
|
|
152
|
+
*
|
|
153
|
+
* @returns The uploaded file's path in Magic Hour's storage system.
|
|
154
|
+
* This path can be used as input for other API endpoints.
|
|
155
|
+
*
|
|
156
|
+
* @throws {Error} If the specified local file doesn't exist.
|
|
157
|
+
* @throws {Error} If the file type is not supported.
|
|
158
|
+
* @throws {Error} If the upload request fails (network/server errors).
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* import { Client } from "../../../index.js";
|
|
163
|
+
*
|
|
164
|
+
* const client = new Client({ token: process.env.MAGIC_HOUR_API_TOKEN });
|
|
165
|
+
*
|
|
166
|
+
* // Upload from file path
|
|
167
|
+
* const filePath = await client.v1.files.uploadFile("/path/to/your/image.jpg");
|
|
168
|
+
* console.log(`Uploaded file: ${filePath}`);
|
|
169
|
+
*
|
|
170
|
+
* // Use the uploaded file in other API calls
|
|
171
|
+
* const result = await client.v1.aiImageUpscaler.create({
|
|
172
|
+
* assets: { imageFilePath: filePath },
|
|
173
|
+
* style: { upscaleFactor: 2 }
|
|
174
|
+
* });
|
|
175
|
+
* ```
|
|
176
|
+
*/
|
|
177
|
+
uploadFile(file) {
|
|
178
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
179
|
+
var _a, e_1, _b, _c;
|
|
180
|
+
const { filePath, fileData, fileType, extension } = processFileInput(file);
|
|
181
|
+
// Create upload URL
|
|
182
|
+
const response = yield this.uploadUrls.create({
|
|
183
|
+
items: [
|
|
184
|
+
{
|
|
185
|
+
extension,
|
|
186
|
+
type: fileType,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
});
|
|
190
|
+
if (!response.items || response.items.length === 0) {
|
|
191
|
+
throw new Error("No upload URL was returned from the server");
|
|
192
|
+
}
|
|
193
|
+
const uploadInfo = response.items[0];
|
|
194
|
+
if (!uploadInfo) {
|
|
195
|
+
throw new Error("Upload info is missing from server response");
|
|
196
|
+
}
|
|
197
|
+
// Prepare file content
|
|
198
|
+
let content;
|
|
199
|
+
if (filePath) {
|
|
200
|
+
content = fs.readFileSync(filePath);
|
|
201
|
+
}
|
|
202
|
+
else if (fileData) {
|
|
203
|
+
if (Buffer.isBuffer(fileData)) {
|
|
204
|
+
content = fileData;
|
|
205
|
+
}
|
|
206
|
+
else if (fileData instanceof stream_1.Readable) {
|
|
207
|
+
// For streams, read all data into buffer
|
|
208
|
+
const chunks = [];
|
|
209
|
+
try {
|
|
210
|
+
for (var _d = true, fileData_1 = __asyncValues(fileData), fileData_1_1; fileData_1_1 = yield fileData_1.next(), _a = fileData_1_1.done, !_a; _d = true) {
|
|
211
|
+
_c = fileData_1_1.value;
|
|
212
|
+
_d = false;
|
|
213
|
+
const chunk = _c;
|
|
214
|
+
chunks.push(chunk);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
218
|
+
finally {
|
|
219
|
+
try {
|
|
220
|
+
if (!_d && !_a && (_b = fileData_1.return)) yield _b.call(fileData_1);
|
|
221
|
+
}
|
|
222
|
+
finally { if (e_1) throw e_1.error; }
|
|
223
|
+
}
|
|
224
|
+
content = Buffer.concat(chunks);
|
|
225
|
+
}
|
|
226
|
+
else if (typeof File !== "undefined" && fileData instanceof File) {
|
|
227
|
+
// File object - convert to buffer
|
|
228
|
+
const arrayBuffer = yield fileData.arrayBuffer();
|
|
229
|
+
content = Buffer.from(arrayBuffer);
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
throw new Error("Unsupported file data type");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
236
|
+
throw new Error("No file data available");
|
|
237
|
+
}
|
|
238
|
+
// Upload the file
|
|
239
|
+
const fetcherFn = core_1.RUNTIME.type === "node" || typeof fetch !== "function"
|
|
240
|
+
? require("node-fetch").default
|
|
241
|
+
: fetch;
|
|
242
|
+
const uploadResponse = yield fetcherFn(uploadInfo.uploadUrl, {
|
|
243
|
+
method: "PUT",
|
|
244
|
+
body: content,
|
|
245
|
+
});
|
|
246
|
+
if (!uploadResponse.ok) {
|
|
247
|
+
throw new Error(`Upload failed with status ${uploadResponse.status}: ${uploadResponse.statusText}`);
|
|
248
|
+
}
|
|
249
|
+
return uploadInfo.filePath;
|
|
250
|
+
});
|
|
251
|
+
}
|
|
16
252
|
}
|
|
17
253
|
exports.FilesClient = FilesClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|