swpp-backends 3.0.0-alpha.2 → 3.0.0-alpha.3

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.
@@ -17,7 +17,7 @@ class JsonBuilder {
17
17
  }
18
18
  // noinspection JSUnusedGlobalSymbols
19
19
  async buildJson() {
20
- const json = await this.compilation.compilationEnv.read('VERSION_FILE')();
20
+ const json = await this.compilation.compilationEnv.read('VERSION_FILE').fetcher();
21
21
  if (json.info.length == 0) {
22
22
  json.info.push({ version: 1 });
23
23
  return json;
@@ -98,22 +98,25 @@ function buildCommon(_env, crossEnv, crossCode) {
98
98
  }),
99
99
  /** 获取已经上线的版本文件 */
100
100
  VERSION_FILE: (0, KeyValueDatabase_1.buildEnv)({
101
- default: async () => {
102
- const host = env.read('DOMAIN_HOST');
103
- const fetcher = env.read('FETCH_NETWORK_FILE');
104
- const isNotFound = env.read('IS_NOT_FOUND');
105
- try {
106
- const response = await fetcher.fetch(`https://${host}/update.json`);
107
- if (!isNotFound.response(response)) {
108
- const json = await response.json();
109
- return json;
101
+ default: {
102
+ path: 'update.json',
103
+ async fetcher() {
104
+ const host = env.read('DOMAIN_HOST');
105
+ const fetcher = env.read('FETCH_NETWORK_FILE');
106
+ const isNotFound = env.read('IS_NOT_FOUND');
107
+ try {
108
+ const response = await fetcher.fetch(`https://${host}/${this.path}`);
109
+ if (!isNotFound.response(response)) {
110
+ const json = await response.json();
111
+ return json;
112
+ }
110
113
  }
114
+ catch (e) {
115
+ if (!isNotFound.error(e))
116
+ throw e;
117
+ }
118
+ return { global: 0, info: [] };
111
119
  }
112
- catch (e) {
113
- if (!isNotFound.error(e))
114
- throw e;
115
- }
116
- return { global: 0, info: [] };
117
120
  }
118
121
  }),
119
122
  /** 读取一个本地文件 */
@@ -140,6 +143,7 @@ function buildCommon(_env, crossEnv, crossCode) {
140
143
  error: (err) => err?.cause?.code === 'ENOTFOUND'
141
144
  }
142
145
  }),
146
+ /** 是否允许 404 */
143
147
  ALLOW_NOT_FOUND: (0, KeyValueDatabase_1.buildEnv)({
144
148
  default: AllowNotFoundEnum.ALLOW_STATUS,
145
149
  checker(value) {
@@ -153,6 +157,7 @@ function buildCommon(_env, crossEnv, crossCode) {
153
157
  }
154
158
  }
155
159
  }),
160
+ /** 文件解析器 */
156
161
  FILE_PARSER: (0, KeyValueDatabase_1.buildEnv)({
157
162
  default: createRegister(env, crossEnv, crossCode)
158
163
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "swpp-backends",
3
- "version": "3.0.0-alpha.2",
3
+ "version": "3.0.0-alpha.3",
4
4
  "main": "dist/index.js",
5
5
  "typings": "types/index.d.ts",
6
6
  "description": "Generate a powerful ServiceWorker for your website.",
@@ -27,7 +27,10 @@ declare function buildCommon(_env: any, crossEnv: CrossEnv, crossCode: CrossDepC
27
27
  /** 版本信息长度限制 */
28
28
  readonly VERSION_LENGTH_LIMIT: import("./KeyValueDatabase").DatabaseValue<number>;
29
29
  /** 获取已经上线的版本文件 */
30
- readonly VERSION_FILE: import("./KeyValueDatabase").DatabaseValue<() => Promise<UpdateJson>>;
30
+ readonly VERSION_FILE: import("./KeyValueDatabase").DatabaseValue<{
31
+ path: string;
32
+ fetcher(): Promise<UpdateJson>;
33
+ }>;
31
34
  /** 读取一个本地文件 */
32
35
  readonly LOCAL_FILE_READER: import("./KeyValueDatabase").DatabaseValue<(path: string) => Promise<string>>;
33
36
  /** 拉取网络文件 */
@@ -37,7 +40,9 @@ declare function buildCommon(_env: any, crossEnv: CrossEnv, crossCode: CrossDepC
37
40
  response: (response: Response) => boolean;
38
41
  error: (err: any) => boolean;
39
42
  }>;
43
+ /** 是否允许 404 */
40
44
  readonly ALLOW_NOT_FOUND: import("./KeyValueDatabase").DatabaseValue<AllowNotFoundEnum>;
45
+ /** 文件解析器 */
41
46
  readonly FILE_PARSER: import("./KeyValueDatabase").DatabaseValue<FileParserRegistry>;
42
47
  };
43
48
  export {};