forked from Mirrors/doipjs
Run prettier
This commit is contained in:
parent
de5d358b31
commit
347c48ff4e
4 changed files with 74 additions and 55 deletions
|
@ -213,39 +213,60 @@ const verify = async (input, fingerprint, opts) => {
|
||||||
case 'adaptive':
|
case 'adaptive':
|
||||||
if (spData.proof.useProxy) {
|
if (spData.proof.useProxy) {
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
|
proofData = await serviceproviders.proxyRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
} catch (er) {}
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.directRequestHandler(spData, opts)
|
proofData = await serviceproviders.directRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
} catch (er) {}
|
||||||
if (!proofData) {
|
if (!proofData) {
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
|
proofData = await serviceproviders.proxyRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
} catch (er) {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break
|
||||||
case 'fallback':
|
case 'fallback':
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.directRequestHandler(spData, opts)
|
proofData = await serviceproviders.directRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
} catch (er) {}
|
||||||
if (!proofData) {
|
if (!proofData) {
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
|
proofData = await serviceproviders.proxyRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
|
opts
|
||||||
|
)
|
||||||
|
} catch (er) {}
|
||||||
}
|
}
|
||||||
break;
|
break
|
||||||
case 'always':
|
case 'always':
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.proxyRequestHandler(spData, opts)
|
proofData = await serviceproviders.proxyRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
break;
|
opts
|
||||||
|
)
|
||||||
|
} catch (er) {}
|
||||||
|
break
|
||||||
case 'never':
|
case 'never':
|
||||||
try {
|
try {
|
||||||
proofData = await serviceproviders.directRequestHandler(spData, opts)
|
proofData = await serviceproviders.directRequestHandler(
|
||||||
} catch(er) {}
|
spData,
|
||||||
break;
|
opts
|
||||||
|
)
|
||||||
|
} catch (er) {}
|
||||||
|
break
|
||||||
default:
|
default:
|
||||||
objResult.errors.push('invalid_proxy_policy')
|
objResult.errors.push('invalid_proxy_policy')
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,7 +120,9 @@ const fetchURI = (uri) => {
|
||||||
|
|
||||||
switch (match[1]) {
|
switch (match[1]) {
|
||||||
case 'hkp':
|
case 'hkp':
|
||||||
resolve(fetchHKP(match[3] ? match[3] : match[2], match[3] ? match[2] : null))
|
resolve(
|
||||||
|
fetchHKP(match[3] ? match[3] : match[2], match[3] ? match[2] : null)
|
||||||
|
)
|
||||||
break
|
break
|
||||||
case 'wkd':
|
case 'wkd':
|
||||||
resolve(fetchWKD(match[2]))
|
resolve(fetchWKD(match[2]))
|
||||||
|
|
|
@ -76,27 +76,27 @@ const directRequestHandler = (spData, opts) => {
|
||||||
Accept: 'application/json',
|
Accept: 'application/json',
|
||||||
'User-Agent': `doipjs/${require('../package.json').version}`,
|
'User-Agent': `doipjs/${require('../package.json').version}`,
|
||||||
})
|
})
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
return await res.json()
|
return await res.json()
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
resolve(res)
|
resolve(res)
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
reject(e)
|
reject(e)
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
case 'text':
|
case 'text':
|
||||||
req(url)
|
req(url)
|
||||||
.then(async (res) => {
|
.then(async (res) => {
|
||||||
return await res.text()
|
return await res.text()
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
resolve(res)
|
resolve(res)
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.catch((e) => {
|
||||||
reject(e)
|
reject(e)
|
||||||
})
|
})
|
||||||
break
|
break
|
||||||
default:
|
default:
|
||||||
reject('No specified proof data format')
|
reject('No specified proof data format')
|
||||||
|
@ -108,20 +108,18 @@ const directRequestHandler = (spData, opts) => {
|
||||||
const proxyRequestHandler = (spData, opts) => {
|
const proxyRequestHandler = (spData, opts) => {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri
|
const url = spData.proof.fetch ? spData.proof.fetch : spData.proof.uri
|
||||||
req(
|
req(utils.generateProxyURL(spData.proof.format, url, opts), null, {
|
||||||
utils.generateProxyURL(spData.proof.format, url, opts),
|
Accept: 'application/json',
|
||||||
null,
|
|
||||||
{ Accept: 'application/json' }
|
|
||||||
)
|
|
||||||
.then(async (res) => {
|
|
||||||
return await res.json()
|
|
||||||
})
|
|
||||||
.then((res) => {
|
|
||||||
resolve(res.content)
|
|
||||||
})
|
|
||||||
.catch((e) => {
|
|
||||||
reject(e)
|
|
||||||
})
|
})
|
||||||
|
.then(async (res) => {
|
||||||
|
return await res.json()
|
||||||
|
})
|
||||||
|
.then((res) => {
|
||||||
|
resolve(res.content)
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
reject(e)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,11 +26,9 @@ const customRequestHandler = async (spData, opts) => {
|
||||||
try {
|
try {
|
||||||
resUser = await req(urlUser, null, { Accept: 'application/json' })
|
resUser = await req(urlUser, null, { Accept: 'application/json' })
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
resUser = await req(
|
resUser = await req(utils.generateProxyURL('web', urlUser, opts), null, {
|
||||||
utils.generateProxyURL('web', urlUser, opts),
|
Accept: 'application/json',
|
||||||
null,
|
})
|
||||||
{ Accept: 'application/json' }
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
const jsonUser = await resUser.json()
|
const jsonUser = await resUser.json()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue