Skip to content

Commit

Permalink
+Captcha Recognize API
Browse files Browse the repository at this point in the history
  • Loading branch information
reruin committed May 15, 2020
1 parent ab0860f commit 4680960
Show file tree
Hide file tree
Showing 8 changed files with 207 additions and 39 deletions.
2 changes: 2 additions & 0 deletions app/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ const db = createFiledb(configPath , {raw:true} , {
proxy_paths:[],

proxy_server:'',

ocr_server:'https://api.reruin.net/ocr'
});

if(process.env.PORT){
Expand Down
19 changes: 15 additions & 4 deletions app/controllers/manage.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const cache = require('../utils/cache')
const { getVendors , reload } = require('../services/plugin')
const service = require('../services/sharelist')

const handlers = async (a, body) => {
const handlers = async (a, body , ctx) => {
let result = { status: 0, message: 'Success', data: '', a }

if (a == 'path') {
Expand Down Expand Up @@ -64,7 +64,7 @@ const handlers = async (a, body) => {
cache.clear()
result.message = 'Success'
} else if (a == 'cfg') {
let { proxy_enable, preview_enable, readme_enable, max_age_dir, max_age_file,max_age_download, webdav_path, anonymous_uplod_enable, ignore_file_extensions , ignore_paths , custom_style , custom_script , proxy_paths , proxy_server } = body
let { proxy_enable, preview_enable, readme_enable, max_age_dir, max_age_file,max_age_download, webdav_path, anonymous_uplod_enable, ignore_file_extensions , ignore_paths , custom_style , custom_script , proxy_paths , proxy_server , ocr_server , language } = body
let opts = {}
if (max_age_dir !== undefined) {
max_age_dir = parseInt(max_age_dir)
Expand Down Expand Up @@ -110,6 +110,17 @@ const handlers = async (a, body) => {
if (webdav_path) {
opts.webdav_path = webdav_path
}

if(ocr_server){
opts.ocr_server = ocr_server
}

if(language !== undefined){
opts.language = language
//console.log(ctx,ctx.__setLocale)
ctx.__setLocale(language)
}

opts.custom_script = custom_script
opts.custom_style = custom_style
opts.ignore_paths = config.getConfig('ignore_paths')
Expand Down Expand Up @@ -164,7 +175,7 @@ module.exports = {
result.status = 403
result.message = 'Require Auth'
} else {
result = await handlers(a, body)
result = await handlers(a, body , ctx)
}

}
Expand All @@ -182,7 +193,7 @@ module.exports = {
ctx.body = JSON.stringify(config.getAllConfig())
return
} else {
result = await handlers(act, body)
result = await handlers(act, body,ctx)
}
} else {
result.status = -1
Expand Down
13 changes: 13 additions & 0 deletions app/services/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ var ready = false

var resourcesCount = 0

const recognize = async (image , lang) => {
let server = config.getConfig('ocr_server')
if(server){
let resp = await http.post(server,{ image , lang },{json:true})
if(resp.body){
return { error:false , result:resp.body.result}
}
}

return { error:true , msg:'ocr server is NOT ready!'}
}

/*
* 根据文件id获取详情
*/
Expand Down Expand Up @@ -146,6 +158,7 @@ const getHelpers = (id) => {
wrapReadableStream,
rectifier,
chunkStream,
recognize,
getOption:()=>{

},
Expand Down
14 changes: 14 additions & 0 deletions app/views/default/manage.pug
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ block content
.panel-body
form.form-horizontal(method='post',action="/manage/api")
input(type='hidden',name='a',value='cfg')
.form-group
.col-sm-4
label= __('language')
.col-sm-8
select.form-control(name='language',value=config.language)
option(value='', selected=config.language=='' ? 'selected' : null)= __('自动')
option(value='zh-CN', selected=config.language=='zh-CN' ? 'selected' : null)= __('简体中文')
option(value='zh-TW', selected=config.language=='zh-TW' ? 'selected' : null)= __('繁體中文')
option(value='en-US', selected=config.language=='en-US' ? 'selected' : null)= __('English')
.form-group
.col-sm-4
label= __('proxy_enable')
Expand Down Expand Up @@ -96,6 +105,11 @@ block content
select.form-control(name='anonymous_uplod_enable',value=config.anonymous_uplod_enable,required)
option(value='1', selected=config.anonymous_uplod_enable==1 ? 'selected' : null)= __('enable')
option(value='0', selected=config.anonymous_uplod_enable==0 ? 'selected' : null)= __('disable')
.form-group
.col-sm-4
label= __('ocr_server')
.col-sm-8
input.form-control(type='text', name='ocr_server' , value=config.ocr_server,placeholder=__('ocr_server_placeholder'))
.form-group
.col-sm-4
label= __('custom_style')
Expand Down
5 changes: 4 additions & 1 deletion locales/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ module.exports = {
"reboot":"Reboot",
"proxy_paths":"Proxy Paths",
"proxy_server":"Proxy Server",
"proxy_server_placeholder":""
"proxy_server_placeholder":"",
"ocr_server":"Captcha Recognize API",
"ocr_server_placeholder":"",
"language":"Language"
}
5 changes: 4 additions & 1 deletion locales/zh-CN.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ module.exports = {
"reboot":"重启",
"proxy_paths":"中转路径",
"proxy_server":"中转服务器",
"proxy_server_placeholder":"留空使用本机中转"
"proxy_server_placeholder":"留空使用本机中转",
"ocr_server":"验证码识别接口",
"ocr_server_placeholder":"留空使用本程序内置接口",
"language":"切换语言"
}
5 changes: 4 additions & 1 deletion locales/zh-TW.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,8 @@ module.exports = {
"reboot":"重啟",
"proxy_paths":"代理路徑",
"proxy_server":"中轉服務器",
"proxy_server_placeholder":""
"proxy_server_placeholder":"",
"ocr_server":"驗證碼識別接口",
"ocr_server_placeholder":"留空使用本程式內置接口",
"language":"切換語言"
}
Loading

0 comments on commit 4680960

Please sign in to comment.