@juzi/file-box 1.7.4 → 1.7.6
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/README.md +5 -1
- package/dist/cjs/src/config.d.ts +1 -0
- package/dist/cjs/src/config.d.ts.map +1 -1
- package/dist/cjs/src/config.js +2 -1
- package/dist/cjs/src/config.js.map +1 -1
- package/dist/cjs/src/file-box.d.ts +2 -2
- package/dist/cjs/src/file-box.d.ts.map +1 -1
- package/dist/cjs/src/misc.d.ts +1 -1
- package/dist/cjs/src/misc.d.ts.map +1 -1
- package/dist/cjs/src/misc.js +88 -190
- package/dist/cjs/src/misc.js.map +1 -1
- package/dist/cjs/src/version.d.ts +3 -2
- package/dist/cjs/src/version.d.ts.map +1 -1
- package/dist/cjs/src/version.js +5 -4
- package/dist/cjs/src/version.js.map +1 -1
- package/dist/esm/src/config.d.ts +1 -0
- package/dist/esm/src/config.d.ts.map +1 -1
- package/dist/esm/src/config.js +1 -0
- package/dist/esm/src/config.js.map +1 -1
- package/dist/esm/src/file-box.d.ts +2 -2
- package/dist/esm/src/file-box.d.ts.map +1 -1
- package/dist/esm/src/misc.d.ts +1 -1
- package/dist/esm/src/misc.d.ts.map +1 -1
- package/dist/esm/src/misc.js +89 -191
- package/dist/esm/src/misc.js.map +1 -1
- package/dist/esm/src/version.d.ts +3 -2
- package/dist/esm/src/version.d.ts.map +1 -1
- package/dist/esm/src/version.js +3 -2
- package/dist/esm/src/version.js.map +1 -1
- package/package.json +6 -3
- package/src/config.ts +6 -1
- package/src/misc.ts +106 -228
- package/src/version.ts +4 -2
package/dist/esm/src/misc.js
CHANGED
|
@@ -1,8 +1,22 @@
|
|
|
1
|
+
import assert from 'assert';
|
|
2
|
+
import { randomUUID } from 'crypto';
|
|
3
|
+
import { once } from 'events';
|
|
4
|
+
import { createReadStream, createWriteStream } from 'fs';
|
|
5
|
+
import { rm } from 'fs/promises';
|
|
1
6
|
import http from 'http';
|
|
2
7
|
import https from 'https';
|
|
8
|
+
import { tmpdir } from 'os';
|
|
9
|
+
import { join } from 'path';
|
|
3
10
|
import { URL } from 'url';
|
|
4
|
-
import {
|
|
5
|
-
|
|
11
|
+
import { HTTP_CHUNK_SIZE, HTTP_TIMEOUT, NO_SLICE_DOWN } from './config.js';
|
|
12
|
+
const protocolMap = {
|
|
13
|
+
'http:': { agent: http.globalAgent, request: http.request },
|
|
14
|
+
'https:': { agent: https.globalAgent, request: https.request },
|
|
15
|
+
};
|
|
16
|
+
function getProtocol(protocol) {
|
|
17
|
+
assert(protocolMap[protocol], new Error('unknown protocol: ' + protocol));
|
|
18
|
+
return protocolMap[protocol];
|
|
19
|
+
}
|
|
6
20
|
export function dataUrlToBase64(dataUrl) {
|
|
7
21
|
const dataList = dataUrl.split(',');
|
|
8
22
|
return dataList[dataList.length - 1];
|
|
@@ -20,7 +34,10 @@ export async function httpHeadHeader(url) {
|
|
|
20
34
|
if (REDIRECT_TTL-- <= 0) {
|
|
21
35
|
throw new Error(`ttl expired! too many(>${REDIRECT_TTL}) 302 redirection.`);
|
|
22
36
|
}
|
|
23
|
-
const res = await
|
|
37
|
+
const res = await fetch(url, {
|
|
38
|
+
method: 'HEAD',
|
|
39
|
+
});
|
|
40
|
+
res.destroy();
|
|
24
41
|
if (!/^3/.test(String(res.statusCode))) {
|
|
25
42
|
if (originUrl !== url) {
|
|
26
43
|
res.headers.location = url;
|
|
@@ -33,37 +50,6 @@ export async function httpHeadHeader(url) {
|
|
|
33
50
|
}
|
|
34
51
|
url = res.headers.location;
|
|
35
52
|
}
|
|
36
|
-
async function _headHeader(destUrl) {
|
|
37
|
-
const parsedUrl = new URL(destUrl);
|
|
38
|
-
const options = {
|
|
39
|
-
method: 'HEAD',
|
|
40
|
-
// method : 'GET',
|
|
41
|
-
};
|
|
42
|
-
let request;
|
|
43
|
-
if (parsedUrl.protocol === 'https:') {
|
|
44
|
-
request = https.request;
|
|
45
|
-
}
|
|
46
|
-
else if (parsedUrl.protocol === 'http:') {
|
|
47
|
-
request = http.request;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
throw new Error('unknown protocol: ' + parsedUrl.protocol);
|
|
51
|
-
}
|
|
52
|
-
return new Promise((resolve, reject) => {
|
|
53
|
-
let res;
|
|
54
|
-
const req = request(parsedUrl, options, (response) => {
|
|
55
|
-
res = response;
|
|
56
|
-
resolve(res);
|
|
57
|
-
})
|
|
58
|
-
.on('error', reject)
|
|
59
|
-
.setTimeout(HTTP_TIMEOUT, () => {
|
|
60
|
-
const e = new Error(`FileBox: Http request timeout (${HTTP_TIMEOUT})!`);
|
|
61
|
-
req.emit('error', e);
|
|
62
|
-
req.destroy();
|
|
63
|
-
})
|
|
64
|
-
.end();
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
53
|
}
|
|
68
54
|
export function httpHeaderToFileName(headers) {
|
|
69
55
|
const contentDisposition = headers['content-disposition'];
|
|
@@ -81,181 +67,93 @@ export async function httpStream(url, headers = {}) {
|
|
|
81
67
|
const headHeaders = await httpHeadHeader(url);
|
|
82
68
|
if (headHeaders.location) {
|
|
83
69
|
url = headHeaders.location;
|
|
70
|
+
const { protocol } = new URL(url);
|
|
71
|
+
getProtocol(protocol);
|
|
84
72
|
}
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
let get;
|
|
89
|
-
if (!protocol) {
|
|
90
|
-
throw new Error('protocol is empty');
|
|
91
|
-
}
|
|
92
|
-
if (protocol.match(/^https:/i)) {
|
|
93
|
-
get = https.get;
|
|
94
|
-
options.agent = https.globalAgent;
|
|
95
|
-
}
|
|
96
|
-
else if (protocol.match(/^http:/i)) {
|
|
97
|
-
get = http.get;
|
|
98
|
-
options.agent = http.globalAgent;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
throw new Error('protocol unknown: ' + protocol);
|
|
102
|
-
}
|
|
103
|
-
options.headers = {
|
|
104
|
-
...headers,
|
|
73
|
+
const options = {
|
|
74
|
+
headers: { ...headers },
|
|
75
|
+
method: 'GET',
|
|
105
76
|
};
|
|
106
77
|
const fileSize = Number(headHeaders['content-length']);
|
|
107
|
-
if (headHeaders['accept-ranges'] === 'bytes' && fileSize > HTTP_CHUNK_SIZE) {
|
|
108
|
-
return await downloadFileInChunks(
|
|
78
|
+
if (!NO_SLICE_DOWN && headHeaders['accept-ranges'] === 'bytes' && fileSize > HTTP_CHUNK_SIZE) {
|
|
79
|
+
return await downloadFileInChunks(url, options, fileSize, HTTP_CHUNK_SIZE);
|
|
109
80
|
}
|
|
110
81
|
else {
|
|
111
|
-
return await
|
|
82
|
+
return await fetch(url, options);
|
|
112
83
|
}
|
|
113
84
|
}
|
|
114
|
-
async function
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
req.destroy();
|
|
130
|
-
})
|
|
131
|
-
.end();
|
|
132
|
-
});
|
|
85
|
+
async function fetch(url, options) {
|
|
86
|
+
const { protocol } = new URL(url);
|
|
87
|
+
const { request, agent } = getProtocol(protocol);
|
|
88
|
+
const opts = {
|
|
89
|
+
agent,
|
|
90
|
+
...options,
|
|
91
|
+
};
|
|
92
|
+
const req = request(url, opts)
|
|
93
|
+
.setTimeout(HTTP_TIMEOUT)
|
|
94
|
+
.once('timeout', () => {
|
|
95
|
+
req.destroy(new Error(`FileBox: Http request timeout (${HTTP_TIMEOUT})!`));
|
|
96
|
+
})
|
|
97
|
+
.end();
|
|
98
|
+
const [res] = (await once(req, 'response'));
|
|
99
|
+
return res;
|
|
133
100
|
}
|
|
134
|
-
async function downloadFileInChunks(
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
101
|
+
async function downloadFileInChunks(url, options, fileSize, chunkSize = HTTP_CHUNK_SIZE) {
|
|
102
|
+
const tmpFile = join(tmpdir(), `filebox-${randomUUID()}`);
|
|
103
|
+
const writeStream = createWriteStream(tmpFile);
|
|
104
|
+
const allowStatusCode = [200, 206];
|
|
105
|
+
const requestBaseOptions = {
|
|
106
|
+
headers: {},
|
|
107
|
+
...options,
|
|
108
|
+
timeout: HTTP_TIMEOUT,
|
|
141
109
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
let
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
const start = i * chunkSize;
|
|
150
|
-
const end = Math.min((i + 1) * chunkSize - 1, fileSize - 1);
|
|
110
|
+
let chunkSeq = 0;
|
|
111
|
+
let start = 0;
|
|
112
|
+
let end = 0;
|
|
113
|
+
let downSize = 0;
|
|
114
|
+
let retries = 3;
|
|
115
|
+
while (downSize < fileSize) {
|
|
116
|
+
end = Math.min(start + chunkSize, fileSize - 1);
|
|
151
117
|
const range = `bytes=${start}-${end}`;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
stream.destroy(new Error('Signal aborted.'));
|
|
155
|
-
return;
|
|
156
|
-
}
|
|
157
|
-
const requestOptions = {
|
|
158
|
-
...options,
|
|
159
|
-
signal: ac.signal,
|
|
160
|
-
timeout: HTTP_TIMEOUT,
|
|
161
|
-
};
|
|
162
|
-
if (!requestOptions.headers) {
|
|
163
|
-
requestOptions.headers = {};
|
|
164
|
-
}
|
|
118
|
+
const requestOptions = Object.assign({}, requestBaseOptions);
|
|
119
|
+
assert(requestOptions.headers, 'Errors that should not happen: Invalid headers');
|
|
165
120
|
requestOptions.headers['Range'] = range;
|
|
166
121
|
try {
|
|
167
|
-
const
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (chunk.destroyed) {
|
|
175
|
-
throw new Error('chunk stream destroyed');
|
|
176
|
-
}
|
|
177
|
-
const buf = await streamToBuffer(chunk);
|
|
178
|
-
stream.push(buf);
|
|
179
|
-
chunksDownloaded++;
|
|
180
|
-
dataTotalSize += buf.length;
|
|
181
|
-
if (chunksDownloaded === chunksCount || dataTotalSize >= fileSize) {
|
|
182
|
-
stream.push(null);
|
|
122
|
+
const res = await fetch(url, options);
|
|
123
|
+
assert(allowStatusCode.includes(res.statusCode ?? 0), `Request failed with status code ${res.statusCode}`);
|
|
124
|
+
assert(Number(res.headers['content-length']) > 0, 'Server returned 0 bytes of data');
|
|
125
|
+
for await (const chunk of res) {
|
|
126
|
+
assert(Buffer.isBuffer(chunk));
|
|
127
|
+
downSize += chunk.length;
|
|
128
|
+
writeStream.write(chunk);
|
|
183
129
|
}
|
|
130
|
+
res.destroy();
|
|
184
131
|
}
|
|
185
|
-
catch (
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
132
|
+
catch (error) {
|
|
133
|
+
const err = error;
|
|
134
|
+
if (--retries <= 0) {
|
|
135
|
+
void rm(tmpFile, { force: true });
|
|
136
|
+
writeStream.close();
|
|
137
|
+
throw new Error(`Download file with chunk failed! ${err.message}`, { cause: err });
|
|
191
138
|
}
|
|
192
139
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
void doDownloadAllChunks().catch((e) => {
|
|
203
|
-
stream.emit('error', e);
|
|
204
|
-
});
|
|
205
|
-
return stream;
|
|
206
|
-
}
|
|
207
|
-
async function downloadChunk(get, url, requestOptions, retries) {
|
|
208
|
-
return new Promise((resolve, reject) => {
|
|
209
|
-
const doRequest = (attempt) => {
|
|
210
|
-
let resolved = false;
|
|
211
|
-
const req = get(url, requestOptions, (res) => {
|
|
212
|
-
const statusCode = res.statusCode ?? 0;
|
|
213
|
-
// console.info('downloadChunk(%d) statusCode: %d rsp.headers: %o', attempt, statusCode, res.headers)
|
|
214
|
-
if (statusCode < 200 || statusCode >= 300) {
|
|
215
|
-
if (attempt < retries) {
|
|
216
|
-
void doRequest(attempt + 1);
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
reject(new Error(`Request failed with status code ${res.statusCode}`));
|
|
220
|
-
}
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const stream = pipeline(res, new PassThrough(), () => { });
|
|
224
|
-
resolve(stream);
|
|
225
|
-
resolved = true;
|
|
226
|
-
});
|
|
227
|
-
req
|
|
228
|
-
.once('error', (err) => {
|
|
229
|
-
if (resolved) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
// console.error('downloadChunk(%d) req error:', attempt, err)
|
|
233
|
-
if (attempt < retries) {
|
|
234
|
-
void doRequest(attempt + 1);
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
reject(err);
|
|
238
|
-
}
|
|
239
|
-
})
|
|
240
|
-
.setTimeout(HTTP_TIMEOUT, () => {
|
|
241
|
-
const e = new Error(`FileBox: Http request timeout (${HTTP_TIMEOUT})!`);
|
|
242
|
-
req.emit('error', e);
|
|
243
|
-
req.destroy();
|
|
244
|
-
})
|
|
245
|
-
.end();
|
|
246
|
-
};
|
|
247
|
-
void doRequest(0);
|
|
140
|
+
chunkSeq++;
|
|
141
|
+
start = downSize;
|
|
142
|
+
}
|
|
143
|
+
writeStream.close();
|
|
144
|
+
const readStream = createReadStream(tmpFile);
|
|
145
|
+
readStream
|
|
146
|
+
.once('end', () => readStream.close())
|
|
147
|
+
.once('close', () => {
|
|
148
|
+
void rm(tmpFile, { force: true });
|
|
248
149
|
});
|
|
150
|
+
return readStream;
|
|
249
151
|
}
|
|
250
152
|
export async function streamToBuffer(stream) {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
resolve(fullBuffer);
|
|
257
|
-
});
|
|
258
|
-
stream.on('data', (buffer) => bufferList.push(buffer));
|
|
259
|
-
});
|
|
153
|
+
const chunks = [];
|
|
154
|
+
for await (const chunk of stream) {
|
|
155
|
+
chunks.push(chunk);
|
|
156
|
+
}
|
|
157
|
+
return Buffer.concat(chunks);
|
|
260
158
|
}
|
|
261
159
|
//# sourceMappingURL=misc.js.map
|
package/dist/esm/src/misc.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../../src/misc.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"misc.js","sourceRoot":"","sources":["../../../src/misc.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACnC,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAA;AAC7B,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,IAAI,CAAA;AACxD,OAAO,EAAE,EAAE,EAAE,MAAM,aAAa,CAAA;AAChC,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAA;AAE3B,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,CAAA;AAEzB,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAE1E,MAAM,WAAW,GAEb;IACF,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE;IAC3D,QAAQ,EAAE,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE;CAC/D,CAAA;AAED,SAAS,WAAW,CAAE,QAAgB;IACpC,MAAM,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,IAAI,KAAK,CAAC,oBAAoB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K,EAAE,CAAA;IAEnB,MAAM,UAAU,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAA;IAC5C,UAAU;SACP,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;SACrC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;QAClB,KAAK,EAAE,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;IACnC,CAAC,CAAC,CAAA;IACJ,OAAO,UAAU,CAAA;AACnB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAAE,MAAgB;IACpD,MAAM,MAAM,GAAa,EAAE,CAAA;IAC3B,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,MAAM,EAAE;QAChC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;KACnB;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;AAC9B,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This file
|
|
2
|
+
* This file will be overwrite when we publish NPM module
|
|
3
|
+
* by scripts/generate_version.ts
|
|
3
4
|
*/
|
|
4
|
-
export declare const VERSION
|
|
5
|
+
export declare const VERSION = "0.0.0";
|
|
5
6
|
//# sourceMappingURL=version.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/version.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,eAAO,MAAM,OAAO,UAAU,CAAA"}
|
package/dist/esm/src/version.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* This file
|
|
2
|
+
* This file will be overwrite when we publish NPM module
|
|
3
|
+
* by scripts/generate_version.ts
|
|
3
4
|
*/
|
|
4
|
-
export const VERSION = '
|
|
5
|
+
export const VERSION = '0.0.0';
|
|
5
6
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/version.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../../src/version.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@juzi/file-box",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.6",
|
|
4
4
|
"description": "Pack a File into Box for easy move/transfer between servers no matter of where it is.(local path, remote url, or cloud storage)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -52,12 +52,15 @@
|
|
|
52
52
|
"@chatie/tsconfig": "^4.6.2",
|
|
53
53
|
"@types/isomorphic-fetch": "0.0.35",
|
|
54
54
|
"@types/mime": "^2.0.3",
|
|
55
|
+
"@types/node": "^18.18.7",
|
|
55
56
|
"@types/qrcode": "^1.4.1",
|
|
56
57
|
"@types/uuid": "^8.3.3",
|
|
58
|
+
"eslint-plugin-n": "^16.2.0",
|
|
57
59
|
"gts": "^3.1.0",
|
|
58
60
|
"pkg-jq": "^0.2.11",
|
|
59
61
|
"read-pkg-up": "^8.0.0",
|
|
60
|
-
"reflect-metadata": "^0.1.13"
|
|
62
|
+
"reflect-metadata": "^0.1.13",
|
|
63
|
+
"tap": "^16.3.9"
|
|
61
64
|
},
|
|
62
65
|
"dependencies": {
|
|
63
66
|
"brolog": "^1.14.2",
|
|
@@ -81,4 +84,4 @@
|
|
|
81
84
|
"pre-push": "npx git-scripts-pre-push"
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
|
-
}
|
|
87
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
/// <reference path="./typings.d.ts" />
|
|
2
2
|
export { VERSION } from './version.js'
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const HTTP_REQUEST_TIMEOUT = Number(process.env['FILEBOX_HTTP_REQUEST_TIMEOUT'])
|
|
5
|
+
|| 10 * 1000
|
|
6
|
+
|
|
7
|
+
export const HTTP_RESPONSE_TIMEOUT = Number(process.env['FILEBOX_HTTP_RESPONSE_TIMEOUT'] ?? process.env['FILEBOX_HTTP_TIMEOUT'])
|
|
5
8
|
|| 60 * 1000
|
|
6
9
|
|
|
10
|
+
export const NO_SLICE_DOWN = process.env['FILEBOX_NO_SLICE_DOWN'] === 'true'
|
|
11
|
+
|
|
7
12
|
export const HTTP_CHUNK_SIZE = Number(process.env['FILEBOX_HTTP_CHUNK_SIZE'])
|
|
8
13
|
|| 1024 * 512
|