koa-files 4.1.0 → 4.1.2

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 CHANGED
@@ -26,7 +26,7 @@ interface Headers {
26
26
  }
27
27
 
28
28
  interface IgnoreFunction {
29
- (path: string): boolean | Promise<boolean>;
29
+ (path: string): Promise<boolean> | boolean;
30
30
  }
31
31
 
32
32
  interface HighWaterMarkFunction {
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
package/cjs/Service.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
@@ -41,10 +41,11 @@ class Service {
41
41
  constructor(root, options = {}) {
42
42
  var _a;
43
43
  this.root = path.unixify(path$1.resolve(root));
44
- const { ignore, highWaterMark = 65536 } = options;
44
+ const { ignore, headers, highWaterMark = 65536 } = options;
45
45
  this.options = Object.assign(Object.assign({}, options), {
46
46
  fs: (_a = options.fs) !== null && _a !== void 0 ? _a : fs__default.default,
47
47
  ignore: type.isFunction(ignore) ? ignore : () => false,
48
+ headers: type.isFunction(headers) ? headers : () => headers,
48
49
  highWaterMark: type.isFunction(highWaterMark) ? highWaterMark : () => highWaterMark
49
50
  });
50
51
  }
@@ -58,21 +59,15 @@ class Service {
58
59
  */
59
60
  async setupHeaders({ response }, path, stats) {
60
61
  const { options } = this;
61
- const { headers } = options;
62
62
  // Set status.
63
63
  response.status = 200;
64
64
  // Set Content-Type.
65
65
  response.type = path$1.extname(path);
66
- // Set headers.
66
+ // Get headers.
67
+ const headers = await options.headers(path, stats);
68
+ // If headers not empty, set headers.
67
69
  if (headers) {
68
- if (type.isFunction(headers)) {
69
- const fields = await headers(path, stats);
70
- if (fields) {
71
- response.set(fields);
72
- }
73
- } else {
74
- response.set(headers);
75
- }
70
+ response.set(headers);
76
71
  }
77
72
  // Accept-Ranges.
78
73
  if (options.acceptRanges === false) {
package/cjs/Service.d.cts CHANGED
@@ -8,7 +8,7 @@ interface Headers {
8
8
  [key: string]: string | string[];
9
9
  }
10
10
  interface IgnoreFunction {
11
- (path: string): boolean | Promise<boolean>;
11
+ (path: string): Promise<boolean> | boolean;
12
12
  }
13
13
  interface HighWaterMarkFunction {
14
14
  (path: string, stats: Stats): Promise<number> | number;
package/cjs/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
package/cjs/utils/fs.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
package/esm/ReadStream.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
package/esm/Service.d.ts CHANGED
@@ -8,7 +8,7 @@ interface Headers {
8
8
  [key: string]: string | string[];
9
9
  }
10
10
  interface IgnoreFunction {
11
- (path: string): boolean | Promise<boolean>;
11
+ (path: string): Promise<boolean> | boolean;
12
12
  }
13
13
  interface HighWaterMarkFunction {
14
14
  (path: string, stats: Stats): Promise<number> | number;
package/esm/Service.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
@@ -32,10 +32,11 @@ class Service {
32
32
  constructor(root, options = {}) {
33
33
  var _a;
34
34
  this.root = unixify(resolve(root));
35
- const { ignore, highWaterMark = 65536 } = options;
35
+ const { ignore, headers, highWaterMark = 65536 } = options;
36
36
  this.options = Object.assign(Object.assign({}, options), {
37
37
  fs: (_a = options.fs) !== null && _a !== void 0 ? _a : fs,
38
38
  ignore: isFunction(ignore) ? ignore : () => false,
39
+ headers: isFunction(headers) ? headers : () => headers,
39
40
  highWaterMark: isFunction(highWaterMark) ? highWaterMark : () => highWaterMark
40
41
  });
41
42
  }
@@ -49,21 +50,15 @@ class Service {
49
50
  */
50
51
  async setupHeaders({ response }, path, stats) {
51
52
  const { options } = this;
52
- const { headers } = options;
53
53
  // Set status.
54
54
  response.status = 200;
55
55
  // Set Content-Type.
56
56
  response.type = extname(path);
57
- // Set headers.
57
+ // Get headers.
58
+ const headers = await options.headers(path, stats);
59
+ // If headers not empty, set headers.
58
60
  if (headers) {
59
- if (isFunction(headers)) {
60
- const fields = await headers(path, stats);
61
- if (fields) {
62
- response.set(fields);
63
- }
64
- } else {
65
- response.set(headers);
66
- }
61
+ response.set(headers);
67
62
  }
68
63
  // Accept-Ranges.
69
64
  if (options.acceptRanges === false) {
package/esm/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
package/esm/utils/fs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
package/esm/utils/hash.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
package/esm/utils/http.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
package/esm/utils/path.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
package/esm/utils/type.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @package koa-files
3
3
  * @license MIT
4
- * @version 4.1.0
4
+ * @version 4.1.2
5
5
  * @author nuintun <nuintun@qq.com>
6
6
  * @description A static files serving middleware for koa.
7
7
  * @see https://github.com/nuintun/koa-files#readme
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koa-files",
3
- "version": "4.1.0",
3
+ "version": "4.1.2",
4
4
  "description": "A static files serving middleware for koa.",
5
5
  "type": "module",
6
6
  "main": "cjs/index.cjs",
@@ -50,16 +50,16 @@
50
50
  "devDependencies": {
51
51
  "@rollup/plugin-typescript": "^12.1.4",
52
52
  "@types/etag": "^1.8.4",
53
- "@types/koa": "^2.15.0",
53
+ "@types/koa": "^3.0.0",
54
54
  "@types/node": "^24.1.0",
55
55
  "@types/range-parser": "^1.2.7",
56
- "dts-paths": "^1.1.10",
56
+ "dts-paths": "^1.1.11",
57
57
  "koa": "^3.0.1",
58
58
  "magic-string": "^0.30.17",
59
59
  "prettier": "^3.6.2",
60
60
  "rimraf": "^6.0.1",
61
- "rollup": "^4.46.1",
62
- "typescript": "^5.8.3"
61
+ "rollup": "^4.46.2",
62
+ "typescript": "^5.9.2"
63
63
  },
64
64
  "peerDependencies": {
65
65
  "koa": ">=2.0.0"