修复缓存目录;优化缓存清除
parent
81ddb02afc
commit
7fe8d8579b
20
index.js
20
index.js
|
@ -11,9 +11,11 @@ import fs from 'iofs'
|
|||
import URL from 'url'
|
||||
import QS from 'querystring'
|
||||
|
||||
const tmpdir = process.cwd() + '/.tmp/'
|
||||
const encode = encodeURIComponent
|
||||
const decode = decodeURIComponent
|
||||
var __dirname = path.dirname(URL.fileURLToPath(import.meta.url))
|
||||
|
||||
var tmpdir = path.resolve(__dirname, './.tmp/')
|
||||
var encode = encodeURIComponent
|
||||
var decode = decodeURIComponent
|
||||
|
||||
function hideProperty(host, name, value) {
|
||||
Object.defineProperty(host, name, {
|
||||
|
@ -36,16 +38,8 @@ export default class Request {
|
|||
|
||||
this.__fixUrl()
|
||||
|
||||
if (!fs.isdir(tmpdir)) {
|
||||
fs.mkdir(tmpdir)
|
||||
} else {
|
||||
// 清除2个小时前的所有临时文件
|
||||
let list = fs.ls(tmpdir)
|
||||
list.forEach(it => {
|
||||
if (fs.stat(it).atime < Date.now() - 2 * 3600 * 1000) {
|
||||
fs.rm(it)
|
||||
}
|
||||
})
|
||||
if (fs.isdir(tmpdir)) {
|
||||
fs.rm(tmpdir)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@gm5/request",
|
||||
"version": "1.2.1",
|
||||
"version": "1.2.2",
|
||||
"description": "对Http的request进一步封装, 提供常用的API",
|
||||
"main": "index.js",
|
||||
"author": "yutent",
|
||||
|
|
Loading…
Reference in New Issue