优化tmp目录创建

v1 1.2.6
yutent 2022-01-08 16:59:11 +08:00
parent 84273469ab
commit 92ef27b06a
2 changed files with 10 additions and 17 deletions

View File

@ -16,10 +16,16 @@ const DEFAULT_FORM_TYPE = 'application/x-www-form-urlencoded'
var __dirname = PATH.dirname(URL.fileURLToPath(import.meta.url)) 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 encode = encodeURIComponent
var decode = decodeURIComponent var decode = decodeURIComponent
if (fs.isdir(tmpdir)) {
fs.rm(tmpdir, true)
}
fs.mkdir(tmpdir)
function hideProperty(host, name, value) { function hideProperty(host, name, value) {
Object.defineProperty(host, name, { Object.defineProperty(host, name, {
value: value, value: value,
@ -40,12 +46,6 @@ export default class Request {
hideProperty(this, '__COOKIE__', parseCookie(this.header('cookie') || '')) hideProperty(this, '__COOKIE__', parseCookie(this.header('cookie') || ''))
this.__fixUrl() this.__fixUrl()
if (fs.isdir(tmpdir)) {
fs.rm(tmpdir)
} else {
fs.mkdir(tmpdir)
}
} }
// 修正请求的url // 修正请求的url
@ -135,11 +135,7 @@ export default class Request {
this.__GET__ = para this.__GET__ = para
} }
return key return key ? (this.__GET__.hasOwnProperty(key) ? this.__GET__[key] : null) : this.__GET__
? this.__GET__.hasOwnProperty(key)
? this.__GET__[key]
: null
: this.__GET__
} }
/** /**
@ -173,10 +169,7 @@ export default class Request {
return return
} }
if (~contentType.indexOf('urlencoded')) { if (~contentType.indexOf('urlencoded')) {
if ( if (name.slice(0, 2) === '{"' && (name.slice(-2) === '"}' || value.slice(-2) === '"}')) {
name.slice(0, 2) === '{"' &&
(name.slice(-2) === '"}' || value.slice(-2) === '"}')
) {
name = name.replace(/\s/g, '+') name = name.replace(/\s/g, '+')
if (value.slice(0, 1) === '=') value = '=' + value if (value.slice(0, 1) === '=') value = '=' + value

View File

@ -1,6 +1,6 @@
{ {
"name": "@gm5/request", "name": "@gm5/request",
"version": "1.2.5", "version": "1.2.6",
"description": "对Http的request进一步封装, 提供常用的API", "description": "对Http的request进一步封装, 提供常用的API",
"main": "index.js", "main": "index.js",
"author": "yutent", "author": "yutent",