@revideo/cli 0.4.0 → 0.4.1-cat.995
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 +0 -0
- package/dist/server/download.js +26 -22
- package/dist/server/player.js +9 -2
- package/dist/server/render.js +4 -3
- package/dist/server.js +109 -0
- package/dist/utils.js +13 -14
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
File without changes
|
package/dist/server/download.js
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
var __importDefault =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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});
|
|
6
8
|
exports.download = void 0;
|
|
7
|
-
const fs_1 = require(
|
|
8
|
-
const path_1 = __importDefault(require(
|
|
9
|
+
const fs_1 = require('fs');
|
|
10
|
+
const path_1 = __importDefault(require('path'));
|
|
9
11
|
async function download(req, res) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
12
|
+
const {projectName} = req.params;
|
|
13
|
+
const resultFilePath = path_1.default.join(
|
|
14
|
+
process.cwd(),
|
|
15
|
+
`output/${projectName}`,
|
|
16
|
+
);
|
|
17
|
+
try {
|
|
18
|
+
await fs_1.promises.access(resultFilePath);
|
|
19
|
+
res.download(resultFilePath, `${projectName}`, async err => {
|
|
20
|
+
if (err) {
|
|
21
|
+
console.error(err);
|
|
22
|
+
res.status(500).send('Error downloading the file.');
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
} catch (error) {
|
|
26
|
+
console.error(`File not found ${resultFilePath}:`, error);
|
|
27
|
+
res.status(404).send('File not found.');
|
|
28
|
+
}
|
|
25
29
|
}
|
|
26
30
|
exports.download = download;
|
package/dist/server/player.js
CHANGED
|
@@ -19,7 +19,7 @@ async function buildProject() {
|
|
|
19
19
|
try {
|
|
20
20
|
await (0, vite_1.build)({
|
|
21
21
|
configFile: false,
|
|
22
|
-
plugins: [(0, vite_plugin_1.default)()],
|
|
22
|
+
plugins: [(0, vite_plugin_1.default)({ project: process.env.PROJECT_FILE })],
|
|
23
23
|
build: {
|
|
24
24
|
outDir: 'dist',
|
|
25
25
|
rollupOptions: {
|
|
@@ -62,7 +62,14 @@ async function createHotReloader(dir) {
|
|
|
62
62
|
}
|
|
63
63
|
exports.createHotReloader = createHotReloader;
|
|
64
64
|
async function player(req, res) {
|
|
65
|
-
|
|
65
|
+
let path = `./dist/${req.params.file}`;
|
|
66
|
+
if (req.params.file === 'projectFile') {
|
|
67
|
+
const playerFileName = (process.env.PROJECT_FILE ?? '')
|
|
68
|
+
.split('/')
|
|
69
|
+
.pop()
|
|
70
|
+
?.replace('.ts', '.js');
|
|
71
|
+
path = `./dist/${playerFileName}`;
|
|
72
|
+
}
|
|
66
73
|
let buildTime = undefined;
|
|
67
74
|
let error = false;
|
|
68
75
|
// Check if the file exists and build the project if it doesn't.
|
package/dist/server/render.js
CHANGED
|
@@ -23,6 +23,7 @@ async function renderWithCallback(req, res) {
|
|
|
23
23
|
// TODO: validate request body
|
|
24
24
|
const { variables, callbackUrl, settings } = req.body;
|
|
25
25
|
const tempProjectName = (0, uuid_1.v4)();
|
|
26
|
+
const outputFileName = `${tempProjectName}.mp4`;
|
|
26
27
|
res.json({ tempProjectName });
|
|
27
28
|
try {
|
|
28
29
|
await (0, renderer_1.renderVideo)({
|
|
@@ -30,11 +31,11 @@ async function renderWithCallback(req, res) {
|
|
|
30
31
|
variables,
|
|
31
32
|
settings: {
|
|
32
33
|
...settings,
|
|
33
|
-
outFile:
|
|
34
|
+
outFile: outputFileName,
|
|
34
35
|
},
|
|
35
36
|
});
|
|
36
|
-
const resultFilePath = path_1.default.join(process.cwd(), `output/${
|
|
37
|
-
const downloadLink = `${req.protocol}://${req.get('host')}/download/${
|
|
37
|
+
const resultFilePath = path_1.default.join(process.cwd(), `output/${outputFileName}`);
|
|
38
|
+
const downloadLink = `${req.protocol}://${req.get('host')}/download/${outputFileName}`;
|
|
38
39
|
const response = await axios_1.default.post(callbackUrl, {
|
|
39
40
|
tempProjectName,
|
|
40
41
|
status: 'success',
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
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
|
+
}
|
package/dist/utils.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
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
|
-
|
|
16
|
-
setTimeout(clean, 10 * 60 * 1000);
|
|
6
|
+
const clean = async () => {
|
|
7
|
+
try {
|
|
8
|
+
await fs_1.promises.unlink(filePath);
|
|
9
|
+
console.log(`Successfully deleted file: ${filePath}`);
|
|
10
|
+
} catch (error) {
|
|
11
|
+
console.error(`Error deleting file ${filePath}: ${error}`);
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
// Wait 10 minutes before removing file.
|
|
15
|
+
setTimeout(clean, 10 * 60 * 1000);
|
|
17
16
|
}
|
|
18
17
|
exports.scheduleCleanup = scheduleCleanup;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revideo/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.1-cat.995+cf88b1a",
|
|
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": "0.4.
|
|
29
|
-
"@revideo/telemetry": "0.4.
|
|
28
|
+
"@revideo/renderer": "^0.4.1-cat.995+cf88b1a",
|
|
29
|
+
"@revideo/telemetry": "^0.4.1-cat.995+cf88b1a",
|
|
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": "cf88b1a08e579957ff3c4d44975a47afa96d688c"
|
|
37
37
|
}
|