57 lines
1.8 KiB
Lua
57 lines
1.8 KiB
Lua
local cjson = require "cjson"
|
|
local http = require "resty.http"
|
|
|
|
local TaskTypes = {
|
|
NOOP = 'NOOP',
|
|
CONVERT_AUDIO_FILE = "CONVERT_AUDIO_FILE"
|
|
}
|
|
|
|
local httpc = http.new()
|
|
ngx.req.read_body()
|
|
local req_body = cjson.decode(ngx.req.get_body_data())
|
|
print('req_body...', ngx.req.get_body_data())
|
|
local media_id = req_body['media_id']
|
|
local authHeader = ngx.req.get_headers().Authorization
|
|
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
|
local htyHost = ngx.req.get_headers().HtyHost
|
|
|
|
local function create_task()
|
|
local task_server = ngx.var.task_server
|
|
local remote_url = string.format("%s/api/v1/ts/create_task", task_server)
|
|
ngx.log(ngx.INFO, 'remote_url -> ', remote_url)
|
|
ngx.log(ngx.INFO, 'Authorization -> ', authHeader)
|
|
ngx.log(ngx.INFO, 'HtySudoerToken -> ', sudoerToken)
|
|
ngx.log(ngx.INFO, 'HtyHost -> ', htyHost)
|
|
|
|
local body_text = cjson.encode({ task_type = TaskTypes.CONVERT_AUDIO_FILE, payload = { media_id = media_id } })
|
|
|
|
ngx.log(ngx.INFO, 'AUDIO_CONVERT *body_text* ->', body_text)
|
|
local res, err = httpc:request_uri(
|
|
remote_url,
|
|
{
|
|
ssl_verify = false, -- 设置参数 ssl_verify 为false 不校验ssl证书
|
|
method = "POST",
|
|
headers = {
|
|
["Content-Type"] = "application/json",
|
|
["Authorization"] = authHeader,
|
|
["HtySudoerToken"] = sudoerToken,
|
|
["HtyHost"] = htyHost
|
|
},
|
|
body = body_text,
|
|
}
|
|
)
|
|
if res == nil then
|
|
ngx.log(ngx.ERR, "FAILED TO CONNECT TO *TASK_SERVER*", err)
|
|
end
|
|
|
|
if 201 ~= res.status then
|
|
ngx.log(ngx.ERR, "TASK CREATE *FAILED*", res.body)
|
|
end
|
|
ngx.say(res.body)
|
|
ngx.exit(res.status)
|
|
end
|
|
|
|
create_task()
|
|
|
|
|