From 7fe8d8579b8ee9c510519e675f0b0861f857d2e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Mon, 28 Sep 2020 09:48:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BC=93=E5=AD=98=E7=9B=AE?= =?UTF-8?q?=E5=BD=95;=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98=E6=B8=85?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 20 +++++++------------- package.json | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) 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",