fix: 取消了回调的设计, 修复了部分bug
将回调的接口换成了run的函数接口, 修复了在线查询, 自动命令, 窗口显示的bug
This commit is contained in:
@ -1,24 +1,20 @@
|
||||
local youdao = require("Trans").conf.engine.youdao
|
||||
local appKey = youdao.appKey
|
||||
local appPasswd = youdao.appPasswd
|
||||
local uri = 'https://openapi.youdao.com/api'
|
||||
local salt = tostring(math.random(bit.rshift(1, 5)))
|
||||
|
||||
|
||||
local ok, curl = pcall(require, 'plenary.curl')
|
||||
if not ok then
|
||||
error('plenary not found')
|
||||
end
|
||||
local salt = tostring(math.random(bit.lshift(1, 15)))
|
||||
local appid = youdao.appid
|
||||
local appPasswd = youdao.appPasswd
|
||||
|
||||
local post = require('Trans.util.curl').POST
|
||||
|
||||
local function get_field(word)
|
||||
-- local to = isEn and 'zh-'
|
||||
local len = #word
|
||||
local curtime = tostring(os.time())
|
||||
local input = len > 20 and
|
||||
word:sub(1, 10) .. len .. word:sub(-10) or word
|
||||
|
||||
-- sign=sha256(应用ID+input+salt+curtime+应用密钥);
|
||||
local hash = appKey .. input .. salt .. curtime .. appPasswd
|
||||
local hash = appid .. input .. salt .. curtime .. appPasswd
|
||||
local sign = vim.fn.sha256(hash)
|
||||
|
||||
return {
|
||||
@ -26,7 +22,7 @@ local function get_field(word)
|
||||
from = 'auto',
|
||||
to = 'zh-CHS',
|
||||
signType = 'v3',
|
||||
appKey = appKey,
|
||||
appKey = appid,
|
||||
salt = salt,
|
||||
curtime = curtime,
|
||||
sign = sign,
|
||||
@ -35,14 +31,15 @@ end
|
||||
|
||||
return function(word)
|
||||
-- return result
|
||||
local field = get_field(word)
|
||||
local output = curl.post(uri, {
|
||||
body = field,
|
||||
})
|
||||
if output.exit == 0 and output.status == 200 then
|
||||
local result = vim.fn.json_decode(output.body)
|
||||
if result and result.errorCode == 0 then
|
||||
--- TODO :
|
||||
end
|
||||
end
|
||||
-- local field = get_field(word)
|
||||
-- local output = post(uri, {
|
||||
-- body = field,
|
||||
-- })
|
||||
|
||||
-- if output.exit == 0 and output.status == 200 then
|
||||
-- local result = vim.fn.json_decode(output.body)
|
||||
-- if result and result.errorCode == 0 then
|
||||
-- --- TODO :
|
||||
-- end
|
||||
-- end
|
||||
end
|
||||
|
Reference in New Issue
Block a user