diff --git a/index.js b/index.js index ecf2ea7..54012b5 100644 --- a/index.js +++ b/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) } } diff --git a/package.json b/package.json index 1aa13c8..b0bf9ee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gm5/request", - "version": "1.2.1", + "version": "1.2.2", "description": "对Http的request进一步封装, 提供常用的API", "main": "index.js", "author": "yutent",