Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed May 30, 2020
1 parent cd9d5d2 commit 0925279
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 8 deletions.
80 changes: 75 additions & 5 deletions app/services/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,86 @@ var resourcesCount = 0

const recognize = async (image , type, lang) => {
let server = config.getConfig('ocr_server')
let preProcess = (data) => {

let serverData = server.split('#')
let output = 'result'
let ct = 'form'
let options = {
url:serverData[0],
method:'POST',
}
let reform = {}
if(serverData[1]){
let form = querystring.parse(serverData[1] || '') || {}
if(form.$noscheme){
data.image = data.image.split(',')[1]
delete form.$scheme
}
if( form.$method ) {
options.method == form.$method
delete form.$method
}
if( form.$ct ){
ct = form.$ct
delete form.$ct
}
if( form.$output ){
output = form.$output
delete form.$output
}

for(let i in form){
let value = form[i]
if(data[value]){
reform[i] = data[value]
}else{
reform[i] = value
}
}
}else{
reform = data
}

options[ct] = reform

if(output){
if( output != 'raw'){
options.json = true
}
}

return { options , output }
}

const getValue = (value , output) => {
if(!value) return value
let ret = value
if(output != 'raw'){
try{
let fn = new Function(`return this.${output};`);
ret = fn.call(value) || ''
}catch(e){
ret = ''
}
}
return ret
}

if(server){
let resp
let resp
let { options , output } = preProcess({image , type, lang })
// console.log(options,output)
try{
resp = await http.post(server,{ image , type, lang },{json:true})
resp = await http({...options , async:true})
}catch(e){
//console.log(e)
console.log(e)
}

// console.log(options,resp.body)
if(resp && resp.body){
return { error:false , result:resp.body.result}
return { error:false , result:getValue(resp.body , output)}
}else{
return { error:false , result:''}
}
}

Expand Down
9 changes: 6 additions & 3 deletions plugins/drive.189cloud.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class Manager {

let result = false
let msg = ''
let needcaptcha = await this.needcaptcha({
let needcaptcha = true;await this.needcaptcha({
accountType: '01',
userName:username,
appKey: 'cloud',
Expand All @@ -187,6 +187,8 @@ class Manager {
imgBase64 = "data:" + resp.headers["content-type"] + ";base64," + Buffer.from(resp.body).toString('base64');
}
let { error , code } = await this.ocr(imgBase64)
console.log('validateCode:['+code+']')

//服务不可用
if(error){
formdata.validateCode = ''
Expand All @@ -195,7 +197,6 @@ class Manager {
}
else if(code){
formdata.validateCode = code
console.log('validateCode:['+code+']')
}
//无法有效识别
else{
Expand All @@ -221,6 +222,7 @@ class Manager {

continue;
}

if( resp.body && resp.body.toUrl ){
resp = await this.request.get(resp.body.toUrl , { followRedirect:false, headers })
let cookies = resp.headers['set-cookie'].join('; ')
Expand All @@ -233,6 +235,7 @@ class Manager {
break;
}else{
msg = resp.body.msg
break;
}

}
Expand Down Expand Up @@ -367,7 +370,7 @@ module.exports = ({ request, cache, getConfig, querystring, base64, saveDrive, g
},
json:true
})

if (!resp || !resp.body) {
return { id, type: 'folder', protocol: defaultProtocol,body:resp.msg || '解析错误' }

Expand Down

0 comments on commit 0925279

Please sign in to comment.