vidspotai-shared 1.0.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/lib/globals/aiModels.d.ts +60 -0
- package/lib/globals/aiModels.d.ts.map +1 -0
- package/lib/globals/aiModels.js +463 -0
- package/lib/globals/config.d.ts +4 -0
- package/lib/globals/config.d.ts.map +1 -0
- package/lib/globals/config.js +20 -0
- package/lib/globals/index.d.ts +6 -0
- package/lib/globals/index.d.ts.map +1 -0
- package/lib/globals/index.js +21 -0
- package/lib/globals/plans.d.ts +3 -0
- package/lib/globals/plans.d.ts.map +1 -0
- package/lib/globals/plans.js +60 -0
- package/lib/globals/schemas.d.ts +3 -0
- package/lib/globals/schemas.d.ts.map +1 -0
- package/lib/globals/schemas.js +18 -0
- package/lib/globals/types.d.ts +90 -0
- package/lib/globals/types.d.ts.map +1 -0
- package/lib/globals/types.js +93 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +21 -0
- package/lib/libs/firebase.d.ts +7 -0
- package/lib/libs/firebase.d.ts.map +1 -0
- package/lib/libs/firebase.js +60 -0
- package/lib/libs/index.d.ts +2 -0
- package/lib/libs/index.d.ts.map +1 -0
- package/lib/libs/index.js +17 -0
- package/lib/models/index.d.ts +4 -0
- package/lib/models/index.d.ts.map +1 -0
- package/lib/models/index.js +19 -0
- package/lib/models/script.model.d.ts +39 -0
- package/lib/models/script.model.d.ts.map +1 -0
- package/lib/models/script.model.js +26 -0
- package/lib/models/user.model.d.ts +46 -0
- package/lib/models/user.model.d.ts.map +1 -0
- package/lib/models/user.model.js +2 -0
- package/lib/models/video.model.d.ts +43 -0
- package/lib/models/video.model.d.ts.map +1 -0
- package/lib/models/video.model.js +2 -0
- package/lib/services/aiGen/aiGenFactory.service.d.ts +8 -0
- package/lib/services/aiGen/aiGenFactory.service.d.ts.map +1 -0
- package/lib/services/aiGen/aiGenFactory.service.js +56 -0
- package/lib/services/aiGen/atypes.d.ts +5 -0
- package/lib/services/aiGen/atypes.d.ts.map +1 -0
- package/lib/services/aiGen/atypes.js +8 -0
- package/lib/services/aiGen/helpers.d.ts +3 -0
- package/lib/services/aiGen/helpers.d.ts.map +1 -0
- package/lib/services/aiGen/helpers.js +76 -0
- package/lib/services/aiGen/index.d.ts +5 -0
- package/lib/services/aiGen/index.d.ts.map +1 -0
- package/lib/services/aiGen/index.js +20 -0
- package/lib/services/aiGen/providers/alibaba/alibaba.d.ts +12 -0
- package/lib/services/aiGen/providers/alibaba/alibaba.d.ts.map +1 -0
- package/lib/services/aiGen/providers/alibaba/alibaba.js +146 -0
- package/lib/services/aiGen/providers/alibaba/helpers.d.ts +3 -0
- package/lib/services/aiGen/providers/alibaba/helpers.d.ts.map +1 -0
- package/lib/services/aiGen/providers/alibaba/helpers.js +31 -0
- package/lib/services/aiGen/providers/azure/azure.d.ts +1 -0
- package/lib/services/aiGen/providers/azure/azure.d.ts.map +1 -0
- package/lib/services/aiGen/providers/azure/azure.js +1 -0
- package/lib/services/aiGen/providers/azure/azure.service.d.ts +14 -0
- package/lib/services/aiGen/providers/azure/azure.service.d.ts.map +1 -0
- package/lib/services/aiGen/providers/azure/azure.service.js +125 -0
- package/lib/services/aiGen/providers/azure/index.d.ts +2 -0
- package/lib/services/aiGen/providers/azure/index.d.ts.map +1 -0
- package/lib/services/aiGen/providers/azure/index.js +17 -0
- package/lib/services/aiGen/providers/baseAiGenProvider.service.d.ts +8 -0
- package/lib/services/aiGen/providers/baseAiGenProvider.service.d.ts.map +1 -0
- package/lib/services/aiGen/providers/baseAiGenProvider.service.js +12 -0
- package/lib/services/aiGen/providers/google/google.service.d.ts +10 -0
- package/lib/services/aiGen/providers/google/google.service.d.ts.map +1 -0
- package/lib/services/aiGen/providers/google/google.service.js +96 -0
- package/lib/services/aiGen/providers/google/index.d.ts +2 -0
- package/lib/services/aiGen/providers/google/index.d.ts.map +1 -0
- package/lib/services/aiGen/providers/google/index.js +17 -0
- package/lib/services/aiGen/providers/index.d.ts +8 -0
- package/lib/services/aiGen/providers/index.d.ts.map +1 -0
- package/lib/services/aiGen/providers/index.js +23 -0
- package/lib/services/aiGen/providers/kling/btypes.d.ts +73 -0
- package/lib/services/aiGen/providers/kling/btypes.d.ts.map +1 -0
- package/lib/services/aiGen/providers/kling/btypes.js +2 -0
- package/lib/services/aiGen/providers/kling/index.d.ts +3 -0
- package/lib/services/aiGen/providers/kling/index.d.ts.map +1 -0
- package/lib/services/aiGen/providers/kling/index.js +18 -0
- package/lib/services/aiGen/providers/kling/kling.service.d.ts +13 -0
- package/lib/services/aiGen/providers/kling/kling.service.d.ts.map +1 -0
- package/lib/services/aiGen/providers/kling/kling.service.js +139 -0
- package/lib/services/aiGen/providers/kling/types.d.ts +73 -0
- package/lib/services/aiGen/providers/kling/types.d.ts.map +1 -0
- package/lib/services/aiGen/providers/kling/types.js +2 -0
- package/lib/services/aiGen/providers/minimax/ctypes.d.ts +26 -0
- package/lib/services/aiGen/providers/minimax/ctypes.d.ts.map +1 -0
- package/lib/services/aiGen/providers/minimax/ctypes.js +3 -0
- package/lib/services/aiGen/providers/minimax/index.d.ts +3 -0
- package/lib/services/aiGen/providers/minimax/index.d.ts.map +1 -0
- package/lib/services/aiGen/providers/minimax/index.js +18 -0
- package/lib/services/aiGen/providers/minimax/minimax.service.d.ts +12 -0
- package/lib/services/aiGen/providers/minimax/minimax.service.d.ts.map +1 -0
- package/lib/services/aiGen/providers/minimax/minimax.service.js +115 -0
- package/lib/services/aiGen/providers/minimax/types.d.ts +26 -0
- package/lib/services/aiGen/providers/minimax/types.d.ts.map +1 -0
- package/lib/services/aiGen/providers/minimax/types.js +3 -0
- package/lib/services/aiGen/providers/openai/index.d.ts +2 -0
- package/lib/services/aiGen/providers/openai/index.d.ts.map +1 -0
- package/lib/services/aiGen/providers/openai/index.js +17 -0
- package/lib/services/aiGen/providers/openai/openai.service.d.ts +12 -0
- package/lib/services/aiGen/providers/openai/openai.service.d.ts.map +1 -0
- package/lib/services/aiGen/providers/openai/openai.service.js +97 -0
- package/lib/services/aiGen/providers/runway/dtypes.d.ts +14 -0
- package/lib/services/aiGen/providers/runway/dtypes.d.ts.map +1 -0
- package/lib/services/aiGen/providers/runway/dtypes.js +27 -0
- package/lib/services/aiGen/providers/runway/index.d.ts +3 -0
- package/lib/services/aiGen/providers/runway/index.d.ts.map +1 -0
- package/lib/services/aiGen/providers/runway/index.js +18 -0
- package/lib/services/aiGen/providers/runway/runway.service.d.ts +12 -0
- package/lib/services/aiGen/providers/runway/runway.service.d.ts.map +1 -0
- package/lib/services/aiGen/providers/runway/runway.service.js +122 -0
- package/lib/services/aiGen/providers/runway/types.d.ts +14 -0
- package/lib/services/aiGen/providers/runway/types.d.ts.map +1 -0
- package/lib/services/aiGen/providers/runway/types.js +27 -0
- package/lib/services/aiGen/providers/types.d.ts +49 -0
- package/lib/services/aiGen/providers/types.d.ts.map +1 -0
- package/lib/services/aiGen/providers/types.js +2 -0
- package/lib/services/aiGen/types.d.ts +5 -0
- package/lib/services/aiGen/types.d.ts.map +1 -0
- package/lib/services/aiGen/types.js +8 -0
- package/lib/services/firestore.service.d.ts +66 -0
- package/lib/services/firestore.service.d.ts.map +1 -0
- package/lib/services/firestore.service.js +118 -0
- package/lib/services/index.d.ts +4 -0
- package/lib/services/index.d.ts.map +1 -0
- package/lib/services/index.js +19 -0
- package/lib/services/redis.service.d.ts +19 -0
- package/lib/services/redis.service.d.ts.map +1 -0
- package/lib/services/redis.service.js +97 -0
- package/lib/utils/helpers.d.ts +6 -0
- package/lib/utils/helpers.d.ts.map +1 -0
- package/lib/utils/helpers.js +55 -0
- package/lib/utils/index.d.ts +2 -0
- package/lib/utils/index.d.ts.map +1 -0
- package/lib/utils/index.js +17 -0
- package/package.json +31 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../src/services/aiGen/helpers.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAE1D,wBAAgB,cAAc,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAgHrE"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateParams = validateParams;
|
|
4
|
+
const aiModels_1 = require("../../globals/aiModels");
|
|
5
|
+
function validateParams(params) {
|
|
6
|
+
const modelConfig = aiModels_1.aiModelConfigs[params.modelKey];
|
|
7
|
+
if (!modelConfig) {
|
|
8
|
+
throw new Error(`Unsupported model: ${params.modelKey}`);
|
|
9
|
+
}
|
|
10
|
+
const errors = [];
|
|
11
|
+
// 1. Field-level validation (required + allowedValues)
|
|
12
|
+
for (const [field, rules] of Object.entries(modelConfig.fields)) {
|
|
13
|
+
const value = params[field];
|
|
14
|
+
if (rules.required && (value === null || value === undefined)) {
|
|
15
|
+
errors.push(`Missing required field: ${field}`);
|
|
16
|
+
}
|
|
17
|
+
if (value != null &&
|
|
18
|
+
rules.allowedValues &&
|
|
19
|
+
((typeof value === "string" &&
|
|
20
|
+
rules.allowedValues.includes(value)) ||
|
|
21
|
+
(typeof value === "number" &&
|
|
22
|
+
rules.allowedValues.includes(value))) === false) {
|
|
23
|
+
errors.push(`Invalid value for ${field}: "${value}". Allowed: ${rules.allowedValues.join(", ")}`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// 2. Type-specific required fields
|
|
27
|
+
if (modelConfig.type.includes("image-to-video") && !params.inputImageUrl) {
|
|
28
|
+
errors.push(`Model ${params.modelKey} requires imageUrl for image-to-video mode`);
|
|
29
|
+
}
|
|
30
|
+
if (modelConfig.type.includes("video-to-video") && !params.inputVideoUrl) {
|
|
31
|
+
errors.push(`Model ${params.modelKey} requires videoUrl for video-to-video mode`);
|
|
32
|
+
}
|
|
33
|
+
if (modelConfig.type.includes("text-to-video") && !params.prompt) {
|
|
34
|
+
errors.push(`Model ${params.modelKey} requires prompt for text-to-video mode`);
|
|
35
|
+
}
|
|
36
|
+
// 3. Cross-field validation: resolution ↔ aspectRatio
|
|
37
|
+
if (modelConfig.resolutionRules) {
|
|
38
|
+
const ratio = params.aspectRatio;
|
|
39
|
+
const resolution = params.resolution;
|
|
40
|
+
if (!resolution) {
|
|
41
|
+
errors.push(`Missing resolution for model ${params.modelKey}`);
|
|
42
|
+
}
|
|
43
|
+
else if (!Object.keys(modelConfig.resolutionRules).includes(resolution)) {
|
|
44
|
+
errors.push(`Invalid resolution "${resolution}" for ${params.modelKey}. Allowed: ${Object.keys(modelConfig.resolutionRules).join(", ")}`);
|
|
45
|
+
}
|
|
46
|
+
else if (ratio) {
|
|
47
|
+
const allowedRatios = modelConfig.resolutionRules[resolution];
|
|
48
|
+
if (allowedRatios && !allowedRatios.includes(ratio)) {
|
|
49
|
+
errors.push(`Invalid aspectRatio "${ratio}" for resolution "${resolution}" in ${params.modelKey}. Allowed: ${allowedRatios.join(", ")}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
// 3b. Cross-field validation: duration ↔ resolution
|
|
54
|
+
if (modelConfig.durationRules) {
|
|
55
|
+
const duration = params.duration;
|
|
56
|
+
const resolution = params.resolution;
|
|
57
|
+
if (!duration) {
|
|
58
|
+
errors.push(`Missing duration for model ${params.modelKey}`);
|
|
59
|
+
}
|
|
60
|
+
else if (!Object.keys(modelConfig.durationRules).includes(String(duration))) {
|
|
61
|
+
errors.push(`Invalid duration "${duration}" for ${params.modelKey}. Allowed: ${Object.keys(modelConfig.durationRules).join(", ")}`);
|
|
62
|
+
}
|
|
63
|
+
else if (resolution) {
|
|
64
|
+
const allowedResForDuration = modelConfig.durationRules[duration];
|
|
65
|
+
if (allowedResForDuration &&
|
|
66
|
+
!allowedResForDuration.includes(resolution)) {
|
|
67
|
+
errors.push(`Invalid resolution "${resolution}" for duration "${duration}" in ${params.modelKey}. Allowed: ${allowedResForDuration.join(", ")}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
// 4. Fail fast if validation fails
|
|
72
|
+
if (errors.length) {
|
|
73
|
+
throw new Error(`Validation failed: ${errors.join("; ")}`);
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/services/aiGen/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,SAAS,CAAC;AACxB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./aiGenFactory.service"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
19
|
+
__exportStar(require("./helpers"), exports);
|
|
20
|
+
__exportStar(require("./providers"), exports);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { BaseAiGenProviderService } from "../baseAiGenProvider.service";
|
|
2
|
+
import { CreditUsageParams, VideoGenerationParams, VideoGenerationResult, VideoStatusParams, VideoStatusResult } from "../types";
|
|
3
|
+
export declare class AlibabaService extends BaseAiGenProviderService {
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
private readonly timeout;
|
|
6
|
+
constructor();
|
|
7
|
+
private request;
|
|
8
|
+
generateVideo(params: VideoGenerationParams): Promise<VideoGenerationResult>;
|
|
9
|
+
checkVideoStatus({ task, outputFilename, outputFilePath, }: VideoStatusParams): Promise<VideoStatusResult | null>;
|
|
10
|
+
getCreditUsed({ modelKey, resolution, aspectRatio, duration, }: CreditUsageParams): number;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=alibaba.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"alibaba.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/alibaba/alibaba.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAOlB,qBAAa,cAAe,SAAQ,wBAAwB;IAC1D,OAAO,CAAC,QAAQ,CAAC,OAAO,CACsE;IAC9F,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;;YASnB,OAAO;IAgCf,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAwC3B,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAuExD,aAAa,CAAC,EACZ,QAAQ,EACR,UAAU,EACV,WAAW,EACX,QAAQ,GACT,EAAE,iBAAiB,GAAG,MAAM;CAO9B"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AlibabaService = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const types_1 = require("../../../../globals/types");
|
|
9
|
+
const baseAiGenProvider_service_1 = require("../baseAiGenProvider.service");
|
|
10
|
+
const aiModels_1 = require("../../../../globals/aiModels");
|
|
11
|
+
const firebase_1 = require("../../../../libs/firebase");
|
|
12
|
+
const helpers_1 = require("./helpers");
|
|
13
|
+
const helpers_2 = require("../../helpers");
|
|
14
|
+
const utils_1 = require("../../../../utils");
|
|
15
|
+
class AlibabaService extends baseAiGenProvider_service_1.BaseAiGenProviderService {
|
|
16
|
+
constructor() {
|
|
17
|
+
super();
|
|
18
|
+
this.baseUrl = "https://dashscope-intl.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis";
|
|
19
|
+
this.timeout = 60000; // 60 seconds
|
|
20
|
+
if (!process.env.ALIBABA_API_KEY) {
|
|
21
|
+
throw new Error("Missing ALIBABA_API_KEY in environment variables");
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
async request(body, method = "POST", url = this.baseUrl) {
|
|
25
|
+
const config = {
|
|
26
|
+
method,
|
|
27
|
+
url,
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: `Bearer ${process.env.ALIBABA_API_KEY}`,
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
"X-DashScope-Async": "enable",
|
|
32
|
+
},
|
|
33
|
+
timeout: this.timeout,
|
|
34
|
+
data: method === "POST" ? body : undefined,
|
|
35
|
+
};
|
|
36
|
+
try {
|
|
37
|
+
const res = await axios_1.default.request(config);
|
|
38
|
+
return res.data;
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (err.response) {
|
|
42
|
+
console.error("Alibaba API error:", err.response.data);
|
|
43
|
+
}
|
|
44
|
+
else if (err.request) {
|
|
45
|
+
console.error("Alibaba API request error:", err.message);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
console.error("Unexpected error:", err.message);
|
|
49
|
+
}
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async generateVideo(params) {
|
|
54
|
+
(0, helpers_2.validateParams)(params);
|
|
55
|
+
const modelConfig = aiModels_1.aiModelConfigs[params.modelKey];
|
|
56
|
+
const modelId = modelConfig?.modelId;
|
|
57
|
+
if (!modelId)
|
|
58
|
+
throw new Error(`Unknown modelKey: ${params.modelKey}`);
|
|
59
|
+
const size = (0, helpers_1.getAlibabaDimensions)(params.resolution, params.aspectRatio);
|
|
60
|
+
if (!size) {
|
|
61
|
+
throw new Error(`Invalid resolution/aspect ratio combination: ${params.resolution} ${params.aspectRatio}`);
|
|
62
|
+
}
|
|
63
|
+
const body = {
|
|
64
|
+
model: modelId,
|
|
65
|
+
input: {
|
|
66
|
+
prompt: params.prompt,
|
|
67
|
+
},
|
|
68
|
+
parameters: {
|
|
69
|
+
size,
|
|
70
|
+
prompt_extend: true,
|
|
71
|
+
duration: params.duration || 5,
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
const result = await this.request(body);
|
|
75
|
+
if (!result || !result.request_id) {
|
|
76
|
+
return {
|
|
77
|
+
status: types_1.EVideoJobStatus.FAILED,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
task: result.request_id,
|
|
82
|
+
status: types_1.EVideoJobStatus.TRIGGERED,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
async checkVideoStatus({ task, outputFilename, outputFilePath = "videos", }) {
|
|
86
|
+
const statusUrl = `${this.baseUrl}/${task}`;
|
|
87
|
+
const result = await this.request(null, "GET", statusUrl);
|
|
88
|
+
if (!result) {
|
|
89
|
+
return {
|
|
90
|
+
status: types_1.EVideoJobStatus.FAILED,
|
|
91
|
+
errorMessage: "No response from Alibaba API",
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
const status = result.output?.task_status ?? result.status;
|
|
95
|
+
if (status === "SUCCEEDED" || status === "succeeded") {
|
|
96
|
+
const videoUrl = result.output?.results?.[0]?.url ||
|
|
97
|
+
result.output?.videos?.[0]?.url ||
|
|
98
|
+
result.output?.video_url;
|
|
99
|
+
if (!videoUrl) {
|
|
100
|
+
return {
|
|
101
|
+
status: types_1.EVideoJobStatus.FAILED,
|
|
102
|
+
errorMessage: "No video URL found in Alibaba response",
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
console.log("Alibaba video URL:", videoUrl);
|
|
106
|
+
const filePath = `${outputFilePath}/${outputFilename}.mp4`;
|
|
107
|
+
const file = (0, firebase_1.getBucket)().file(filePath);
|
|
108
|
+
try {
|
|
109
|
+
const videoResp = await axios_1.default.get(videoUrl, {
|
|
110
|
+
responseType: "arraybuffer",
|
|
111
|
+
timeout: this.timeout,
|
|
112
|
+
});
|
|
113
|
+
const buffer = Buffer.from(videoResp.data);
|
|
114
|
+
await file.save(buffer, { contentType: "video/mp4" });
|
|
115
|
+
const [signedUrl] = await file.getSignedUrl({
|
|
116
|
+
action: "read",
|
|
117
|
+
expires: "03-09-2491",
|
|
118
|
+
});
|
|
119
|
+
return {
|
|
120
|
+
videoUrl: signedUrl,
|
|
121
|
+
status: types_1.EVideoJobStatus.COMPLETED,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
catch (downloadErr) {
|
|
125
|
+
console.error("Error downloading or saving Alibaba video:", downloadErr);
|
|
126
|
+
return {
|
|
127
|
+
status: types_1.EVideoJobStatus.FAILED,
|
|
128
|
+
errorMessage: "Error downloading or saving video file",
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (status === "FAILED" || status === "failed") {
|
|
133
|
+
return {
|
|
134
|
+
status: types_1.EVideoJobStatus.FAILED,
|
|
135
|
+
errorMessage: result.output?.message || "Video generation failed",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
return { status: types_1.EVideoJobStatus.PENDING };
|
|
139
|
+
}
|
|
140
|
+
getCreditUsed({ modelKey, resolution, aspectRatio, duration, }) {
|
|
141
|
+
const modelConfig = aiModels_1.aiModelConfigs[modelKey];
|
|
142
|
+
const dimensions = (0, helpers_1.getAlibabaDimensions)(resolution, aspectRatio);
|
|
143
|
+
return (0, utils_1.getCreditsFromCost)(modelConfig.cost?.table?.[dimensions]?.[duration] || 0);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.AlibabaService = AlibabaService;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export declare const VideoModelsDimensionsMap: Record<"480p" | "720p" | "1080p", Record<"16:9" | "9:16" | "1:1" | "4:3" | "3:4", string>>;
|
|
2
|
+
export declare function getAlibabaDimensions(resolution: string, aspectRatio: string): string | null;
|
|
3
|
+
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/alibaba/helpers.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wBAAwB,EAAE,MAAM,CAC3C,MAAM,GAAG,MAAM,GAAG,OAAO,EACzB,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,KAAK,GAAG,KAAK,GAAG,KAAK,EAAE,MAAM,CAAC,CAuBxD,CAAC;AAEF,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,GAClB,MAAM,GAAG,IAAI,CAMf"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.VideoModelsDimensionsMap = void 0;
|
|
4
|
+
exports.getAlibabaDimensions = getAlibabaDimensions;
|
|
5
|
+
exports.VideoModelsDimensionsMap = {
|
|
6
|
+
"480p": {
|
|
7
|
+
"16:9": "832x480",
|
|
8
|
+
"9:16": "480x832",
|
|
9
|
+
"1:1": "624x624",
|
|
10
|
+
"4:3": "640x480",
|
|
11
|
+
"3:4": "480x640",
|
|
12
|
+
},
|
|
13
|
+
"720p": {
|
|
14
|
+
"16:9": "1280x720",
|
|
15
|
+
"9:16": "720x1280",
|
|
16
|
+
"1:1": "960x960",
|
|
17
|
+
"4:3": "1088x832",
|
|
18
|
+
"3:4": "832x1088",
|
|
19
|
+
},
|
|
20
|
+
"1080p": {
|
|
21
|
+
"16:9": "1920x1080",
|
|
22
|
+
"9:16": "1080x1920",
|
|
23
|
+
"1:1": "1440x1440",
|
|
24
|
+
"4:3": "1632x1248",
|
|
25
|
+
"3:4": "1248x1632",
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
function getAlibabaDimensions(resolution, aspectRatio) {
|
|
29
|
+
const size = exports.VideoModelsDimensionsMap[resolution]?.[aspectRatio];
|
|
30
|
+
return size || null;
|
|
31
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=azure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/azure/azure.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { BaseAiGenProviderService } from "../baseAiGenProvider.service";
|
|
2
|
+
import { CreditUsageParams, VideoGenerationParams, VideoGenerationResult, VideoStatusParams, VideoStatusResult } from "../types";
|
|
3
|
+
export declare class AzureService extends BaseAiGenProviderService {
|
|
4
|
+
private readonly baseUrl;
|
|
5
|
+
private readonly apiKey;
|
|
6
|
+
private readonly apiVersion;
|
|
7
|
+
private readonly timeout;
|
|
8
|
+
constructor();
|
|
9
|
+
private request;
|
|
10
|
+
generateVideo(params: VideoGenerationParams): Promise<VideoGenerationResult>;
|
|
11
|
+
checkVideoStatus({ task, outputFilename, outputFilePath, }: VideoStatusParams): Promise<VideoStatusResult | null>;
|
|
12
|
+
getCreditUsed({ modelKey, dimensions, duration, }: CreditUsageParams): number;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=azure.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"azure.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/azure/azure.service.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAElB,qBAAa,YAAa,SAAQ,wBAAwB;IACxD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;IACjC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAS;IAChC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAa;IACxC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAS;;YAYnB,OAAO;IAyCf,aAAa,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IA6B5E,gBAAgB,CAAC,EACrB,IAAI,EACJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAuDxD,aAAa,CAAC,EACZ,QAAQ,EACR,UAAsB,EACtB,QAAY,GACb,EAAE,iBAAiB,GAAG,MAAM;CAK9B"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AzureService = void 0;
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
8
|
+
const aiModels_1 = require("../../../../globals/aiModels");
|
|
9
|
+
const types_1 = require("../../../../globals/types");
|
|
10
|
+
const firebase_1 = require("../../../../libs/firebase");
|
|
11
|
+
const helpers_1 = require("../../../../utils/helpers");
|
|
12
|
+
const helpers_2 = require("../../helpers");
|
|
13
|
+
const baseAiGenProvider_service_1 = require("../baseAiGenProvider.service");
|
|
14
|
+
class AzureService extends baseAiGenProvider_service_1.BaseAiGenProviderService {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.apiVersion = "preview";
|
|
18
|
+
this.timeout = 60000; // 60 seconds
|
|
19
|
+
if (!process.env.AZURE_OPENAI_ENDPOINT || !process.env.AZURE_OPENAI_API_KEY) {
|
|
20
|
+
throw new Error("Missing AZURE_OPENAI_ENDPOINT or AZURE_OPENAI_API_KEY in environment variables");
|
|
21
|
+
}
|
|
22
|
+
this.baseUrl = process.env.AZURE_OPENAI_ENDPOINT;
|
|
23
|
+
this.apiKey = process.env.AZURE_OPENAI_API_KEY;
|
|
24
|
+
}
|
|
25
|
+
async request(endpoint, method, body) {
|
|
26
|
+
const url = `${this.baseUrl}${endpoint}${endpoint.includes("?") ? "&" : "?"}api-version=${this.apiVersion}`;
|
|
27
|
+
const config = {
|
|
28
|
+
method,
|
|
29
|
+
url,
|
|
30
|
+
headers: {
|
|
31
|
+
"api-key": this.apiKey,
|
|
32
|
+
"Content-Type": "application/json",
|
|
33
|
+
},
|
|
34
|
+
timeout: this.timeout,
|
|
35
|
+
data: body,
|
|
36
|
+
};
|
|
37
|
+
try {
|
|
38
|
+
const res = await axios_1.default.request(config);
|
|
39
|
+
return res.data;
|
|
40
|
+
}
|
|
41
|
+
catch (err) {
|
|
42
|
+
if (err.response) {
|
|
43
|
+
console.error("Azure OpenAI API error:", err.response.data);
|
|
44
|
+
throw new Error(`Azure API Error: ${err.response.status} ${err.response.statusText} - ${JSON.stringify(err.response.data)}`);
|
|
45
|
+
}
|
|
46
|
+
else if (err.request) {
|
|
47
|
+
console.error("Azure OpenAI API request error:", err.message);
|
|
48
|
+
throw new Error(`Azure API Request failed: ${err.message}`);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
console.error("Unexpected Azure API error:", err.message);
|
|
52
|
+
throw new Error(`Unexpected Azure API error: ${err.message}`);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async generateVideo(params) {
|
|
57
|
+
(0, helpers_2.validateParams)(params);
|
|
58
|
+
const modelId = aiModels_1.aiModelConfigs[params.modelKey]?.modelId || "sora";
|
|
59
|
+
const body = {
|
|
60
|
+
prompt: params.prompt,
|
|
61
|
+
width: params.dimensions?.split("x")[0]
|
|
62
|
+
? parseInt(params.dimensions.split("x")[0] ?? "480", 10)
|
|
63
|
+
: 480,
|
|
64
|
+
height: params.dimensions?.split("x")[1]
|
|
65
|
+
? parseInt(params.dimensions.split("x")[1] ?? "480", 10)
|
|
66
|
+
: 480,
|
|
67
|
+
n_seconds: params.duration || 5,
|
|
68
|
+
model: modelId,
|
|
69
|
+
};
|
|
70
|
+
const job = await this.request(`/openai/v1/video/generations/jobs?`, "POST", body);
|
|
71
|
+
return {
|
|
72
|
+
task: job.id,
|
|
73
|
+
status: job.status || types_1.EVideoJobStatus.PENDING,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
async checkVideoStatus({ task, outputFilename, outputFilePath = "videos", }) {
|
|
77
|
+
const result = await this.request(`/openai/v1/video/generations/jobs/${task}?`, "GET");
|
|
78
|
+
if (result.status === "succeeded") {
|
|
79
|
+
if (!result.generations || !(result.generations.length > 0)) {
|
|
80
|
+
return {
|
|
81
|
+
status: types_1.EVideoJobStatus.FAILED,
|
|
82
|
+
errorMessage: "No video returned from API",
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const generationId = result.generations[0].id;
|
|
86
|
+
const videoUrl = `${this.baseUrl}/openai/v1/video/generations/${generationId}/content/video?api-version=${this.apiVersion}`;
|
|
87
|
+
try {
|
|
88
|
+
const videoResp = await axios_1.default.get(videoUrl, {
|
|
89
|
+
headers: { "api-key": this.apiKey },
|
|
90
|
+
responseType: "arraybuffer",
|
|
91
|
+
timeout: this.timeout,
|
|
92
|
+
});
|
|
93
|
+
const filePath = `${outputFilePath}/${outputFilename}.mp4`;
|
|
94
|
+
const file = (0, firebase_1.getBucket)().file(filePath);
|
|
95
|
+
const buffer = Buffer.from(videoResp.data);
|
|
96
|
+
await file.save(buffer, { contentType: "video/mp4" });
|
|
97
|
+
const [signedUrl] = await file.getSignedUrl({
|
|
98
|
+
action: "read",
|
|
99
|
+
expires: "03-09-2491",
|
|
100
|
+
});
|
|
101
|
+
return { videoUrl: signedUrl, status: types_1.EVideoJobStatus.COMPLETED };
|
|
102
|
+
}
|
|
103
|
+
catch (downloadErr) {
|
|
104
|
+
console.error("Error downloading Azure video:", downloadErr.message);
|
|
105
|
+
return {
|
|
106
|
+
status: types_1.EVideoJobStatus.FAILED,
|
|
107
|
+
errorMessage: "Failed to download or save video content",
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (result.status === "failed" || result.status === types_1.EVideoJobStatus.FAILED) {
|
|
112
|
+
return {
|
|
113
|
+
status: types_1.EVideoJobStatus.FAILED,
|
|
114
|
+
errorMessage: `Task failed: ${result.failure_reason || "unknown"}`,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return { status: types_1.EVideoJobStatus.PENDING };
|
|
118
|
+
}
|
|
119
|
+
getCreditUsed({ modelKey, dimensions = "480x480", duration = 5, }) {
|
|
120
|
+
const modelConfig = aiModels_1.aiModelConfigs[modelKey];
|
|
121
|
+
const cost = modelConfig.cost?.table?.[dimensions]?.[duration];
|
|
122
|
+
return (0, helpers_1.getCreditsFromCost)(cost ?? 0);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
exports.AzureService = AzureService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/azure/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./azure.service"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { CreditUsageParams, TextGenerationParams, TextGenerationResult, VideoGenerationParams, VideoGenerationResult, VideoStatusParams, VideoStatusResult } from "./types";
|
|
2
|
+
export declare abstract class BaseAiGenProviderService {
|
|
3
|
+
abstract generateVideo(params: VideoGenerationParams): Promise<VideoGenerationResult>;
|
|
4
|
+
abstract checkVideoStatus(params: VideoStatusParams): Promise<VideoStatusResult | null>;
|
|
5
|
+
generateText?(params: TextGenerationParams): Promise<TextGenerationResult>;
|
|
6
|
+
getCreditUsed(params: CreditUsageParams): number;
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=baseAiGenProvider.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"baseAiGenProvider.service.d.ts","sourceRoot":"","sources":["../../../../src/services/aiGen/providers/baseAiGenProvider.service.ts"],"names":[],"mappings":"AACA,OAAO,EACL,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,SAAS,CAAC;AAEjB,8BAAsB,wBAAwB;IAC5C,QAAQ,CAAC,aAAa,CACpB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAEjC,QAAQ,CAAC,gBAAgB,CACvB,MAAM,EAAE,iBAAiB,GACxB,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAE9B,YAAY,CAAC,CACjB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,oBAAoB,CAAC;IAIhC,aAAa,CAAC,MAAM,EAAE,iBAAiB,GAAG,MAAM;CAKjD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseAiGenProviderService = void 0;
|
|
4
|
+
class BaseAiGenProviderService {
|
|
5
|
+
async generateText(params) {
|
|
6
|
+
throw new Error("generateText not implemented for this provider");
|
|
7
|
+
}
|
|
8
|
+
getCreditUsed(params) {
|
|
9
|
+
throw new Error("getCreditUsed not implemented for this provider");
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.BaseAiGenProviderService = BaseAiGenProviderService;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseAiGenProviderService } from "../baseAiGenProvider.service";
|
|
2
|
+
import { CreditUsageParams, VideoGenerationParams, VideoGenerationResult, VideoStatusParams, VideoStatusResult } from "../types";
|
|
3
|
+
export declare class GoogleService extends BaseAiGenProviderService {
|
|
4
|
+
private ai;
|
|
5
|
+
constructor();
|
|
6
|
+
generateVideo(params: VideoGenerationParams): Promise<VideoGenerationResult>;
|
|
7
|
+
checkVideoStatus({ task, outputFilename, outputFilePath, }: VideoStatusParams): Promise<VideoStatusResult | null>;
|
|
8
|
+
getCreditUsed({ modelKey, duration }: CreditUsageParams): number;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=google.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"google.service.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/google/google.service.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AACxE,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACrB,qBAAqB,EACrB,iBAAiB,EACjB,iBAAiB,EAClB,MAAM,UAAU,CAAC;AAIlB,qBAAa,aAAc,SAAQ,wBAAwB;IACzD,OAAO,CAAC,EAAE,CAAc;;IAOlB,aAAa,CACjB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,qBAAqB,CAAC;IAoC3B,gBAAgB,CAAC,EACrB,IAAI,EAEJ,cAAc,EACd,cAAyB,GAC1B,EAAE,iBAAiB,GAAG,OAAO,CAAC,iBAAiB,GAAG,IAAI,CAAC;IAgDxD,aAAa,CAAC,EAAE,QAAQ,EAAE,QAAY,EAAE,EAAE,iBAAiB,GAAG,MAAM;CAMrE"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GoogleService = void 0;
|
|
4
|
+
// google.service.ts
|
|
5
|
+
const genai_1 = require("@google/genai");
|
|
6
|
+
const aiModels_1 = require("../../../../globals/aiModels");
|
|
7
|
+
const types_1 = require("../../../../globals/types");
|
|
8
|
+
const firebase_1 = require("../../../../libs/firebase");
|
|
9
|
+
const baseAiGenProvider_service_1 = require("../baseAiGenProvider.service");
|
|
10
|
+
const helpers_1 = require("../../../../utils/helpers");
|
|
11
|
+
const helpers_2 = require("../../helpers");
|
|
12
|
+
class GoogleService extends baseAiGenProvider_service_1.BaseAiGenProviderService {
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this.ai = new genai_1.GoogleGenAI({});
|
|
16
|
+
}
|
|
17
|
+
async generateVideo(params) {
|
|
18
|
+
try {
|
|
19
|
+
(0, helpers_2.validateParams)(params);
|
|
20
|
+
const modelConfig = aiModels_1.aiModelConfigs[params.modelKey];
|
|
21
|
+
const modelId = modelConfig.modelId;
|
|
22
|
+
const request = {
|
|
23
|
+
model: modelId,
|
|
24
|
+
prompt: params.prompt,
|
|
25
|
+
config: {
|
|
26
|
+
aspectRatio: params.aspectRatio,
|
|
27
|
+
resolution: params.resolution,
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
if (params.inputImageUrl) {
|
|
31
|
+
const imgResp = await fetch(params.inputImageUrl);
|
|
32
|
+
const imgBuffer = Buffer.from(await imgResp.arrayBuffer());
|
|
33
|
+
request.image = {
|
|
34
|
+
mimeType: "image/png", // or infer from URL (jpg/png)
|
|
35
|
+
imageBytes: imgBuffer.toString("base64"),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const task = await this.ai.models.generateVideos(request);
|
|
39
|
+
return { task, status: types_1.EVideoJobStatus.TRIGGERED };
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.error("Google video generation error:", error);
|
|
43
|
+
throw {
|
|
44
|
+
code: 500,
|
|
45
|
+
message: "Google video generation failed. " + String(error),
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
async checkVideoStatus({ task,
|
|
50
|
+
// modelKey,
|
|
51
|
+
outputFilename, outputFilePath = "videos", }) {
|
|
52
|
+
// Poll the SDK for operation status
|
|
53
|
+
const result = await this.ai.operations.getVideosOperation({
|
|
54
|
+
operation: task,
|
|
55
|
+
});
|
|
56
|
+
// const modelConfig = aiModelConfigs[modelKey];
|
|
57
|
+
if (result.done) {
|
|
58
|
+
if (result.error) {
|
|
59
|
+
return {
|
|
60
|
+
status: types_1.EVideoJobStatus.FAILED,
|
|
61
|
+
errorMessage: JSON.stringify(result.error),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
const videoUri = result.response?.generatedVideos?.[0]?.video?.uri;
|
|
65
|
+
if (!videoUri) {
|
|
66
|
+
return {
|
|
67
|
+
status: types_1.EVideoJobStatus.FAILED,
|
|
68
|
+
errorMessage: "No video URL found in response",
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
// Download & upload to Firebase Storage
|
|
72
|
+
const filePath = `${outputFilePath}/${outputFilename}.mp4`;
|
|
73
|
+
const file = (0, firebase_1.getBucket)().file(filePath);
|
|
74
|
+
const videoResp = await fetch(videoUri);
|
|
75
|
+
const buffer = Buffer.from(await videoResp.arrayBuffer());
|
|
76
|
+
await file.save(buffer, { contentType: "video/mp4" });
|
|
77
|
+
const [signedUrl] = await file.getSignedUrl({
|
|
78
|
+
action: "read",
|
|
79
|
+
expires: "03-09-2491",
|
|
80
|
+
});
|
|
81
|
+
// const creditsUsed = this.calculateCredits(videoJob);
|
|
82
|
+
return {
|
|
83
|
+
videoUrl: signedUrl,
|
|
84
|
+
status: types_1.EVideoJobStatus.COMPLETED,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return { status: types_1.EVideoJobStatus.PENDING };
|
|
88
|
+
}
|
|
89
|
+
getCreditUsed({ modelKey, duration = 8 }) {
|
|
90
|
+
const modelConfig = aiModels_1.aiModelConfigs[modelKey];
|
|
91
|
+
return modelConfig.cost?.perSecond
|
|
92
|
+
? (0, helpers_1.getCreditsFromCost)(modelConfig.cost?.perSecond * duration)
|
|
93
|
+
: 0;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
exports.GoogleService = GoogleService;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/services/aiGen/providers/google/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC"}
|