修复缓存目录;优化缓存清除
parent
81ddb02afc
commit
7fe8d8579b
20
index.js
20
index.js
|
@ -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)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in New Issue