@walkhi/code-relax 0.1.0-beta.106 → 0.1.0-beta.107
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/build-platform.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"layout":"npm-platform-packages","version":"0.1.0-beta.
|
|
1
|
+
{"layout":"npm-platform-packages","version":"0.1.0-beta.107"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export const FILE_READ_LIMIT =
|
|
1
|
+
export const FILE_READ_LIMIT = 50 * 1024 * 1024;
|
|
2
2
|
export const FILE_PART_BYTES = 256 * 1024;
|
|
3
3
|
export class FileRangeError extends Error {
|
|
4
4
|
constructor(statusCode, message) { super(message); this.statusCode = statusCode; }
|
|
@@ -2,9 +2,9 @@ import crypto from 'node:crypto';
|
|
|
2
2
|
import fs from 'node:fs/promises';
|
|
3
3
|
import path from 'node:path';
|
|
4
4
|
|
|
5
|
-
export const MAX_FILE_BYTES =
|
|
5
|
+
export const MAX_FILE_BYTES = 50 * 1024 * 1024;
|
|
6
6
|
export const MAX_FILE_COUNT = 4;
|
|
7
|
-
export const MAX_TOTAL_BYTES =
|
|
7
|
+
export const MAX_TOTAL_BYTES = MAX_FILE_BYTES;
|
|
8
8
|
export const FILE_CHUNK_BYTES = 256 * 1024;
|
|
9
9
|
|
|
10
10
|
function validName(value) {
|
|
@@ -63,8 +63,8 @@ export function createFileUploadSession(root) {
|
|
|
63
63
|
// and commit after a direct connection has been replaced.
|
|
64
64
|
if (relayed) {
|
|
65
65
|
const originals = [...files.values()].filter(file => !file.previewOf);
|
|
66
|
-
if (originals.some(file => file.size > MAX_FILE_BYTES)) throw new Error('服务器转发仅支持单个文件不超过
|
|
67
|
-
if (originals.reduce((sum, file) => sum + file.size, 0) > MAX_TOTAL_BYTES) throw new Error('服务器转发仅支持每批合计不超过
|
|
66
|
+
if (originals.some(file => file.size > MAX_FILE_BYTES)) throw new Error('服务器转发仅支持单个文件不超过 50 MiB,请使用局域网或 RTC 直连');
|
|
67
|
+
if (originals.reduce((sum, file) => sum + file.size, 0) > MAX_TOTAL_BYTES) throw new Error('服务器转发仅支持每批合计不超过 50 MiB,请使用局域网或 RTC 直连');
|
|
68
68
|
}
|
|
69
69
|
if (message.type === 'commit') {
|
|
70
70
|
if (upload) throw new Error('文件尚未上传完成');
|
|
@@ -96,11 +96,11 @@ export function createFileUploadSession(root) {
|
|
|
96
96
|
if (!Number.isSafeInteger(message.size) || message.size < 1) {
|
|
97
97
|
throw new Error('文件大小无效');
|
|
98
98
|
}
|
|
99
|
-
if (relayed && message.size > MAX_FILE_BYTES) throw new Error('服务器转发仅支持单个文件不超过
|
|
99
|
+
if (relayed && message.size > MAX_FILE_BYTES) throw new Error('服务器转发仅支持单个文件不超过 50 MiB,请使用局域网或 RTC 直连');
|
|
100
100
|
const parent = message.previewOf ? completed.get(message.previewOf) : null;
|
|
101
101
|
if (message.previewOf && (!parent || parent.preview || message.size > FILE_CHUNK_BYTES)) throw new Error('预览图关联无效或超过 256 KiB');
|
|
102
102
|
if (!parent && completed.size >= MAX_FILE_COUNT) throw new Error('每条消息最多 4 个文件');
|
|
103
|
-
if (!parent && relayed && completedBytes + message.size > MAX_TOTAL_BYTES) throw new Error('服务器转发仅支持每批合计不超过
|
|
103
|
+
if (!parent && relayed && completedBytes + message.size > MAX_TOTAL_BYTES) throw new Error('服务器转发仅支持每批合计不超过 50 MiB,请使用局域网或 RTC 直连');
|
|
104
104
|
const id = crypto.randomUUID();
|
|
105
105
|
await fs.mkdir(directory, { recursive: true });
|
|
106
106
|
const partial = path.join(directory, `.upload-${id}`);
|
|
@@ -150,7 +150,7 @@ export function attachLanSocket(server, { token, dispatch, authorizeDevice = ()
|
|
|
150
150
|
json(status, body) { reply({ type: 'error', status, error: body?.error || '文件读取失败' }); },
|
|
151
151
|
filePart(metadata, data) {
|
|
152
152
|
if (stopped || ws.readyState !== WebSocket.OPEN) return;
|
|
153
|
-
if (fileRelay && metadata.size > FILE_READ_LIMIT) throw new Error('服务器转发仅支持下载不超过
|
|
153
|
+
if (fileRelay && metadata.size > FILE_READ_LIMIT) throw new Error('服务器转发仅支持下载不超过 50 MiB 的文件,请使用局域网或 RTC 直连');
|
|
154
154
|
if (!Buffer.isBuffer(data) || data.length > FILE_CHUNK_BYTES || ws.bufferedAmount > 1024 * 1024) throw new Error('文件接收过慢或分片无效');
|
|
155
155
|
reply({ type: 'part', ...metadata, length: data.length });
|
|
156
156
|
ws.send(data);
|