@aomex/etag 0.0.27 → 1.0.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/CHANGELOG.md +7 -49
- package/LICENSE +1 -1
- package/dist/index.d.ts +10 -3
- package/dist/index.js +15 -11
- package/dist/index.js.map +1 -1
- package/package.json +8 -13
package/CHANGELOG.md
CHANGED
|
@@ -1,57 +1,15 @@
|
|
|
1
1
|
# @aomex/etag
|
|
2
2
|
|
|
3
|
-
##
|
|
3
|
+
## 1.0.1
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
- Updated dependencies [[`59cd3f9`](https://github.com/aomex/aomex/commit/59cd3f98a0b5648a972d6118ba21501130a9ee7e), [`90ca7d5`](https://github.com/aomex/aomex/commit/90ca7d5fc736b523c4fbf7949f64653428dc413c)]:
|
|
8
|
-
- @aomex/web@0.0.29
|
|
9
|
-
- @aomex/core@0.0.28
|
|
10
|
-
|
|
11
|
-
## 0.0.26
|
|
12
|
-
|
|
13
|
-
### Patch Changes
|
|
14
|
-
|
|
15
|
-
- Updated dependencies [[`00bafbb`](https://github.com/aomex/aomex/commit/00bafbbac2d32205b63a6bf561fb0a69c38a54bb), [`8becf8e`](https://github.com/aomex/aomex/commit/8becf8ee5ef86a5909783d0654e536db7be9bf5b), [`0776719`](https://github.com/aomex/aomex/commit/077671963401f1dafb5b03722899452d45df13fc), [`f996bf7`](https://github.com/aomex/aomex/commit/f996bf7e529e7751a5e858c579feed33f5f02d65)]:
|
|
16
|
-
- @aomex/core@0.0.27
|
|
17
|
-
- @aomex/web@0.0.28
|
|
18
|
-
|
|
19
|
-
## 0.0.25
|
|
20
|
-
|
|
21
|
-
### Patch Changes
|
|
22
|
-
|
|
23
|
-
- Updated dependencies [[`33c3c61`](https://github.com/aomex/aomex/commit/33c3c614be9f66077f7487350b88d2db854f5fc8), [`fbcea3d`](https://github.com/aomex/aomex/commit/fbcea3d68ff033e6861130c645c8e5ad7336193f)]:
|
|
24
|
-
- @aomex/web@0.0.27
|
|
25
|
-
- @aomex/core@0.0.26
|
|
26
|
-
|
|
27
|
-
## 0.0.24
|
|
28
|
-
|
|
29
|
-
### Patch Changes
|
|
30
|
-
|
|
31
|
-
- Updated dependencies [[`5ef2022`](https://github.com/aomex/aomex/commit/5ef202248b4320ff9076fbecb54379055cffb7db), [`8d9e9d8`](https://github.com/aomex/aomex/commit/8d9e9d8ece0bbcc7e1ac685702eacbfdfa145aa9), [`0e6ed2c`](https://github.com/aomex/aomex/commit/0e6ed2c611100dcfaafb6fb41357624ad9f5c67a)]:
|
|
32
|
-
- @aomex/web@0.0.26
|
|
33
|
-
- @aomex/core@0.0.25
|
|
34
|
-
|
|
35
|
-
## 0.0.23
|
|
36
|
-
|
|
37
|
-
### Patch Changes
|
|
38
|
-
|
|
39
|
-
- Updated dependencies [[`2ac62fd`](https://github.com/aomex/aomex/commit/2ac62fd28166a1d9dd60b3c6d5a6508a6f9ee82b), [`4258410`](https://github.com/aomex/aomex/commit/42584107ad9f7e34492ae1053fef83aa2d9d747a), [`4177cba`](https://github.com/aomex/aomex/commit/4177cba7877e38120842bd8d287eaed54e4926ca)]:
|
|
40
|
-
- @aomex/core@0.0.24
|
|
41
|
-
- @aomex/web@0.0.25
|
|
42
|
-
|
|
43
|
-
## 0.0.22
|
|
44
|
-
|
|
45
|
-
### Patch Changes
|
|
5
|
+
## 1.0.0
|
|
46
6
|
|
|
47
|
-
|
|
48
|
-
- @aomex/web@0.0.24
|
|
49
|
-
- @aomex/core@0.0.23
|
|
7
|
+
### Minor Changes
|
|
50
8
|
|
|
51
|
-
|
|
9
|
+
- [`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8) Thanks [@geekact](https://github.com/geekact)! - 重新制作
|
|
52
10
|
|
|
53
11
|
### Patch Changes
|
|
54
12
|
|
|
55
|
-
- Updated dependencies [[`
|
|
56
|
-
- @aomex/core@0.0
|
|
57
|
-
- @aomex/web@0.0
|
|
13
|
+
- Updated dependencies [[`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8)]:
|
|
14
|
+
- @aomex/core@1.0.0
|
|
15
|
+
- @aomex/web@1.0.0
|
package/LICENSE
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
-
import calculate from 'etag';
|
|
2
1
|
import { WebMiddleware } from '@aomex/web';
|
|
3
2
|
|
|
4
|
-
|
|
3
|
+
interface EtagOptions {
|
|
4
|
+
/**
|
|
5
|
+
* 是否增加 `W/` 前缀。默认:`false`
|
|
6
|
+
*
|
|
7
|
+
* 如果是ReadStream,则默认开启。
|
|
8
|
+
*/
|
|
9
|
+
weak?: boolean | undefined;
|
|
10
|
+
}
|
|
11
|
+
declare const etag: (options?: EtagOptions) => WebMiddleware;
|
|
5
12
|
|
|
6
|
-
export { etag };
|
|
13
|
+
export { type EtagOptions, etag };
|
package/dist/index.js
CHANGED
|
@@ -3,29 +3,33 @@ import { ReadStream } from "node:fs";
|
|
|
3
3
|
import { stat } from "node:fs/promises";
|
|
4
4
|
import calculate from "etag";
|
|
5
5
|
import { middleware } from "@aomex/core";
|
|
6
|
+
import { Stream } from "node:stream";
|
|
6
7
|
var etag = (options = {}) => {
|
|
7
8
|
return middleware.web(async (ctx, next) => {
|
|
8
9
|
await next();
|
|
9
10
|
const { response, request } = ctx;
|
|
10
|
-
const {
|
|
11
|
-
|
|
11
|
+
const { method } = request;
|
|
12
|
+
const { body, statusCode } = response;
|
|
13
|
+
if (statusCode < 200 || statusCode > 299)
|
|
14
|
+
return;
|
|
15
|
+
if (method !== "GET" && method !== "HEAD")
|
|
12
16
|
return;
|
|
13
|
-
if (
|
|
17
|
+
if (body === null || response.hasHeader("Etag"))
|
|
14
18
|
return;
|
|
15
19
|
let entity;
|
|
16
|
-
if (body instanceof
|
|
17
|
-
|
|
20
|
+
if (body instanceof Stream) {
|
|
21
|
+
if (body instanceof ReadStream) {
|
|
22
|
+
entity = await stat(body.path);
|
|
23
|
+
}
|
|
18
24
|
} else if (typeof body === "string" || Buffer.isBuffer(body)) {
|
|
19
25
|
entity = body;
|
|
20
26
|
} else {
|
|
21
27
|
entity = JSON.stringify(body);
|
|
22
28
|
}
|
|
23
|
-
if (entity)
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ctx.send(304, null);
|
|
28
|
-
}
|
|
29
|
+
if (!entity)
|
|
30
|
+
return;
|
|
31
|
+
response.setHeader("Etag", calculate(entity, options));
|
|
32
|
+
request.fresh && ctx.send(304, null);
|
|
29
33
|
});
|
|
30
34
|
};
|
|
31
35
|
export {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ReadStream } from 'node:fs';\nimport { stat } from 'node:fs/promises';\nimport calculate from 'etag';\nimport { middleware } from '@aomex/core';\nimport type { WebMiddleware } from '@aomex/web';\n\nexport const etag = (options:
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["import { ReadStream } from 'node:fs';\nimport { stat } from 'node:fs/promises';\nimport calculate from 'etag';\nimport { middleware } from '@aomex/core';\nimport type { WebMiddleware } from '@aomex/web';\nimport { Stream } from 'node:stream';\n\nexport interface EtagOptions {\n /**\n * 是否增加 `W/` 前缀。默认:`false`\n *\n * 如果是ReadStream,则默认开启。\n */\n weak?: boolean | undefined;\n}\n\nexport const etag = (options: EtagOptions = {}): WebMiddleware => {\n return middleware.web(async (ctx, next) => {\n await next();\n\n const { response, request } = ctx;\n const { method } = request;\n const { body, statusCode } = response;\n\n if (statusCode < 200 || statusCode > 299) return;\n if (method !== 'GET' && method !== 'HEAD') return;\n if (body === null || response.hasHeader('Etag')) return;\n\n let entity: Parameters<typeof calculate>[0] | undefined;\n if (body instanceof Stream) {\n if (body instanceof ReadStream) {\n entity = await stat(body.path);\n }\n } else if (typeof body === 'string' || Buffer.isBuffer(body)) {\n entity = body;\n } else {\n entity = JSON.stringify(body);\n }\n\n if (!entity) return;\n\n response.setHeader('Etag', calculate(entity, options));\n request.fresh && ctx.send(304, null);\n });\n};\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,YAAY;AACrB,OAAO,eAAe;AACtB,SAAS,kBAAkB;AAE3B,SAAS,cAAc;AAWhB,IAAM,OAAO,CAAC,UAAuB,CAAC,MAAqB;AAChE,SAAO,WAAW,IAAI,OAAO,KAAK,SAAS;AACzC,UAAM,KAAK;AAEX,UAAM,EAAE,UAAU,QAAQ,IAAI;AAC9B,UAAM,EAAE,OAAO,IAAI;AACnB,UAAM,EAAE,MAAM,WAAW,IAAI;AAE7B,QAAI,aAAa,OAAO,aAAa;AAAK;AAC1C,QAAI,WAAW,SAAS,WAAW;AAAQ;AAC3C,QAAI,SAAS,QAAQ,SAAS,UAAU,MAAM;AAAG;AAEjD,QAAI;AACJ,QAAI,gBAAgB,QAAQ;AAC1B,UAAI,gBAAgB,YAAY;AAC9B,iBAAS,MAAM,KAAK,KAAK,IAAI;AAAA,MAC/B;AAAA,IACF,WAAW,OAAO,SAAS,YAAY,OAAO,SAAS,IAAI,GAAG;AAC5D,eAAS;AAAA,IACX,OAAO;AACL,eAAS,KAAK,UAAU,IAAI;AAAA,IAC9B;AAEA,QAAI,CAAC;AAAQ;AAEb,aAAS,UAAU,QAAQ,UAAU,QAAQ,OAAO,CAAC;AACrD,YAAQ,SAAS,IAAI,KAAK,KAAK,IAAI;AAAA,EACrC,CAAC;AACH;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/etag",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
5
|
-
"keywords": [
|
|
6
|
-
"etag"
|
|
7
|
-
],
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "响应实体标签",
|
|
8
5
|
"repository": "git@github.com:aomex/aomex.git",
|
|
9
6
|
"homepage": "https://aomex.js.org",
|
|
10
7
|
"license": "MIT",
|
|
@@ -29,18 +26,16 @@
|
|
|
29
26
|
"access": "public"
|
|
30
27
|
},
|
|
31
28
|
"peerDependencies": {
|
|
32
|
-
"@aomex/core": "^0.0
|
|
33
|
-
"@aomex/web": "^0.0
|
|
29
|
+
"@aomex/core": "^1.0.0",
|
|
30
|
+
"@aomex/web": "^1.0.0"
|
|
34
31
|
},
|
|
35
32
|
"dependencies": {
|
|
36
33
|
"etag": "^1.8.1"
|
|
37
34
|
},
|
|
38
35
|
"devDependencies": {
|
|
39
|
-
"@
|
|
40
|
-
"@aomex/
|
|
41
|
-
"@
|
|
36
|
+
"@types/etag": "^1.8.1",
|
|
37
|
+
"@aomex/core": "^1.0.1",
|
|
38
|
+
"@aomex/web": "^1.0.1"
|
|
42
39
|
},
|
|
43
|
-
"scripts": {
|
|
44
|
-
"test": "vitest"
|
|
45
|
-
}
|
|
40
|
+
"scripts": {}
|
|
46
41
|
}
|