@revideo/cli 0.3.5-white.969 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +21 -27
- package/dist/server/download.js +22 -26
- package/dist/server/index.js +20 -22
- package/dist/server/player.js +89 -132
- package/dist/server/render.js +106 -136
- package/dist/utils.js +14 -13
- package/package.json +4 -4
- package/dist/server.js +0 -109
package/dist/index.js
CHANGED
|
@@ -1,39 +1,33 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports,
|
|
4
|
-
const telemetry_1 = require(
|
|
5
|
-
const commander_1 = require(
|
|
6
|
-
const index_1 = require(
|
|
7
|
-
const player_1 = require(
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
const telemetry_1 = require("@revideo/telemetry");
|
|
5
|
+
const commander_1 = require("commander");
|
|
6
|
+
const index_1 = require("./server/index");
|
|
7
|
+
const player_1 = require("./server/player");
|
|
8
8
|
const program = new commander_1.Command();
|
|
9
9
|
program
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
.name('revideo')
|
|
11
|
+
.description('CLI to interact with the revideo service')
|
|
12
|
+
.version('0.3.5');
|
|
13
13
|
program
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
'
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
'Path to the project file',
|
|
22
|
-
'./vite.config.ts',
|
|
23
|
-
)
|
|
24
|
-
.option('--port <number>', 'Port on which to start the server', '4000')
|
|
25
|
-
.option('--watchDir <path>', 'Directory to watch for changes', 'src')
|
|
26
|
-
.action(async options => {
|
|
14
|
+
.command('serve')
|
|
15
|
+
.description('UNSTABLE (still WIP): Start the revideo server in development mode. Watches for changes ' +
|
|
16
|
+
'in the project directory and re-builds the player on each change.')
|
|
17
|
+
.option('--projectFile <path>', 'Path to the project file', './vite.config.ts')
|
|
18
|
+
.option('--port <number>', 'Port on which to start the server', '4000')
|
|
19
|
+
.option('--watchDir <path>', 'Directory to watch for changes', 'src')
|
|
20
|
+
.action(async (options) => {
|
|
27
21
|
(0, telemetry_1.sendEvent)(telemetry_1.EventName.CLICommand);
|
|
28
|
-
const {projectFile, port} = options;
|
|
22
|
+
const { projectFile, port } = options;
|
|
29
23
|
process.env.PROJECT_FILE = projectFile;
|
|
30
24
|
process.env.REVIDEO_PORT = port;
|
|
31
25
|
await (0, player_1.buildProject)().catch(() => {
|
|
32
|
-
|
|
26
|
+
process.exit(1);
|
|
33
27
|
});
|
|
34
28
|
(0, index_1.createServer)(options.watchDir).listen(port, () => {
|
|
35
|
-
|
|
36
|
-
|
|
29
|
+
console.log(`Server listening on port ${port}`);
|
|
30
|
+
console.log();
|
|
37
31
|
});
|
|
38
|
-
|
|
32
|
+
});
|
|
39
33
|
program.parse(process.argv);
|
package/dist/server/download.js
CHANGED
|
@@ -1,30 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, '__esModule', {value: true});
|
|
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 });
|
|
8
6
|
exports.download = void 0;
|
|
9
|
-
const fs_1 = require(
|
|
10
|
-
const path_1 = __importDefault(require(
|
|
7
|
+
const fs_1 = require("fs");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
11
9
|
async function download(req, res) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
res.status(404).send('File not found.');
|
|
28
|
-
}
|
|
10
|
+
const { projectName } = req.params;
|
|
11
|
+
const resultFilePath = path_1.default.join(process.cwd(), `output/${projectName}`);
|
|
12
|
+
try {
|
|
13
|
+
await fs_1.promises.access(resultFilePath);
|
|
14
|
+
res.download(resultFilePath, `${projectName}`, async (err) => {
|
|
15
|
+
if (err) {
|
|
16
|
+
console.error(err);
|
|
17
|
+
res.status(500).send('Error downloading the file.');
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
console.error(`File not found ${resultFilePath}:`, error);
|
|
23
|
+
res.status(404).send('File not found.');
|
|
24
|
+
}
|
|
29
25
|
}
|
|
30
26
|
exports.download = download;
|
package/dist/server/index.js
CHANGED
|
@@ -1,26 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, '__esModule', {value: true});
|
|
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 });
|
|
8
6
|
exports.createServer = void 0;
|
|
9
|
-
const cors_1 = __importDefault(require(
|
|
10
|
-
const express_1 = __importDefault(require(
|
|
11
|
-
const download_1 = require(
|
|
12
|
-
const player_1 = require(
|
|
13
|
-
const render_1 = require(
|
|
7
|
+
const cors_1 = __importDefault(require("cors"));
|
|
8
|
+
const express_1 = __importDefault(require("express"));
|
|
9
|
+
const download_1 = require("./download");
|
|
10
|
+
const player_1 = require("./player");
|
|
11
|
+
const render_1 = require("./render");
|
|
14
12
|
function createServer(hotReloadDir) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
13
|
+
const app = (0, express_1.default)();
|
|
14
|
+
app.use(express_1.default.json({ limit: '50mb' }));
|
|
15
|
+
app.use((0, cors_1.default)());
|
|
16
|
+
app.post('/render', render_1.render);
|
|
17
|
+
app.get('/download/:projectName', download_1.download);
|
|
18
|
+
app.get('/player/:file', player_1.player);
|
|
19
|
+
if (hotReloadDir) {
|
|
20
|
+
(0, player_1.createHotReloader)(hotReloadDir);
|
|
21
|
+
}
|
|
22
|
+
return app;
|
|
25
23
|
}
|
|
26
24
|
exports.createServer = createServer;
|
package/dist/server/player.js
CHANGED
|
@@ -1,91 +1,61 @@
|
|
|
1
|
-
|
|
2
|
-
var __createBinding =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
Object.defineProperty(o, k2, desc);
|
|
20
|
-
}
|
|
21
|
-
: function (o, m, k, k2) {
|
|
22
|
-
if (k2 === undefined) k2 = k;
|
|
23
|
-
o[k2] = m[k];
|
|
24
|
-
});
|
|
25
|
-
var __setModuleDefault =
|
|
26
|
-
(this && this.__setModuleDefault) ||
|
|
27
|
-
(Object.create
|
|
28
|
-
? function (o, v) {
|
|
29
|
-
Object.defineProperty(o, 'default', {enumerable: true, value: v});
|
|
30
|
-
}
|
|
31
|
-
: function (o, v) {
|
|
32
|
-
o['default'] = v;
|
|
33
|
-
});
|
|
34
|
-
var __importStar =
|
|
35
|
-
(this && this.__importStar) ||
|
|
36
|
-
function (mod) {
|
|
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 (mod) {
|
|
37
19
|
if (mod && mod.__esModule) return mod;
|
|
38
20
|
var result = {};
|
|
39
|
-
if (mod != null)
|
|
40
|
-
for (var k in mod)
|
|
41
|
-
if (k !== 'default' && Object.prototype.hasOwnProperty.call(mod, k))
|
|
42
|
-
__createBinding(result, mod, k);
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
43
22
|
__setModuleDefault(result, mod);
|
|
44
23
|
return result;
|
|
45
|
-
|
|
46
|
-
Object.defineProperty(exports,
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
26
|
exports.player = exports.createHotReloader = exports.buildProject = void 0;
|
|
48
|
-
const chokidar_1 = require(
|
|
49
|
-
const fs_1 = require(
|
|
50
|
-
const path = __importStar(require(
|
|
51
|
-
const vite_1 = require(
|
|
27
|
+
const chokidar_1 = require("chokidar");
|
|
28
|
+
const fs_1 = require("fs");
|
|
29
|
+
const path = __importStar(require("path"));
|
|
30
|
+
const vite_1 = require("vite");
|
|
52
31
|
const YELLOW_DOT = '\u001b[33m•\u001b[0m';
|
|
53
32
|
const GREEN_CHECK = '\u001b[32m✔\u001b[0m';
|
|
54
33
|
const RED_CROSS = '\u001b[31m✘\u001b[0m';
|
|
55
|
-
const fileNotFoundMessage = filePath =>
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
padding,
|
|
60
|
-
' ',
|
|
61
|
-
) + '\n';
|
|
62
|
-
const fileChangedMessage = filePath =>
|
|
63
|
-
`${YELLOW_DOT} File ${filePath} has changed. Rebuilding...`;
|
|
64
|
-
const successMessage = (time, padding) =>
|
|
65
|
-
`\r${GREEN_CHECK} Project built successfully. ${time}ms`.padEnd(
|
|
66
|
-
padding,
|
|
67
|
-
' ',
|
|
68
|
-
) + '\n';
|
|
34
|
+
const fileNotFoundMessage = (filePath) => `${YELLOW_DOT} File ${filePath} not found. Building project...`;
|
|
35
|
+
const fileNotFoundAfterBuildingMessage = (filePath, padding) => `\r${RED_CROSS} File ${filePath} still not found after building project...`.padEnd(padding, ' ') + '\n';
|
|
36
|
+
const fileChangedMessage = (filePath) => `${YELLOW_DOT} File ${filePath} has changed. Rebuilding...`;
|
|
37
|
+
const successMessage = (time, padding) => `\r${GREEN_CHECK} Project built successfully. ${time}ms`.padEnd(padding, ' ') + '\n';
|
|
69
38
|
async function buildProject() {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
39
|
+
try {
|
|
40
|
+
await (0, vite_1.build)({
|
|
41
|
+
configFile: path.join(process.cwd(), process.env.PROJECT_FILE || ''),
|
|
42
|
+
publicDir: false,
|
|
43
|
+
build: {
|
|
44
|
+
outDir: 'dist',
|
|
45
|
+
rollupOptions: {
|
|
46
|
+
output: {
|
|
47
|
+
entryFileNames: '[name].js',
|
|
48
|
+
chunkFileNames: '[name].js',
|
|
49
|
+
assetFileNames: '[name].[ext]',
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
console.error('Error building project:', error);
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
89
59
|
}
|
|
90
60
|
exports.buildProject = buildProject;
|
|
91
61
|
/**
|
|
@@ -93,62 +63,49 @@ exports.buildProject = buildProject;
|
|
|
93
63
|
* @param dir - Directory to watch for changes.
|
|
94
64
|
*/
|
|
95
65
|
async function createHotReloader(dir) {
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
);
|
|
113
|
-
}
|
|
114
|
-
});
|
|
66
|
+
const watcher = (0, chokidar_1.watch)(dir, {
|
|
67
|
+
ignored: ['**/*.meta'],
|
|
68
|
+
});
|
|
69
|
+
watcher.on('change', async (path) => {
|
|
70
|
+
const rebuildingMessage = fileChangedMessage(path);
|
|
71
|
+
process.stdout.write(rebuildingMessage);
|
|
72
|
+
const start = Date.now();
|
|
73
|
+
try {
|
|
74
|
+
await buildProject();
|
|
75
|
+
process.stdout.write(successMessage(Date.now() - start, rebuildingMessage.length + 1));
|
|
76
|
+
}
|
|
77
|
+
catch (e) {
|
|
78
|
+
// TODO: Add more detailed error message
|
|
79
|
+
console.error('Error building project. Try to run `npm run build` manually and check for errors.');
|
|
80
|
+
}
|
|
81
|
+
});
|
|
115
82
|
}
|
|
116
83
|
exports.createHotReloader = createHotReloader;
|
|
117
84
|
async function player(req, res) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
85
|
+
const path = `./dist/${req.params.file}`;
|
|
86
|
+
let buildTime = undefined;
|
|
87
|
+
let error = false;
|
|
88
|
+
// Check if the file exists and build the project if it doesn't.
|
|
89
|
+
await fs_1.promises.access(path).catch(async () => {
|
|
90
|
+
buildTime = Date.now();
|
|
91
|
+
process.stdout.write(fileNotFoundMessage(path));
|
|
92
|
+
await buildProject().catch(() => {
|
|
93
|
+
res.status(500).send('Error building project');
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
// If the file still doesn't exist, send an error response.
|
|
97
|
+
await fs_1.promises.access(path).catch(() => {
|
|
98
|
+
process.stdout.write(fileNotFoundAfterBuildingMessage(path, fileNotFoundMessage(path).length + 1));
|
|
99
|
+
res.status(404).send(`File ${path} not found`);
|
|
100
|
+
error = true;
|
|
127
101
|
});
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
path
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
);
|
|
137
|
-
res.status(404).send(`File ${path} not found`);
|
|
138
|
-
error = true;
|
|
139
|
-
});
|
|
140
|
-
if (error) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
// If we built the project, update the log message.
|
|
144
|
-
if (buildTime) {
|
|
145
|
-
process.stdout.write(
|
|
146
|
-
successMessage(
|
|
147
|
-
Date.now() - buildTime,
|
|
148
|
-
fileNotFoundMessage(path).length + 1,
|
|
149
|
-
),
|
|
150
|
-
);
|
|
151
|
-
}
|
|
152
|
-
return res.sendFile(path, {root: './'});
|
|
102
|
+
if (error) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
// If we built the project, update the log message.
|
|
106
|
+
if (buildTime) {
|
|
107
|
+
process.stdout.write(successMessage(Date.now() - buildTime, fileNotFoundMessage(path).length + 1));
|
|
108
|
+
}
|
|
109
|
+
return res.sendFile(path, { root: './' });
|
|
153
110
|
}
|
|
154
111
|
exports.player = player;
|
package/dist/server/render.js
CHANGED
|
@@ -1,147 +1,117 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, '__esModule', {value: true});
|
|
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 });
|
|
8
6
|
exports.render = void 0;
|
|
9
|
-
const renderer_1 = require(
|
|
10
|
-
const axios_1 = __importDefault(require(
|
|
11
|
-
const path_1 = __importDefault(require(
|
|
12
|
-
const uuid_1 = require(
|
|
13
|
-
const utils_1 = require(
|
|
7
|
+
const renderer_1 = require("@revideo/renderer");
|
|
8
|
+
const axios_1 = __importDefault(require("axios"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
11
|
+
const utils_1 = require("../utils");
|
|
14
12
|
async function render(req, res) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
const { callbackUrl } = req.body;
|
|
14
|
+
if (callbackUrl) {
|
|
15
|
+
await renderWithCallback(req, res);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
await renderWithoutCallback(req, res);
|
|
19
|
+
}
|
|
21
20
|
}
|
|
22
21
|
exports.render = render;
|
|
23
22
|
async function renderWithCallback(req, res) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
23
|
+
const { variables, callbackUrl, settings } = req.body;
|
|
24
|
+
const tempProjectName = (0, uuid_1.v4)();
|
|
25
|
+
res.json({ tempProjectName });
|
|
26
|
+
try {
|
|
27
|
+
await (0, renderer_1.renderVideo)(process.env.PROJECT_FILE || '', variables, () => { }, {
|
|
28
|
+
...settings,
|
|
29
|
+
name: tempProjectName,
|
|
30
|
+
});
|
|
31
|
+
const resultFilePath = path_1.default.join(process.cwd(), `output/${tempProjectName}.mp4`);
|
|
32
|
+
const downloadLink = `${req.protocol}://${req.get('host')}/download/${tempProjectName}.mp4`;
|
|
33
|
+
const response = await axios_1.default.post(callbackUrl, {
|
|
34
|
+
tempProjectName,
|
|
35
|
+
status: 'success',
|
|
36
|
+
downloadLink,
|
|
37
|
+
}, {
|
|
38
|
+
headers: {
|
|
39
|
+
// eslint-disable-next-line
|
|
40
|
+
'Content-Type': 'application/json',
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
if (response.status !== 200) {
|
|
44
|
+
throw new Error('Callback URL responded with an error');
|
|
45
|
+
}
|
|
46
|
+
(0, utils_1.scheduleCleanup)(resultFilePath);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error(error);
|
|
50
|
+
await axios_1.default.post(callbackUrl, {
|
|
51
|
+
tempProjectName,
|
|
52
|
+
status: 'error',
|
|
53
|
+
error: error.message,
|
|
54
|
+
}, {
|
|
55
|
+
headers: {
|
|
56
|
+
// eslint-disable-next-line
|
|
57
|
+
'Content-Type': 'application/json',
|
|
58
|
+
},
|
|
59
|
+
});
|
|
58
60
|
}
|
|
59
|
-
(0, utils_1.scheduleCleanup)(resultFilePath);
|
|
60
|
-
} catch (error) {
|
|
61
|
-
console.error(error);
|
|
62
|
-
await axios_1.default.post(
|
|
63
|
-
callbackUrl,
|
|
64
|
-
{
|
|
65
|
-
tempProjectName,
|
|
66
|
-
status: 'error',
|
|
67
|
-
error: error.message,
|
|
68
|
-
},
|
|
69
|
-
{
|
|
70
|
-
headers: {
|
|
71
|
-
// eslint-disable-next-line
|
|
72
|
-
'Content-Type': 'application/json',
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
|
-
);
|
|
76
|
-
}
|
|
77
61
|
}
|
|
78
62
|
async function renderWithoutCallback(req, res) {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
);
|
|
113
|
-
res.end();
|
|
114
|
-
(0, utils_1.scheduleCleanup)(resultFilePath);
|
|
115
|
-
} catch (error) {
|
|
116
|
-
console.error(error);
|
|
117
|
-
res.write(`event: error\n`);
|
|
118
|
-
res.write(
|
|
119
|
-
`data: ${JSON.stringify({status: 'error', message: error.message})}\n\n`,
|
|
120
|
-
);
|
|
121
|
-
res.end();
|
|
63
|
+
const { variables, streamProgress, settings } = req.body;
|
|
64
|
+
const tempProjectName = (0, uuid_1.v4)();
|
|
65
|
+
const resultFilePath = path_1.default.join(process.cwd(), `output/${tempProjectName}.mp4`);
|
|
66
|
+
if (streamProgress) {
|
|
67
|
+
res.writeHead(200, {
|
|
68
|
+
// eslint-disable-next-line
|
|
69
|
+
'Content-Type': 'text/event-stream',
|
|
70
|
+
// eslint-disable-next-line
|
|
71
|
+
'Cache-Control': 'no-cache',
|
|
72
|
+
// eslint-disable-next-line
|
|
73
|
+
Connection: 'keep-alive',
|
|
74
|
+
});
|
|
75
|
+
const sendProgress = (worker, progress) => {
|
|
76
|
+
res.write(`event: progress\n`);
|
|
77
|
+
res.write(`data: ${JSON.stringify({ worker, progress })}\n\n`);
|
|
78
|
+
};
|
|
79
|
+
try {
|
|
80
|
+
await (0, renderer_1.renderVideo)(process.env.PROJECT_FILE || '', variables, sendProgress, {
|
|
81
|
+
...settings,
|
|
82
|
+
name: tempProjectName,
|
|
83
|
+
});
|
|
84
|
+
const downloadLink = `${req.protocol}://${req.get('host')}/download/${tempProjectName}.mp4`;
|
|
85
|
+
res.write(`event: completed\n`);
|
|
86
|
+
res.write(`data: ${JSON.stringify({ status: 'success', downloadLink })}\n\n`);
|
|
87
|
+
res.end();
|
|
88
|
+
(0, utils_1.scheduleCleanup)(resultFilePath);
|
|
89
|
+
}
|
|
90
|
+
catch (error) {
|
|
91
|
+
console.error(error);
|
|
92
|
+
res.write(`event: error\n`);
|
|
93
|
+
res.write(`data: ${JSON.stringify({ status: 'error', message: error.message })}\n\n`);
|
|
94
|
+
res.end();
|
|
95
|
+
}
|
|
122
96
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
status: 'error',
|
|
143
|
-
message: error.message,
|
|
144
|
-
});
|
|
97
|
+
else {
|
|
98
|
+
try {
|
|
99
|
+
await (0, renderer_1.renderVideo)(process.env.PROJECT_FILE || '', variables, () => { }, {
|
|
100
|
+
name: tempProjectName,
|
|
101
|
+
});
|
|
102
|
+
const downloadLink = `${req.protocol}://${req.get('host')}/download/${tempProjectName}.mp4`;
|
|
103
|
+
res.json({
|
|
104
|
+
status: 'success',
|
|
105
|
+
downloadLink: downloadLink,
|
|
106
|
+
});
|
|
107
|
+
(0, utils_1.scheduleCleanup)(resultFilePath);
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
console.error(error);
|
|
111
|
+
res.status(500).json({
|
|
112
|
+
status: 'error',
|
|
113
|
+
message: error.message,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
145
116
|
}
|
|
146
|
-
}
|
|
147
117
|
}
|
package/dist/utils.js
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports,
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.scheduleCleanup = void 0;
|
|
4
|
-
const fs_1 = require(
|
|
4
|
+
const fs_1 = require("fs");
|
|
5
5
|
function scheduleCleanup(filePath) {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
6
|
+
const clean = async () => {
|
|
7
|
+
try {
|
|
8
|
+
await fs_1.promises.unlink(filePath);
|
|
9
|
+
console.log(`Successfully deleted file: ${filePath}`);
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
console.error(`Error deleting file ${filePath}: ${error}`);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
// Wait 10 minutes before removing file.
|
|
16
|
+
setTimeout(clean, 10 * 60 * 1000);
|
|
16
17
|
}
|
|
17
18
|
exports.scheduleCleanup = scheduleCleanup;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revideo/cli",
|
|
3
|
-
"version": "0.3.5
|
|
3
|
+
"version": "0.3.5",
|
|
4
4
|
"description": "A CLI for revideo",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"author": "revideo",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"typescript": "^5.4.3"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@revideo/renderer": "
|
|
29
|
-
"@revideo/telemetry": "
|
|
28
|
+
"@revideo/renderer": "0.3.5",
|
|
29
|
+
"@revideo/telemetry": "0.3.5",
|
|
30
30
|
"chokidar": "^3.5.3",
|
|
31
31
|
"commander": "^12.0.0",
|
|
32
32
|
"cors": "^2.8.5",
|
|
33
33
|
"express": "^4.19.2",
|
|
34
34
|
"uuid": "^9.0.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "a2e790c1dffd637642b706b3dccfb55865e14d1e"
|
|
37
37
|
}
|
package/dist/server.js
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
var __importDefault =
|
|
3
|
-
(this && this.__importDefault) ||
|
|
4
|
-
function (mod) {
|
|
5
|
-
return mod && mod.__esModule ? mod : {default: mod};
|
|
6
|
-
};
|
|
7
|
-
Object.defineProperty(exports, '__esModule', {value: true});
|
|
8
|
-
const renderer_1 = require('@revideo/renderer');
|
|
9
|
-
const axios_1 = __importDefault(require('axios'));
|
|
10
|
-
const express_1 = __importDefault(require('express'));
|
|
11
|
-
const fs_1 = require('fs');
|
|
12
|
-
const path_1 = __importDefault(require('path'));
|
|
13
|
-
const uuid_1 = require('uuid');
|
|
14
|
-
const App = (0, express_1.default)();
|
|
15
|
-
const Port = process.env.REVIDEO_PORT || 3000;
|
|
16
|
-
App.use(express_1.default.json());
|
|
17
|
-
App.post('/render', async (req, res) => {
|
|
18
|
-
const {variables, callbackUrl} = req.body;
|
|
19
|
-
if (!callbackUrl) {
|
|
20
|
-
return res.status(400).send('Callback URL is required.');
|
|
21
|
-
}
|
|
22
|
-
const jobId = (0, uuid_1.v4)();
|
|
23
|
-
res.json({jobId});
|
|
24
|
-
try {
|
|
25
|
-
const tempProjectName = (0, uuid_1.v4)();
|
|
26
|
-
await (0, renderer_1.renderVideo)(
|
|
27
|
-
process.env.PROJECT_FILE || '',
|
|
28
|
-
variables,
|
|
29
|
-
{
|
|
30
|
-
name: tempProjectName,
|
|
31
|
-
},
|
|
32
|
-
);
|
|
33
|
-
const resultFilePath = path_1.default.join(
|
|
34
|
-
process.cwd(),
|
|
35
|
-
`output/${tempProjectName}.mp4`,
|
|
36
|
-
);
|
|
37
|
-
const downloadLink = `${req.protocol}://${req.get('host')}/download/${tempProjectName}.mp4`;
|
|
38
|
-
const response = await axios_1.default.post(
|
|
39
|
-
callbackUrl,
|
|
40
|
-
{
|
|
41
|
-
jobId,
|
|
42
|
-
status: 'success',
|
|
43
|
-
downloadLink,
|
|
44
|
-
},
|
|
45
|
-
{
|
|
46
|
-
headers: {
|
|
47
|
-
// eslint-disable-next-line
|
|
48
|
-
'Content-Type': 'application/json',
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
);
|
|
52
|
-
if (response.status !== 200) {
|
|
53
|
-
throw new Error('Callback URL responded with an error');
|
|
54
|
-
}
|
|
55
|
-
scheduleCleanup(resultFilePath);
|
|
56
|
-
} catch (error) {
|
|
57
|
-
console.error(error);
|
|
58
|
-
await axios_1.default.post(
|
|
59
|
-
callbackUrl,
|
|
60
|
-
{
|
|
61
|
-
jobId,
|
|
62
|
-
status: 'error',
|
|
63
|
-
error: error.message,
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
headers: {
|
|
67
|
-
// eslint-disable-next-line
|
|
68
|
-
'Content-Type': 'application/json',
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
App.get('/download/:projectName', async (req, res) => {
|
|
75
|
-
const {projectName} = req.params;
|
|
76
|
-
const resultFilePath = path_1.default.join(
|
|
77
|
-
process.cwd(),
|
|
78
|
-
`output/${projectName}`,
|
|
79
|
-
);
|
|
80
|
-
try {
|
|
81
|
-
await fs_1.promises.access(resultFilePath);
|
|
82
|
-
res.download(resultFilePath, `${projectName}`, async err => {
|
|
83
|
-
if (err) {
|
|
84
|
-
console.error(err);
|
|
85
|
-
res.status(500).send('Error downloading the file.');
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
} catch (error) {
|
|
89
|
-
console.error(`File not found ${resultFilePath}:`, error);
|
|
90
|
-
res.status(404).send('File not found.');
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
App.listen(Port, () => {
|
|
94
|
-
console.log(`Server running on port ${Port}`);
|
|
95
|
-
});
|
|
96
|
-
function scheduleCleanup(filePath) {
|
|
97
|
-
// wait 10 minutes before removing file
|
|
98
|
-
setTimeout(
|
|
99
|
-
async () => {
|
|
100
|
-
try {
|
|
101
|
-
await fs_1.promises.unlink(filePath);
|
|
102
|
-
console.log(`Successfully deleted file: ${filePath}`);
|
|
103
|
-
} catch (error) {
|
|
104
|
-
console.error(`Error deleting file ${filePath}: ${error}`);
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
10 * 60 * 1000,
|
|
108
|
-
);
|
|
109
|
-
}
|