swpp-backends 3.1.0 → 3.1.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/swpp/database/CrossDepCode.d.ts +8 -2
- package/dist/swpp/database/CrossDepCode.js +7 -1
- package/dist/swpp/database/CrossEnv.d.ts +0 -2
- package/dist/swpp/database/CrossEnv.js +0 -11
- package/dist/swpp/database/RuntimeDepCode.d.ts +1 -1
- package/dist/swpp/database/RuntimeDepCode.js +3 -1
- package/package.json +1 -1
|
@@ -26,9 +26,15 @@ declare function buildCommon(): {
|
|
|
26
26
|
readonly isFetchSuccessful: {
|
|
27
27
|
readonly default: FunctionInBrowserAndNode<[response: Response], boolean>;
|
|
28
28
|
};
|
|
29
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* 缓存规则
|
|
31
|
+
*
|
|
32
|
+
* + 返回转换为 false 的值表示不缓存;
|
|
33
|
+
* + 返回正数表示缓存指定毫秒数;
|
|
34
|
+
* + 返回负数表示永久缓存(仅对本站资源有效,非本站资源返回负数等价于 24h)
|
|
35
|
+
*/
|
|
30
36
|
readonly matchCacheRule: {
|
|
31
|
-
readonly default: FunctionInBrowserAndNode<[_url: URL], number | false |
|
|
37
|
+
readonly default: FunctionInBrowserAndNode<[_url: URL], number | false | null | undefined>;
|
|
32
38
|
};
|
|
33
39
|
/** 归一化 URL */
|
|
34
40
|
readonly normalizeUrl: {
|
|
@@ -42,7 +42,13 @@ function buildCommon() {
|
|
|
42
42
|
isFetchSuccessful: {
|
|
43
43
|
default: CrossDepCode.buildBothFunction((response) => [200, 301, 302, 307, 308].includes(response.status))
|
|
44
44
|
},
|
|
45
|
-
/**
|
|
45
|
+
/**
|
|
46
|
+
* 缓存规则
|
|
47
|
+
*
|
|
48
|
+
* + 返回转换为 false 的值表示不缓存;
|
|
49
|
+
* + 返回正数表示缓存指定毫秒数;
|
|
50
|
+
* + 返回负数表示永久缓存(仅对本站资源有效,非本站资源返回负数等价于 24h)
|
|
51
|
+
*/
|
|
46
52
|
matchCacheRule: {
|
|
47
53
|
default: CrossDepCode.buildBothFunction((_url) => false)
|
|
48
54
|
},
|
|
@@ -11,8 +11,6 @@ declare function buildCommon(): {
|
|
|
11
11
|
readonly CACHE_NAME: import("./KeyValueDatabase").DatabaseValue<string>;
|
|
12
12
|
/** 网站的基准域名 */
|
|
13
13
|
readonly BASE_URL: import("./KeyValueDatabase").DatabaseValue<string>;
|
|
14
|
-
/** 永久缓存标记 */
|
|
15
|
-
readonly INFINITE_CACHE: import("./KeyValueDatabase").DatabaseValue<symbol>;
|
|
16
14
|
/** 存储版本号的 URL */
|
|
17
15
|
readonly VERSION_PATH: import("./KeyValueDatabase").DatabaseValue<string>;
|
|
18
16
|
/** 逃生门版本号 */
|
|
@@ -44,17 +44,6 @@ function buildCommon() {
|
|
|
44
44
|
return false;
|
|
45
45
|
},
|
|
46
46
|
}),
|
|
47
|
-
/** 永久缓存标记 */
|
|
48
|
-
INFINITE_CACHE: (0, KeyValueDatabase_1.buildEnv)({
|
|
49
|
-
default: Symbol(),
|
|
50
|
-
checker(value) {
|
|
51
|
-
// noinspection SuspiciousTypeOfGuard
|
|
52
|
-
if (typeof value !== 'symbol') {
|
|
53
|
-
return { value, message: '填写的值应当为一个 Symbol' };
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}),
|
|
58
47
|
/** 存储版本号的 URL */
|
|
59
48
|
VERSION_PATH: (0, KeyValueDatabase_1.buildEnv)({
|
|
60
49
|
default: 'https://id.v3/',
|
|
@@ -30,7 +30,7 @@ declare function buildCommon(): {
|
|
|
30
30
|
};
|
|
31
31
|
/** 判断指定的缓存是否是有效缓存 */
|
|
32
32
|
readonly isValidCache: {
|
|
33
|
-
readonly default: (response: Response, rule: number
|
|
33
|
+
readonly default: (response: Response, rule: number) => boolean;
|
|
34
34
|
};
|
|
35
35
|
/** 读取版本号 */
|
|
36
36
|
readonly readVersion: {
|
|
@@ -85,12 +85,14 @@ function buildCommon() {
|
|
|
85
85
|
if (headers.has(INVALID_KEY))
|
|
86
86
|
return false;
|
|
87
87
|
// 只有本站资源允许永久缓存
|
|
88
|
-
if (rule
|
|
88
|
+
if (rule < 0) {
|
|
89
89
|
const url = response.url;
|
|
90
90
|
const baseLength = BASE_URL.length;
|
|
91
91
|
if (url.startsWith(BASE_URL) && (url.length === baseLength || url[baseLength] === '/')) {
|
|
92
92
|
return true;
|
|
93
93
|
}
|
|
94
|
+
// 将rule设置为一天(24小时)
|
|
95
|
+
rule = 24 * 60 * 60 * 1000;
|
|
94
96
|
}
|
|
95
97
|
const storage = headers.get(STORAGE_TIMESTAMP);
|
|
96
98
|
if (!storage)
|