minimalistic-server 0.0.20 → 0.0.21
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/index.mjs +13 -3
- package/package.json +1 -1
package/index.mjs
CHANGED
|
@@ -5,6 +5,8 @@ import * as fs from "node:fs/promises";
|
|
|
5
5
|
const servers = new Map();
|
|
6
6
|
const keepAliveTimeout = 20000;
|
|
7
7
|
|
|
8
|
+
let currentFsPromiseModule = fs;
|
|
9
|
+
|
|
8
10
|
function safePrint(data, isError = false) {
|
|
9
11
|
try {
|
|
10
12
|
if (isError) {
|
|
@@ -710,6 +712,14 @@ const mimeTypes = {
|
|
|
710
712
|
"rss": "application/rss+xml"
|
|
711
713
|
};
|
|
712
714
|
|
|
715
|
+
export function getServerFsPromiseModule() {
|
|
716
|
+
return currentFsPromiseModule;
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
export function setServerFsPromiseModule(fsPromiseModule) {
|
|
720
|
+
currentFsPromiseModule = fsPromiseModule;
|
|
721
|
+
}
|
|
722
|
+
|
|
713
723
|
export class UploadedFile {
|
|
714
724
|
#content;
|
|
715
725
|
#contentType;
|
|
@@ -1349,7 +1359,7 @@ export class FileResponse extends Response {
|
|
|
1349
1359
|
${urlPath ? `<a href="/${parentUrlPath}">Up</a><hr>` : ''}
|
|
1350
1360
|
`;
|
|
1351
1361
|
|
|
1352
|
-
const files = await
|
|
1362
|
+
const files = await currentFsPromiseModule.readdir(filePath);
|
|
1353
1363
|
let counter = 0;
|
|
1354
1364
|
|
|
1355
1365
|
for (const file of files) {
|
|
@@ -1381,7 +1391,7 @@ ${urlPath ? `<a href="/${parentUrlPath}">Up</a><hr>` : ''}
|
|
|
1381
1391
|
const requestedPosition = fragmentRequest?.offset ?? 0;
|
|
1382
1392
|
const requestedSize = fragmentRequest?.size ?? data.size;
|
|
1383
1393
|
|
|
1384
|
-
filehandle = await
|
|
1394
|
+
filehandle = await currentFsPromiseModule.open(this.#filePath, 'r');
|
|
1385
1395
|
|
|
1386
1396
|
for (let offset = 0; offset < requestedSize; offset += this.#maxChunkSize) {
|
|
1387
1397
|
const size = Math.min(this.#maxChunkSize, requestedSize - offset);
|
|
@@ -1399,7 +1409,7 @@ ${urlPath ? `<a href="/${parentUrlPath}">Up</a><hr>` : ''}
|
|
|
1399
1409
|
let filehandle;
|
|
1400
1410
|
|
|
1401
1411
|
try {
|
|
1402
|
-
filehandle = await
|
|
1412
|
+
filehandle = await currentFsPromiseModule.open(this.#filePath, 'r');
|
|
1403
1413
|
const stat = await filehandle.stat();
|
|
1404
1414
|
const size = stat.size;
|
|
1405
1415
|
const readAsDirectory = stat.isDirectory() && this.#urlPathForDirectory !== null;
|