@aomex/etag 1.0.4 → 1.1.0
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 +6 -16
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,21 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Change Log
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
# 1.1.0 (2024-06-27)
|
|
6
7
|
|
|
7
|
-
## 1.0.2
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
### Features
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### Minor Changes
|
|
14
|
-
|
|
15
|
-
- [`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8) Thanks [@geekact](https://github.com/geekact)! - 重新制作
|
|
16
|
-
|
|
17
|
-
### Patch Changes
|
|
18
|
-
|
|
19
|
-
- Updated dependencies [[`11103a2`](https://github.com/aomex/aomex/commit/11103a2aff4e081754c56b0ff18fa5130ca252e8)]:
|
|
20
|
-
- @aomex/core@1.0.0
|
|
21
|
-
- @aomex/web@1.0.0
|
|
11
|
+
* 初始化 ([3350159](https://github.com/aomex/aomex/commit/3350159454ad230e6d910405f907293b059b1f49))
|
package/dist/index.d.ts
CHANGED
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';\nimport { Stream } from 'node:stream';\n\nexport interface EtagOptions {\n /**\n * 是否增加 `W/`
|
|
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,IAAK;AAC1C,QAAI,WAAW,SAAS,WAAW,OAAQ;AAC3C,QAAI,SAAS,QAAQ,SAAS,UAAU,MAAM,EAAG;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,OAAQ;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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aomex/etag",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "响应实体标签",
|
|
5
5
|
"repository": "git@github.com:aomex/aomex.git",
|
|
6
6
|
"homepage": "https://aomex.js.org",
|
|
@@ -34,8 +34,8 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@types/etag": "^1.8.1",
|
|
37
|
-
"@aomex/core": "^1.0
|
|
38
|
-
"@aomex/web": "^1.0
|
|
37
|
+
"@aomex/core": "^1.1.0",
|
|
38
|
+
"@aomex/web": "^1.1.0"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {}
|
|
41
41
|
}
|