优化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 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

View File

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