修复缓存目录;优化缓存清除

v1
宇天 2020-09-28 09:48:20 +08:00
parent 81ddb02afc
commit 7fe8d8579b
2 changed files with 8 additions and 14 deletions

View File

@ -11,9 +11,11 @@ import fs from 'iofs'
import URL from 'url' import URL from 'url'
import QS from 'querystring' import QS from 'querystring'
const tmpdir = process.cwd() + '/.tmp/' var __dirname = path.dirname(URL.fileURLToPath(import.meta.url))
const encode = encodeURIComponent
const decode = decodeURIComponent var tmpdir = path.resolve(__dirname, './.tmp/')
var encode = encodeURIComponent
var decode = decodeURIComponent
function hideProperty(host, name, value) { function hideProperty(host, name, value) {
Object.defineProperty(host, name, { Object.defineProperty(host, name, {
@ -36,16 +38,8 @@ export default class Request {
this.__fixUrl() this.__fixUrl()
if (!fs.isdir(tmpdir)) { if (fs.isdir(tmpdir)) {
fs.mkdir(tmpdir) fs.rm(tmpdir)
} else {
// 清除2个小时前的所有临时文件
let list = fs.ls(tmpdir)
list.forEach(it => {
if (fs.stat(it).atime < Date.now() - 2 * 3600 * 1000) {
fs.rm(it)
}
})
} }
} }

View File

@ -1,6 +1,6 @@
{ {
"name": "@gm5/request", "name": "@gm5/request",
"version": "1.2.1", "version": "1.2.2",
"description": "对Http的request进一步封装, 提供常用的API", "description": "对Http的request进一步封装, 提供常用的API",
"main": "index.js", "main": "index.js",
"author": "yutent", "author": "yutent",