本地编译优化
This commit is contained in:
tangly1024
2021-12-15 12:36:52 +08:00
parent de99bb7a5d
commit f8694456ef
3 changed files with 77 additions and 11 deletions

View File

@@ -10,7 +10,14 @@ export async function getCacheFromFile (key) {
const exist = await fs.existsSync(jsonFile)
if (!exist) return null
const data = await fs.readFileSync(jsonFile)
const json = data ? JSON.parse(data) : {}
let json = null
if (!data) return null
try {
json = JSON.parse(data)
} catch (error) {
console.error('读取JSON缓存文件失败', data)
return null
}
// 缓存超过有效期就作废
const cacheValidTime = new Date(parseInt(json[key + '_expire_time']) + cacheInvalidSeconds)
const currentTime = new Date()