convert audio

This commit is contained in:
moicen
2022-01-14 14:11:17 +08:00
committed by 阿男
parent 6580d73d31
commit fd39e6c8ae
6 changed files with 935 additions and 57 deletions
+41 -3
View File
@@ -1,6 +1,8 @@
local cjson = require "cjson"
local uuid = require "resty.jit-uuid"
local uuid = require "resty.jit-uuid"
local http = require "resty.http"
local upyun_token = require('upyun_token')
local TaskTypes = {
NOOP = 'NOOP',
@@ -89,7 +91,44 @@ local function get_wx_media(media_id)
return saved_audio;
end
local function upload(filename)
local upyun_api = ngx.var.upyun_api
local token = upyun_token(filename)
local file, err = io.open(saved_audio, 'w')
local form = {
["Authorization"] = token.token,
["file"] = file,
["policy"] = token.policy
}
local res, err = httpc:request_uri(
upyun_api,
{
ssl_verify = false, -- 设置参数 ssl_verify 为false 不校验ssl证书
method = "POST",
body = form,
}
)
if res == nil then
ngx.log(ngx.ERR, "FAILED TO CONNECT TO *Upyun*", err)
ngx.say(err)
ngx.exit(500)
end
if 200 ~= res.status then
ngx.log(ngx.ERR, 'GET WECHET MEDIA *FAILED*', err)
ngx.say(err)
ngx.exit(res.status)
end
end
local function convert()
-- mock for test
local res = cjson.encode({
r = true, d = "https://upyun.alchemy-studio.cn/daily-music/audios/Song-of-joy.mp3"
})
ngx.say(res)
ngx.exit(200)
local file_dir = ngx.var.tmp_file_dir
ngx.req.read_body()
local req_body = cjson.decode(ngx.req.get_body_data())
@@ -108,7 +147,7 @@ local function convert()
local result, _, code = os.execute(cmd)
if result and code == 0 then
ngx.log(ngx.INFO, "result -> ", result);
ngx.say(result)
upload(result)
else
ngx.status = 500
ngx.log(ngx.ERR, "AUDIO CONVERT *FAILED*")
@@ -118,4 +157,3 @@ local function convert()
end
convert();