From 92ef27b06a342fad28c7b1ecad2531e369e604fe Mon Sep 17 00:00:00 2001 From: yutent Date: Sat, 8 Jan 2022 16:59:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96tmp=E7=9B=AE=E5=BD=95?= =?UTF-8?q?=E5=88=9B=E5=BB=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.js | 25 +++++++++---------------- package.json | 2 +- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/index.js b/index.js index db5f48e..c2aa9f0 100644 --- a/index.js +++ b/index.js @@ -16,10 +16,16 @@ const DEFAULT_FORM_TYPE = 'application/x-www-form-urlencoded' var __dirname = PATH.dirname(URL.fileURLToPath(import.meta.url)) -var tmpdir = PATH.resolve(__dirname, './.tmp/') +var tmpdir = PATH.resolve(__dirname, '.tmp/') var encode = encodeURIComponent var decode = decodeURIComponent +if (fs.isdir(tmpdir)) { + fs.rm(tmpdir, true) +} + +fs.mkdir(tmpdir) + function hideProperty(host, name, value) { Object.defineProperty(host, name, { value: value, @@ -40,12 +46,6 @@ export default class Request { hideProperty(this, '__COOKIE__', parseCookie(this.header('cookie') || '')) this.__fixUrl() - - if (fs.isdir(tmpdir)) { - fs.rm(tmpdir) - } else { - fs.mkdir(tmpdir) - } } // 修正请求的url @@ -135,11 +135,7 @@ export default class Request { this.__GET__ = para } - return key - ? this.__GET__.hasOwnProperty(key) - ? this.__GET__[key] - : null - : this.__GET__ + return key ? (this.__GET__.hasOwnProperty(key) ? this.__GET__[key] : null) : this.__GET__ } /** @@ -173,10 +169,7 @@ export default class Request { return } if (~contentType.indexOf('urlencoded')) { - if ( - name.slice(0, 2) === '{"' && - (name.slice(-2) === '"}' || value.slice(-2) === '"}') - ) { + if (name.slice(0, 2) === '{"' && (name.slice(-2) === '"}' || value.slice(-2) === '"}')) { name = name.replace(/\s/g, '+') if (value.slice(0, 1) === '=') value = '=' + value diff --git a/package.json b/package.json index a216da9..2f2b6ea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gm5/request", - "version": "1.2.5", + "version": "1.2.6", "description": "对Http的request进一步封装, 提供常用的API", "main": "index.js", "author": "yutent",