@lvce-editor/main-process 4.5.0 → 4.7.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/dist/mainProcessMain.js +39 -24
- package/package.json +1 -1
package/dist/mainProcessMain.js
CHANGED
|
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'node:url';
|
|
|
5
5
|
import { inspect } from 'node:util';
|
|
6
6
|
import { spawn } from 'node:child_process';
|
|
7
7
|
import { Console } from 'node:console';
|
|
8
|
-
import { createWriteStream, readFileSync, existsSync } from 'node:fs';
|
|
8
|
+
import { createWriteStream, readFileSync, openAsBlob, existsSync } from 'node:fs';
|
|
9
9
|
import { tmpdir, homedir } from 'node:os';
|
|
10
10
|
import * as NodePath from 'node:path';
|
|
11
11
|
import { dirname, join as join$1 } from 'node:path';
|
|
@@ -4178,6 +4178,32 @@ const handlePermissionCheck$1 = (webContents, permission, origin, details) => {
|
|
|
4178
4178
|
return isAllowed;
|
|
4179
4179
|
};
|
|
4180
4180
|
|
|
4181
|
+
const getElectronFileResponseIpc = async (url, request) => {
|
|
4182
|
+
const {
|
|
4183
|
+
body,
|
|
4184
|
+
init
|
|
4185
|
+
} = await invoke('GetElectronFileResponse.getElectronFileResponse', url, request);
|
|
4186
|
+
const response = new Response(body, init);
|
|
4187
|
+
return response;
|
|
4188
|
+
};
|
|
4189
|
+
|
|
4190
|
+
/* eslint-disable n/no-unsupported-features/node-builtins */
|
|
4191
|
+
const getFileResponse = async (absolutePath, headers) => {
|
|
4192
|
+
// TODO support request method head
|
|
4193
|
+
const blob = await openAsBlob(absolutePath);
|
|
4194
|
+
const response = new Response(blob, {
|
|
4195
|
+
headers,
|
|
4196
|
+
status: 200
|
|
4197
|
+
});
|
|
4198
|
+
return response;
|
|
4199
|
+
};
|
|
4200
|
+
|
|
4201
|
+
const getNotFoundResponse = () => {
|
|
4202
|
+
return new Response('Not Found', {
|
|
4203
|
+
status: 404
|
|
4204
|
+
});
|
|
4205
|
+
};
|
|
4206
|
+
|
|
4181
4207
|
let config;
|
|
4182
4208
|
const createConfig = () => {
|
|
4183
4209
|
const configPath = join$1(root, 'config.json');
|
|
@@ -4192,49 +4218,38 @@ const getOrCreateConfig = () => {
|
|
|
4192
4218
|
return config;
|
|
4193
4219
|
};
|
|
4194
4220
|
|
|
4221
|
+
const getRelativePath = url => {
|
|
4222
|
+
const relative = url.slice(scheme.length + 4);
|
|
4223
|
+
return relative;
|
|
4224
|
+
};
|
|
4195
4225
|
const getElectronFileResponseConfig = async (url, request) => {
|
|
4196
4226
|
const parsedConfig = getOrCreateConfig();
|
|
4197
4227
|
const {
|
|
4198
4228
|
files,
|
|
4199
4229
|
headers
|
|
4200
4230
|
} = parsedConfig;
|
|
4201
|
-
const relative = url
|
|
4231
|
+
const relative = getRelativePath(url);
|
|
4232
|
+
if (relative.startsWith('/remote')) {
|
|
4233
|
+
return getElectronFileResponseIpc(url, request);
|
|
4234
|
+
}
|
|
4202
4235
|
const actual = relative === '/' ? '/index.html' : relative;
|
|
4203
4236
|
const match = files[actual];
|
|
4204
4237
|
if (match === undefined) {
|
|
4205
|
-
return
|
|
4206
|
-
status: 404
|
|
4207
|
-
});
|
|
4238
|
+
return getNotFoundResponse();
|
|
4208
4239
|
}
|
|
4209
4240
|
const responseHeaders = headers[match];
|
|
4210
4241
|
const absolutePath = join$1(root, 'static', actual);
|
|
4211
4242
|
if (!existsSync(absolutePath)) {
|
|
4212
|
-
return
|
|
4213
|
-
status: 404
|
|
4214
|
-
});
|
|
4243
|
+
return getNotFoundResponse();
|
|
4215
4244
|
}
|
|
4216
|
-
|
|
4217
|
-
const response = new Response(content, {
|
|
4218
|
-
headers: responseHeaders,
|
|
4219
|
-
status: 200
|
|
4220
|
-
});
|
|
4221
|
-
return response;
|
|
4222
|
-
};
|
|
4223
|
-
|
|
4224
|
-
const getElectronFileResponseIpc = async (url, request) => {
|
|
4225
|
-
const {
|
|
4226
|
-
body,
|
|
4227
|
-
init
|
|
4228
|
-
} = await invoke('GetElectronFileResponse.getElectronFileResponse', url, request);
|
|
4229
|
-
const response = new Response(body, init);
|
|
4230
|
-
return response;
|
|
4245
|
+
return getFileResponse(absolutePath, responseHeaders);
|
|
4231
4246
|
};
|
|
4232
4247
|
|
|
4233
4248
|
const getElectronFileResponse = async (url, request) => {
|
|
4234
4249
|
if (useIpcForResponse) {
|
|
4235
4250
|
return getElectronFileResponseIpc(url, request);
|
|
4236
4251
|
}
|
|
4237
|
-
return getElectronFileResponseConfig(url);
|
|
4252
|
+
return getElectronFileResponseConfig(url, request);
|
|
4238
4253
|
};
|
|
4239
4254
|
|
|
4240
4255
|
/**
|