@wooksjs/http-static 0.6.0 → 0.6.1
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/index.cjs +5 -6
- package/dist/index.mjs +4 -4
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
//#region rolldown:runtime
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
@@ -1258,12 +1257,12 @@ async function serveFile(filePath, options = {}) {
|
|
|
1258
1257
|
}
|
|
1259
1258
|
setHeader("etag", etag);
|
|
1260
1259
|
setHeader("last-modified", lastModified.toUTCString());
|
|
1261
|
-
if (options.cacheControl !==
|
|
1260
|
+
if (options.cacheControl !== void 0) setCacheControl(options.cacheControl);
|
|
1262
1261
|
if (options.expires) setExpires(options.expires);
|
|
1263
1262
|
if (options.pragmaNoCache) setPragmaNoCache(options.pragmaNoCache);
|
|
1264
1263
|
if (fileStats.isDirectory()) {
|
|
1265
1264
|
if (options.listDirectory) return listDirectory(normalizedPath);
|
|
1266
|
-
else if (options.index) {
|
|
1265
|
+
else if (options.index) {
|
|
1267
1266
|
if (!filePath.endsWith("/") && url && !url.endsWith("/")) return new __wooksjs_event_http.BaseHttpResponse().setStatus(302).setHeader("location", `${url}/`);
|
|
1268
1267
|
return serveFile(path.default.join(filePath, options.index), {
|
|
1269
1268
|
...options,
|
|
@@ -1305,7 +1304,7 @@ else if (options.index) {
|
|
|
1305
1304
|
return method === "HEAD" ? "" : (0, fs.createReadStream)(normalizedPath, range ? {
|
|
1306
1305
|
start,
|
|
1307
1306
|
end
|
|
1308
|
-
} :
|
|
1307
|
+
} : void 0);
|
|
1309
1308
|
}
|
|
1310
1309
|
function isNotModified(etag, lastModified, clientEtag, clientLM) {
|
|
1311
1310
|
if (clientEtag) {
|
|
@@ -1343,8 +1342,8 @@ async function listDirectory(dirPath) {
|
|
|
1343
1342
|
});
|
|
1344
1343
|
setContentType("text/html");
|
|
1345
1344
|
const styles = "<style type=\"text/css\">\nhtml { font-family: monospace }\nspan { padding: 0px 2px }\n.text { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }\n.icon { width: 20px; display: inline-block; text-align: center; }\n.name { width: 250px; display: inline-block; }\n.size { width: 80px; display: inline-block; color: grey; text-align: right; }\n.date { width: 200px; display: inline-block; color: grey; text-align: right; }\n\n</style>";
|
|
1346
|
-
return `<html><head><title>Dir</title> ${styles} </head><body><ul>${detailedList.map((d) => `<li> <span class="icon">${d.dir ? "📁" : "🗎"}</span
|
|
1345
|
+
return `<html><head><title>Dir</title> ${styles} </head><body><ul>${detailedList.map((d) => `<li> <span class="icon">${d.dir ? "📁" : "🗎"}</span><a href="${path.default.join(url || "", d.name)}"><span class="name text">${d.name}</span></a><span class="size text">${d.size && (d.size > 1e4 ? `${Math.round(d.size / 1024 / 1024).toString()}Mb` : `${Math.round(d.size / 1024).toString()}Kb`) || ""}</span><span class="date text">${d.mtime && d.mtime.toISOString() || ""}</li>`).join("\n")}</ul></body></html>`;
|
|
1347
1346
|
}
|
|
1348
1347
|
|
|
1349
1348
|
//#endregion
|
|
1350
|
-
exports.serveFile = serveFile
|
|
1349
|
+
exports.serveFile = serveFile;
|
package/dist/index.mjs
CHANGED
|
@@ -1234,12 +1234,12 @@ async function serveFile(filePath, options = {}) {
|
|
|
1234
1234
|
}
|
|
1235
1235
|
setHeader("etag", etag);
|
|
1236
1236
|
setHeader("last-modified", lastModified.toUTCString());
|
|
1237
|
-
if (options.cacheControl !==
|
|
1237
|
+
if (options.cacheControl !== void 0) setCacheControl(options.cacheControl);
|
|
1238
1238
|
if (options.expires) setExpires(options.expires);
|
|
1239
1239
|
if (options.pragmaNoCache) setPragmaNoCache(options.pragmaNoCache);
|
|
1240
1240
|
if (fileStats.isDirectory()) {
|
|
1241
1241
|
if (options.listDirectory) return listDirectory(normalizedPath);
|
|
1242
|
-
else if (options.index) {
|
|
1242
|
+
else if (options.index) {
|
|
1243
1243
|
if (!filePath.endsWith("/") && url && !url.endsWith("/")) return new BaseHttpResponse().setStatus(302).setHeader("location", `${url}/`);
|
|
1244
1244
|
return serveFile(path.join(filePath, options.index), {
|
|
1245
1245
|
...options,
|
|
@@ -1281,7 +1281,7 @@ else if (options.index) {
|
|
|
1281
1281
|
return method === "HEAD" ? "" : createReadStream(normalizedPath, range ? {
|
|
1282
1282
|
start,
|
|
1283
1283
|
end
|
|
1284
|
-
} :
|
|
1284
|
+
} : void 0);
|
|
1285
1285
|
}
|
|
1286
1286
|
function isNotModified(etag, lastModified, clientEtag, clientLM) {
|
|
1287
1287
|
if (clientEtag) {
|
|
@@ -1319,7 +1319,7 @@ async function listDirectory(dirPath) {
|
|
|
1319
1319
|
});
|
|
1320
1320
|
setContentType("text/html");
|
|
1321
1321
|
const styles = "<style type=\"text/css\">\nhtml { font-family: monospace }\nspan { padding: 0px 2px }\n.text { text-overflow: ellipsis; overflow: hidden; white-space: nowrap; }\n.icon { width: 20px; display: inline-block; text-align: center; }\n.name { width: 250px; display: inline-block; }\n.size { width: 80px; display: inline-block; color: grey; text-align: right; }\n.date { width: 200px; display: inline-block; color: grey; text-align: right; }\n\n</style>";
|
|
1322
|
-
return `<html><head><title>Dir</title> ${styles} </head><body><ul>${detailedList.map((d) => `<li> <span class="icon">${d.dir ? "📁" : "🗎"}</span
|
|
1322
|
+
return `<html><head><title>Dir</title> ${styles} </head><body><ul>${detailedList.map((d) => `<li> <span class="icon">${d.dir ? "📁" : "🗎"}</span><a href="${path.join(url || "", d.name)}"><span class="name text">${d.name}</span></a><span class="size text">${d.size && (d.size > 1e4 ? `${Math.round(d.size / 1024 / 1024).toString()}Mb` : `${Math.round(d.size / 1024).toString()}Kb`) || ""}</span><span class="date text">${d.mtime && d.mtime.toISOString() || ""}</li>`).join("\n")}</ul></body></html>`;
|
|
1323
1323
|
}
|
|
1324
1324
|
|
|
1325
1325
|
//#endregion
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wooksjs/http-static",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"description": "@wooksjs/http-static",
|
|
5
5
|
"main": "dist/index.cjs",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -39,12 +39,12 @@
|
|
|
39
39
|
"url": "https://github.com/wooksjs/wooksjs/issues"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@wooksjs/event-http": "^0.6.
|
|
42
|
+
"@wooksjs/event-http": "^0.6.1"
|
|
43
43
|
},
|
|
44
44
|
"homepage": "https://github.com/wooksjs/wooksjs/tree/main/packages/http-static#readme",
|
|
45
45
|
"devDependencies": {
|
|
46
|
-
"typescript": "^5.
|
|
47
|
-
"vitest": "^2.
|
|
46
|
+
"typescript": "^5.8.3",
|
|
47
|
+
"vitest": "^3.2.4"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rolldown -c ../../rolldown.config.mjs"
|