️ 优化saucenao错误处理

This commit is contained in:
yeyang
2023-02-14 00:49:11 +08:00
parent 90a2725f53
commit a747c4673d
6 changed files with 17 additions and 15 deletions

View File

@@ -57,10 +57,7 @@ export class NewPicSearch extends plugin {
if (!await this.Authentication(e)) return
if (!await this.handelImg(e, 'Ascii2D')) return
await PicSearch.Ascii2D(e.img[0])
.then(res => {
common.getRecallsendMsg(e, res.color, { isxmlMsg: false })
common.getRecallsendMsg(e, res.bovw, { isxmlMsg: false })
})
.then(res => common.getRecallsendMsg(e, [...res.color, ...res.bovw], { isxmlMsg: false }))
.catch(err => e.reply(err.message))
}

View File

@@ -16,7 +16,7 @@ cfTLSVersion: TLSv1.1
#是否使用 Puppeteer 请求 ascii2d 以绕过 cf js challenge
ascii2dUsePuppeteer: false
#ascii2d搜图返回结果的最大数量
ascii2dResultMaxQuantity: 6
ascii2dResultMaxQuantity: 3
#隐藏所有搜索结果的缩略图
hideImg: false
#whatanime 得到 R18 结果时隐藏结果缩略图

View File

@@ -50,7 +50,9 @@ export default new class {
if (!options.agent) options.agent = await this.getAgent()
try {
let res = await fetch(url, options)
res = checkStatus(res)
if (!options.closeCheckStatus) {
res = checkStatus(res)
}
if (options.statusCode) {
return res[options.statusCode]()
}
@@ -90,7 +92,9 @@ export default new class {
if (!options.agent) options.agent = await this.getAgent()
try {
let res = await fetch(url, options)
res = checkStatus(res)
if (!options.closeCheckStatus) {
res = checkStatus(res)
}
if (options.statusCode) {
return res[options.statusCode]()
}

View File

@@ -25,7 +25,7 @@ export default async function doSearch (url) {
const $ = cheerio.load(ret.data, { decodeEntities: false })
logger.error('[error] ascii2d url:', colorURL)
logger.debug(ret.data)
throw Error(`搜索失败,错误原因:${$('.container > .row > div:first-child > p').text().trim()}`)
throw Error(`Ascii2D搜索失败,错误原因:${$('.container > .row > div:first-child > p').text().trim()}`)
}
const bovwURL = colorURL.replace('/color/', '/bovw/')
let bovwDetail = await (ascii2dUsePuppeteer ? getAscii2dWithPuppeteer(bovwURL) : request.cfGet(bovwURL))

View File

@@ -42,7 +42,7 @@ export default async function doSearch (url) {
async function getSearchResult (imgURL, db = 999) {
logger.debug(`saucenao [${imgURL}]}`)
let api_key = Config.picSearch.SauceNAOApiKey
if (!api_key) return { error: '未配置SauceNAOApiKey无法使用SauceNAO搜图请在 https://saucenao.com/user.php?page=search-api 进行获取,请用指令:#设置SauceNAOapiKey <apikey> 进行添加' }
if (!api_key) throw Error('未配置SauceNAOApiKey无法使用SauceNAO搜图请在 https://saucenao.com/user.php?page=search-api 进行获取,请用指令:#设置SauceNAOapiKey <apikey> 进行添加')
return await request.get('https://saucenao.com/search.php', {
params: {
api_key,
@@ -51,10 +51,11 @@ async function getSearchResult (imgURL, db = 999) {
numres: 3,
url: imgURL,
hide: Config.picSearch.hideImgWhenSaucenaoNSFW
}
},
closeCheckStatus: true
}).then(res => {
if (res.status === 429) {
return { error: 'SauceNAO搜图 搜索次数已达单位时间上限,请稍候再试' }
throw Error('SauceNAO搜图 搜索次数已达单位时间上限,请稍候再试')
} else {
return res.json()
}

View File

@@ -22,7 +22,7 @@ export default class PixivApi {
async login () {
if (!this.refresh_token) {
throw Error('Pixiv 未配置refresh_token刷新令牌')
throw Error('[Yenai][Pixiv] 未配置refresh_token刷新令牌')
}
const data = {
client_id: 'MOBrBDS8blbauoSck0ZfDbtuzpyT',
@@ -34,15 +34,15 @@ export default class PixivApi {
data,
headers: this.headers
}).then(res => res.json())
if (error) throw Error(`Pixiv login Error Response: ${error}`)
if (error) throw Error(`[Yenai][Pixiv]login Error Response: ${error}`)
this.access_token = response.access_token
this.refresh_token = response.refresh_token
this.auth = response
if (this.access_token) {
const { id, name, account } = this.auth.user
logger.info(`[Yenai] Pixiv login ${logger.yellow(`${name}(${id}) @${account}`)} ${logger.green('success')}`)
logger.info(`[Yenai][Pixiv]login ${logger.yellow(`${name}(${id}) @${account}`)} ${logger.green('success')}`)
} else {
logger.error(`[Yenai] Pixiv login ${logger.red('fail')}`)
logger.error(`[Yenai][Pixiv]login ${logger.red('fail')}`)
}
}