| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- const crypto = require('crypto');
- function registerQuicklyRoutes(app, options) {
- const appKey = options.appKey;
- const appSecret = options.appSecret;
- const accountId = options.accountId;
- const callbackUrl = options.callbackUrl;
- const relayUrl = options.relayUrl;
- const queryUrl = options.queryUrl || 'https://server.fmode.cn/api/functions';
- app.post('/api/quickly/create', async (req, res) => {
- try {
- const { videoUrls, options: createOptions = {} } = req.body;
- if (!videoUrls || !Array.isArray(videoUrls) || videoUrls.length === 0) {
- return res.status(400).json({ error: '缺少 videoUrls 参数' });
- }
- const timestamp = Date.now().toString();
- const signStr = timestamp + '#' + appSecret;
- const sign = crypto.createHash('md5').update(signStr).digest('hex');
- const materialList = videoUrls.map(url => ({ type: 'video', value: url }));
- const preId = timestamp;
- const apiBody = {
- account_id: accountId,
- callback_url: callbackUrl,
- material_list: materialList,
- tags: createOptions.tags || '视频,AI生成',
- proportion: createOptions.proportion || '9:16',
- video_duration: createOptions.videoDuration || { min: 10, max: 30 },
- pre_id: preId,
- compose_number: 1,
- ai_voice: createOptions.aiVoice ?? 1,
- ai_bgm: createOptions.aiBgm ?? 1,
- ai_flower: 1,
- ai_subtitle: createOptions.aiSubtitle ?? 0,
- original_voice: 0,
- };
- const relayData = JSON.stringify({
- apiPath: '/v2/video/vlog/create',
- apiBody,
- appKey,
- timestamp,
- sign,
- });
- const body = JSON.stringify({ action: 'relay', relayData });
- console.log(`📦 一键成片 - timestamp=${timestamp}, sign=${sign}`);
- console.log(` 材料: ${videoUrls.length} 个视频`);
- const response = await fetch(relayUrl, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body,
- });
- const result = await response.json();
- console.log('📦 一键成片 - 响应:', JSON.stringify(result).substring(0, 300));
- res.json(result);
- } catch (err) {
- console.error('❌ 一键成片代理失败:', err.message);
- res.status(500).json({ error: err.message });
- }
- });
- app.post('/api/quickly/query', async (req, res) => {
- try {
- const { taskId } = req.body;
- if (!taskId) return res.status(400).json({ error: '缺少 taskId 参数' });
- const body = JSON.stringify({
- id: 'sWvRr8RvPT',
- _ApplicationId: 'ncloudmaster',
- action: 'query',
- taskId,
- });
- const response = await fetch(queryUrl, {
- method: 'POST',
- headers: { 'Content-Type': 'application/json' },
- body,
- });
- const result = await response.json();
- res.json(result);
- } catch (err) {
- console.error('❌ 一键成片查询失败:', err.message);
- res.status(500).json({ error: err.message });
- }
- });
- }
- module.exports = { registerQuicklyRoutes };
|