hexo-swpp 1.2.0 → 1.2.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.
Files changed (2) hide show
  1. package/index.js +11 -7
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -40,8 +40,7 @@ if (pluginConfig?.enable) {
40
40
  .replace('module.exports.replaceList', 'const replaceList')
41
41
  return {
42
42
  path: 'sw.js',
43
- data: template.replace('const { cacheList, replaceList } = require(\'../sw-cache\')', cache),
44
- layout: 'js'
43
+ data: template.replace('const { cacheList, replaceList } = require(\'../sw-cache\')', cache)
45
44
  }
46
45
  })
47
46
 
@@ -71,8 +70,7 @@ if (pluginConfig?.enable) {
71
70
  .replaceAll('// ${onSuccess}', pluginConfig.dom.onsuccess)
72
71
  return {
73
72
  path: 'sw-dom.js',
74
- data: template,
75
- layout: 'js'
73
+ data: template
76
74
  }
77
75
  })
78
76
  }
@@ -137,13 +135,19 @@ const buildNewJson = path => {
137
135
  const getJsonFromNetwork = async path => {
138
136
  const url = root + path
139
137
  try {
140
- const result = await fetch(url)
141
- if (result.status < 200 || result.status >= 400 || !result.data)
138
+ const result = await fetch(url, {
139
+ headers: {
140
+ referer: new URL(url).hostname,
141
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 Edg/107.0.1418.62'
142
+ }
143
+ })
144
+ if (result.status < 200 || result.status >= 400)
142
145
  // noinspection ExceptionCaughtLocallyJS
143
146
  throw `拉取 ${url} 时出现异常(${result.status})`
144
147
  return await result.json()
145
148
  } catch (e) {
146
- if (e.toString().includes('404'))
149
+ // noinspection SpellCheckingInspection
150
+ if (e.code === 'ENOTFOUND')
147
151
  logger.error(`拉取 ${url} 时出现 404,如果您是第一次构建请忽略这个错误`)
148
152
  else throw e
149
153
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hexo-swpp",
3
- "version": "1.2.0",
3
+ "version": "1.2.2",
4
4
  "main": "index.js",
5
5
  "dependencies": {
6
6
  "hexo-log": "^3.0.0",