@revideo/vite-plugin 0.4.7-two.1024 → 0.4.7

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.
@@ -1,12 +1,10 @@
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});
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.corsProxyPlugin = void 0;
9
- const follow_redirects_1 = __importDefault(require('follow-redirects'));
7
+ const follow_redirects_1 = __importDefault(require("follow-redirects"));
10
8
  /**
11
9
  * This module provides the proxy located at
12
10
  * /cors-proxy/...
@@ -24,78 +22,69 @@ const follow_redirects_1 = __importDefault(require('follow-redirects'));
24
22
  * same host as the main app.
25
23
  */
26
24
  function corsProxyPlugin(config) {
27
- setupEnvVarsForProxy(config);
28
- return {
29
- name: 'revideo:cors-proxy',
30
- configureServer(server) {
31
- if (config !== false && config !== undefined) {
32
- motionCanvasCorsProxy(
33
- server.middlewares,
34
- config === true ? {} : config,
35
- );
36
- }
37
- },
38
- };
25
+ setupEnvVarsForProxy(config);
26
+ return {
27
+ name: 'revideo:cors-proxy',
28
+ configureServer(server) {
29
+ if (config !== false && config !== undefined) {
30
+ motionCanvasCorsProxy(server.middlewares, config === true ? {} : config);
31
+ }
32
+ },
33
+ };
39
34
  }
40
35
  exports.corsProxyPlugin = corsProxyPlugin;
41
36
  function setupEnvVarsForProxy(config) {
42
- // Define Keys for Env Var
43
- const prefix = 'VITE_MC_PROXY_';
44
- const isEnabledKey = prefix + 'ENABLED';
45
- const allowList = prefix + 'ALLOW_LIST';
46
- if (config === true) {
47
- config = {}; // Use Default values
48
- }
49
- process.env[isEnabledKey] = String(!!config); // 'true' or 'false'
50
- if (config) {
51
- // These values are only configured if the Proxy is enabled
52
- // You cannot access them via import.meta.env if the Proxy
53
- // is set to false
54
- process.env[allowList] = JSON.stringify(config.allowListHosts ?? []);
55
- }
56
- }
57
- function motionCanvasCorsProxy(middleware, config) {
58
- // Set the default config if no config was provided
59
- config.allowedMimeTypes ??= ['image/*', 'video/*'];
60
- config.allowListHosts ??= [];
61
- // Check the Mime Types to have a correct structure (left/right)
62
- // not having them in the correct format would crash the Middleware
63
- // further down below
64
- if ((config.allowedMimeTypes ?? []).some(e => e.split('/').length !== 2)) {
65
- throw new Error(
66
- "Invalid config for Proxy:\nAll Entries must have the following format:\n 'left/right' where left may be '*'",
67
- );
68
- }
69
- middleware.use((req, res, next) => {
70
- if (!req.url || !req.url.startsWith('/cors-proxy/')) {
71
- // url does not start with /cors-proxy/, so this
72
- // middleware does not care about it
73
- return next();
74
- }
75
- // For now, only allow GET Requests
76
- if (req.method !== 'GET') {
77
- return writeError('Only GET Requests are allowed', res, 405);
37
+ // Define Keys for Env Var
38
+ const prefix = 'VITE_MC_PROXY_';
39
+ const isEnabledKey = prefix + 'ENABLED';
40
+ const allowList = prefix + 'ALLOW_LIST';
41
+ if (config === true) {
42
+ config = {}; // Use Default values
78
43
  }
79
- let sourceUrl;
80
- try {
81
- sourceUrl = extractDestination(req.url);
82
- } catch (err) {
83
- return writeError(err, res);
44
+ process.env[isEnabledKey] = String(!!config); // 'true' or 'false'
45
+ if (config) {
46
+ // These values are only configured if the Proxy is enabled
47
+ // You cannot access them via import.meta.env if the Proxy
48
+ // is set to false
49
+ process.env[allowList] = JSON.stringify(config.allowListHosts ?? []);
84
50
  }
85
- if (
86
- !isReceivedUrlInAllowedHosts(sourceUrl.hostname, config.allowListHosts)
87
- ) {
88
- return writeError(
89
- `Blocked by Proxy: ${sourceUrl.hostname} is not on Hosts Allowlist`,
90
- res,
91
- );
51
+ }
52
+ function motionCanvasCorsProxy(middleware, config) {
53
+ // Set the default config if no config was provided
54
+ config.allowedMimeTypes ??= ['image/*', 'video/*'];
55
+ config.allowListHosts ??= [];
56
+ // Check the Mime Types to have a correct structure (left/right)
57
+ // not having them in the correct format would crash the Middleware
58
+ // further down below
59
+ if ((config.allowedMimeTypes ?? []).some(e => e.split('/').length !== 2)) {
60
+ throw new Error("Invalid config for Proxy:\nAll Entries must have the following format:\n 'left/right' where left may be '*'");
92
61
  }
93
- // Get the resource, do some checks. Throws an Error
94
- // if the checks fail. The catch then writes an Error
95
- return tryGetResource(res, sourceUrl, config).catch(error => {
96
- writeError(error, res);
62
+ middleware.use((req, res, next) => {
63
+ if (!req.url || !req.url.startsWith('/cors-proxy/')) {
64
+ // url does not start with /cors-proxy/, so this
65
+ // middleware does not care about it
66
+ return next();
67
+ }
68
+ // For now, only allow GET Requests
69
+ if (req.method !== 'GET') {
70
+ return writeError('Only GET Requests are allowed', res, 405);
71
+ }
72
+ let sourceUrl;
73
+ try {
74
+ sourceUrl = extractDestination(req.url);
75
+ }
76
+ catch (err) {
77
+ return writeError(err, res);
78
+ }
79
+ if (!isReceivedUrlInAllowedHosts(sourceUrl.hostname, config.allowListHosts)) {
80
+ return writeError(`Blocked by Proxy: ${sourceUrl.hostname} is not on Hosts Allowlist`, res);
81
+ }
82
+ // Get the resource, do some checks. Throws an Error
83
+ // if the checks fail. The catch then writes an Error
84
+ return tryGetResource(res, sourceUrl, config).catch(error => {
85
+ writeError(error, res);
86
+ });
97
87
  });
98
- });
99
88
  }
100
89
  /**
101
90
  * Unwrap the destination from the URL.
@@ -109,34 +98,32 @@ function motionCanvasCorsProxy(middleware, config) {
109
98
  * @returns The URL that needs to be called.
110
99
  */
111
100
  function extractDestination(url) {
112
- const withoutPrefix = url.replace('/cors-proxy/', '');
113
- const asUrl = new URL(decodeURIComponent(withoutPrefix));
114
- if (asUrl.protocol !== 'http:' && asUrl.protocol !== 'https:') {
115
- throw new Error('Only supported protocols are http and https');
116
- }
117
- return asUrl;
101
+ const withoutPrefix = url.replace('/cors-proxy/', '');
102
+ const asUrl = new URL(decodeURIComponent(withoutPrefix));
103
+ if (asUrl.protocol !== 'http:' && asUrl.protocol !== 'https:') {
104
+ throw new Error('Only supported protocols are http and https');
105
+ }
106
+ return asUrl;
118
107
  }
119
108
  /**
120
109
  * A simple Error Helper that will write an Error and close the response.
121
110
  */
122
111
  function writeError(message, res, statusCode = 400) {
123
- res.writeHead(statusCode, message);
124
- res.end();
112
+ res.writeHead(statusCode, message);
113
+ res.end();
125
114
  }
126
115
  /**
127
116
  * Check if the Proxy is allowed to get the requested resource based on the
128
117
  * host.
129
118
  */
130
119
  function isReceivedUrlInAllowedHosts(hostname, allowListHosts) {
131
- if (!allowListHosts || allowListHosts.length === 0) {
132
- // if the allowListHosts is just the predefinedAllowlist, the user has not
133
- // set any additional hosts. In this case, allow any hostname
134
- return true;
135
- }
136
- // Check if the hostname is any of the values set in allowListHosts
137
- return allowListHosts.some(
138
- e => e.toLowerCase().trim() === hostname.toLowerCase().trim(),
139
- );
120
+ if (!allowListHosts || allowListHosts.length === 0) {
121
+ // if the allowListHosts is just the predefinedAllowlist, the user has not
122
+ // set any additional hosts. In this case, allow any hostname
123
+ return true;
124
+ }
125
+ // Check if the hostname is any of the values set in allowListHosts
126
+ return allowListHosts.some(e => e.toLowerCase().trim() === hostname.toLowerCase().trim());
140
127
  }
141
128
  /**
142
129
  * Check if the Proxy is allowed to get the requested resource based on the
@@ -146,98 +133,87 @@ function isReceivedUrlInAllowedHosts(hostname, allowListHosts) {
146
133
  * Also handles catch-All Declarations like `image/*`.
147
134
  */
148
135
  function isResultOfAllowedResourceType(foundMimeType, allowedMimeTypes) {
149
- if (!allowedMimeTypes || allowedMimeTypes.length === 0) {
150
- return true; // no filters set
151
- }
152
- if (foundMimeType.split('/').length !== 2) {
153
- return false; // invalid mime structure
154
- }
155
- const [leftSegment, rightSegment] = foundMimeType
156
- .split('/')
157
- .map(e => e.trim().toLowerCase());
158
- // Get all Segments where the left Part is identical between foundMimeType and
159
- // allowedMimeType.
160
- const leftSegmentMatches = allowedMimeTypes.filter(
161
- e => e.trim().toLowerCase().split('/')[0] === leftSegment,
162
- );
163
- if (leftSegmentMatches.length === 0) {
164
- // No matches at all, not even catchall - resource is rejected.
165
- return false;
166
- }
167
- // This just gets the right part of the MIME Types from the
168
- // configured allowList, e.g. "image/png" -> png
169
- const rightSegmentOfLeftSegmentMatches = leftSegmentMatches.map(
170
- e => e.split('/')[1],
171
- );
172
- // if an exact match or a catchall is found, the resource is allowed to be
173
- // proxied.
174
- return rightSegmentOfLeftSegmentMatches.some(
175
- e => e === '*' || e === rightSegment,
176
- );
136
+ if (!allowedMimeTypes || allowedMimeTypes.length === 0) {
137
+ return true; // no filters set
138
+ }
139
+ if (foundMimeType.split('/').length !== 2) {
140
+ return false; // invalid mime structure
141
+ }
142
+ const [leftSegment, rightSegment] = foundMimeType
143
+ .split('/')
144
+ .map(e => e.trim().toLowerCase());
145
+ // Get all Segments where the left Part is identical between foundMimeType and
146
+ // allowedMimeType.
147
+ const leftSegmentMatches = allowedMimeTypes.filter(e => e.trim().toLowerCase().split('/')[0] === leftSegment);
148
+ if (leftSegmentMatches.length === 0) {
149
+ // No matches at all, not even catchall - resource is rejected.
150
+ return false;
151
+ }
152
+ // This just gets the right part of the MIME Types from the
153
+ // configured allowList, e.g. "image/png" -> png
154
+ const rightSegmentOfLeftSegmentMatches = leftSegmentMatches.map(e => e.split('/')[1]);
155
+ // if an exact match or a catchall is found, the resource is allowed to be
156
+ // proxied.
157
+ return rightSegmentOfLeftSegmentMatches.some(e => e === '*' || e === rightSegment);
177
158
  }
178
159
  /**
179
160
  * Requests a remote resource with the help of axios
180
161
  * May throw a string in case of a bad mime-type or missing headers
181
162
  */
182
163
  async function tryGetResource(res, sourceUrl, config) {
183
- // Turn this callback into a Promise to avoid additional nesting
184
- const result = await new Promise((res, rej) => {
185
- try {
186
- // We check what protocol was used and decide if we use http or https
187
- const request = (
188
- sourceUrl.protocol.startsWith('https')
189
- ? follow_redirects_1.default.https
190
- : follow_redirects_1.default.http
191
- ).get(sourceUrl, data => {
192
- res(data);
193
- });
194
- request.on('error', err => {
195
- if (err.code && err.code === 'ENOTFOUND') {
196
- // This is a bit hacky, but this basically returns as a
197
- // 404 instead of crashing the Node Server with ENOTFOUND
198
- res({statusCode: 404});
199
- } else {
200
- rej(err);
164
+ // Turn this callback into a Promise to avoid additional nesting
165
+ const result = await new Promise((res, rej) => {
166
+ try {
167
+ // We check what protocol was used and decide if we use http or https
168
+ const request = (sourceUrl.protocol.startsWith('https')
169
+ ? follow_redirects_1.default.https
170
+ : follow_redirects_1.default.http).get(sourceUrl, data => {
171
+ res(data);
172
+ });
173
+ request.on('error', (err) => {
174
+ if (err.code && err.code === 'ENOTFOUND') {
175
+ // This is a bit hacky, but this basically returns as a
176
+ // 404 instead of crashing the Node Server with ENOTFOUND
177
+ res({ statusCode: 404 });
178
+ }
179
+ else {
180
+ rej(err);
181
+ }
182
+ });
183
+ }
184
+ catch (err) {
185
+ rej(err);
201
186
  }
202
- });
203
- } catch (err) {
204
- rej(err);
187
+ });
188
+ if (!result.statusCode || result.statusCode >= 300) {
189
+ throw 'Unexpected Status: ' + result.statusCode ?? 'NO_STATUS';
205
190
  }
206
- });
207
- if (!result.statusCode || result.statusCode >= 300) {
208
- throw 'Unexpected Status: ' + result.statusCode ?? 'NO_STATUS';
209
- }
210
- const contentType = result.headers['content-type'];
211
- const contentLength = result.headers['content-length'];
212
- if (!contentType) {
213
- throw 'Proxied Response does not contain a Content Type';
214
- }
215
- if (!contentLength) {
216
- throw 'Proxied Response does not contain a Content Length';
217
- }
218
- if (
219
- !isResultOfAllowedResourceType(
220
- contentType.toString(),
221
- config.allowedMimeTypes ?? [],
222
- )
223
- ) {
224
- throw 'Proxied response has blocked content-type: ' + contentType;
225
- }
226
- // Prepare Response
227
- for (const key in result.headers) {
228
- const header = result.headers[key];
229
- if (header === undefined) {
230
- console.warn('Proxy: Received Header is empty. Skipping…');
231
- continue;
191
+ const contentType = result.headers['content-type'];
192
+ const contentLength = result.headers['content-length'];
193
+ if (!contentType) {
194
+ throw 'Proxied Response does not contain a Content Type';
232
195
  }
233
- res.setHeader(key, header);
234
- }
235
- res.addListener('error', () => {
236
- console.log('Proxy: Connection Reset');
237
- });
238
- res.setHeader('x-proxy-destination', sourceUrl.toString());
239
- // Don't store on the server, just immediately pass on the
240
- // received chunks
241
- result.pipe(res);
196
+ if (!contentLength) {
197
+ throw 'Proxied Response does not contain a Content Length';
198
+ }
199
+ if (!isResultOfAllowedResourceType(contentType.toString(), config.allowedMimeTypes ?? [])) {
200
+ throw 'Proxied response has blocked content-type: ' + contentType;
201
+ }
202
+ // Prepare Response
203
+ for (const key in result.headers) {
204
+ const header = result.headers[key];
205
+ if (header === undefined) {
206
+ console.warn('Proxy: Received Header is empty. Skipping…');
207
+ continue;
208
+ }
209
+ res.setHeader(key, header);
210
+ }
211
+ res.addListener('error', () => {
212
+ console.log('Proxy: Connection Reset');
213
+ });
214
+ res.setHeader('x-proxy-destination', sourceUrl.toString());
215
+ // Don't store on the server, just immediately pass on the
216
+ // received chunks
217
+ result.pipe(res);
242
218
  }
243
- //# sourceMappingURL=corsProxy.js.map
219
+ //# sourceMappingURL=corsProxy.js.map
@@ -1,11 +1,8 @@
1
- import {Plugin} from 'vite';
2
- import {Projects} from '../utils';
1
+ import { Plugin } from 'vite';
2
+ import { Projects } from '../utils';
3
3
  interface EditorPluginConfig {
4
- editor: string;
5
- projects: Projects;
4
+ editor: string;
5
+ projects: Projects;
6
6
  }
7
- export declare function editorPlugin({
8
- editor,
9
- projects,
10
- }: EditorPluginConfig): Plugin;
7
+ export declare function editorPlugin({ editor, projects }: EditorPluginConfig): Plugin;
11
8
  export {};
@@ -1,79 +1,72 @@
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});
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.editorPlugin = void 0;
9
- const fs_1 = __importDefault(require('fs'));
10
- const path_1 = __importDefault(require('path'));
11
- function editorPlugin({editor, projects}) {
12
- const editorPath = path_1.default.dirname(require.resolve(editor));
13
- const editorFile = fs_1.default.readFileSync(
14
- path_1.default.resolve(editorPath, 'editor.html'),
15
- );
16
- const htmlParts = editorFile
17
- .toString()
18
- .replace(
19
- '{{style}}',
20
- `/@fs/${path_1.default.resolve(editorPath, 'style.css')}`,
21
- )
22
- .split('{{source}}');
23
- const createHtml = src => htmlParts[0] + src + htmlParts[1];
24
- const resolvedEditorId = '\0virtual:editor';
25
- return {
26
- name: 'revideo:editor',
27
- async load(id) {
28
- const [, query] = id.split('?');
29
- if (id.startsWith(resolvedEditorId)) {
30
- if (projects.list.length === 1) {
31
- /* language=typescript */
32
- return `\
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ function editorPlugin({ editor, projects }) {
10
+ const editorPath = path_1.default.dirname(require.resolve(editor));
11
+ const editorFile = fs_1.default.readFileSync(path_1.default.resolve(editorPath, 'editor.html'));
12
+ const htmlParts = editorFile
13
+ .toString()
14
+ .replace('{{style}}', `/@fs/${path_1.default.resolve(editorPath, 'style.css')}`)
15
+ .split('{{source}}');
16
+ const createHtml = (src) => htmlParts[0] + src + htmlParts[1];
17
+ const resolvedEditorId = '\0virtual:editor';
18
+ return {
19
+ name: 'revideo:editor',
20
+ async load(id) {
21
+ const [, query] = id.split('?');
22
+ if (id.startsWith(resolvedEditorId)) {
23
+ if (projects.list.length === 1) {
24
+ /* language=typescript */
25
+ return `\
33
26
  import {editor} from '${editor}';
34
27
  import project from '${projects.list[0].url}?project';
35
28
  editor(project);
36
29
  `;
37
- }
38
- if (query) {
39
- const params = new URLSearchParams(query);
40
- const name = params.get('project');
41
- if (name && projects.lookup.has(name)) {
42
- /* language=typescript */
43
- return `\
30
+ }
31
+ if (query) {
32
+ const params = new URLSearchParams(query);
33
+ const name = params.get('project');
34
+ if (name && projects.lookup.has(name)) {
35
+ /* language=typescript */
36
+ return `\
44
37
  import {editor} from '${editor}';
45
38
  import project from '${projects.lookup.get(name).url}?project';
46
39
  editor(project);
47
40
  `;
48
- }
49
- }
50
- /* language=typescript */
51
- return `\
41
+ }
42
+ }
43
+ /* language=typescript */
44
+ return `\
52
45
  import {index} from '${editor}';
53
46
  index(${JSON.stringify(projects.list)});
54
47
  `;
55
- }
56
- },
57
- configureServer(server) {
58
- server.middlewares.use((req, res, next) => {
59
- if (req.url) {
60
- const url = new URL(req.url, `http://${req.headers.host}`);
61
- if (url.pathname === '/') {
62
- res.setHeader('Content-Type', 'text/html');
63
- res.end(createHtml('/@id/__x00__virtual:editor'));
64
- return;
65
- }
66
- const name = url.pathname.slice(1);
67
- if (name && projects.lookup.has(name)) {
68
- res.setHeader('Content-Type', 'text/html');
69
- res.end(createHtml(`/@id/__x00__virtual:editor?project=${name}`));
70
- return;
71
- }
72
- }
73
- next();
74
- });
75
- },
76
- };
48
+ }
49
+ },
50
+ configureServer(server) {
51
+ server.middlewares.use((req, res, next) => {
52
+ if (req.url) {
53
+ const url = new URL(req.url, `http://${req.headers.host}`);
54
+ if (url.pathname === '/') {
55
+ res.setHeader('Content-Type', 'text/html');
56
+ res.end(createHtml('/@id/__x00__virtual:editor'));
57
+ return;
58
+ }
59
+ const name = url.pathname.slice(1);
60
+ if (name && projects.lookup.has(name)) {
61
+ res.setHeader('Content-Type', 'text/html');
62
+ res.end(createHtml(`/@id/__x00__virtual:editor?project=${name}`));
63
+ return;
64
+ }
65
+ }
66
+ next();
67
+ });
68
+ },
69
+ };
77
70
  }
78
71
  exports.editorPlugin = editorPlugin;
79
- //# sourceMappingURL=editor.js.map
72
+ //# sourceMappingURL=editor.js.map
@@ -1,8 +1,6 @@
1
- import {Plugin} from 'vite';
1
+ import { Plugin } from 'vite';
2
2
  interface ExporterPluginConfig {
3
- outputPath: string;
3
+ outputPath: string;
4
4
  }
5
- export declare function exporterPlugin({
6
- outputPath,
7
- }: ExporterPluginConfig): Plugin;
5
+ export declare function exporterPlugin({ outputPath }: ExporterPluginConfig): Plugin;
8
6
  export {};
@@ -1,58 +1,46 @@
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});
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.exporterPlugin = void 0;
9
- const fs_1 = __importDefault(require('fs'));
10
- const mime_types_1 = __importDefault(require('mime-types'));
11
- const path_1 = __importDefault(require('path'));
12
- const openInExplorer_1 = require('../openInExplorer');
13
- function exporterPlugin({outputPath}) {
14
- return {
15
- name: 'revideo:exporter',
16
- configureServer(server) {
17
- server.middlewares.use((req, res, next) => {
18
- if (req.url === '/__open-output-path') {
19
- if (!fs_1.default.existsSync(outputPath)) {
20
- fs_1.default.mkdirSync(outputPath, {recursive: true});
21
- }
22
- (0, openInExplorer_1.openInExplorer)(outputPath);
23
- res.end();
24
- return;
25
- }
26
- next();
27
- });
28
- server.ws.on(
29
- 'revideo:export',
30
- async (
31
- {data, frame, sceneFrame, subDirectories, mimeType, groupByScene},
32
- client,
33
- ) => {
34
- const name = (groupByScene ? sceneFrame : frame)
35
- .toString()
36
- .padStart(6, '0');
37
- const extension = mime_types_1.default.extension(mimeType);
38
- const outputFilePath = path_1.default.join(
39
- outputPath,
40
- ...subDirectories,
41
- `${name}.${extension}`,
42
- );
43
- const outputDirectory = path_1.default.dirname(outputFilePath);
44
- if (!fs_1.default.existsSync(outputDirectory)) {
45
- fs_1.default.mkdirSync(outputDirectory, {recursive: true});
46
- }
47
- const base64Data = data.slice(data.indexOf(',') + 1);
48
- await fs_1.default.promises.writeFile(outputFilePath, base64Data, {
49
- encoding: 'base64',
50
- });
51
- client.send('revideo:export-ack', {frame});
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const mime_types_1 = __importDefault(require("mime-types"));
9
+ const path_1 = __importDefault(require("path"));
10
+ const openInExplorer_1 = require("../openInExplorer");
11
+ function exporterPlugin({ outputPath }) {
12
+ return {
13
+ name: 'revideo:exporter',
14
+ configureServer(server) {
15
+ server.middlewares.use((req, res, next) => {
16
+ if (req.url === '/__open-output-path') {
17
+ if (!fs_1.default.existsSync(outputPath)) {
18
+ fs_1.default.mkdirSync(outputPath, { recursive: true });
19
+ }
20
+ (0, openInExplorer_1.openInExplorer)(outputPath);
21
+ res.end();
22
+ return;
23
+ }
24
+ next();
25
+ });
26
+ server.ws.on('revideo:export', async ({ data, frame, sceneFrame, subDirectories, mimeType, groupByScene }, client) => {
27
+ const name = (groupByScene ? sceneFrame : frame)
28
+ .toString()
29
+ .padStart(6, '0');
30
+ const extension = mime_types_1.default.extension(mimeType);
31
+ const outputFilePath = path_1.default.join(outputPath, ...subDirectories, `${name}.${extension}`);
32
+ const outputDirectory = path_1.default.dirname(outputFilePath);
33
+ if (!fs_1.default.existsSync(outputDirectory)) {
34
+ fs_1.default.mkdirSync(outputDirectory, { recursive: true });
35
+ }
36
+ const base64Data = data.slice(data.indexOf(',') + 1);
37
+ await fs_1.default.promises.writeFile(outputFilePath, base64Data, {
38
+ encoding: 'base64',
39
+ });
40
+ client.send('revideo:export-ack', { frame });
41
+ });
52
42
  },
53
- );
54
- },
55
- };
43
+ };
56
44
  }
57
45
  exports.exporterPlugin = exporterPlugin;
58
- //# sourceMappingURL=imageExporter.js.map
46
+ //# sourceMappingURL=imageExporter.js.map