diff --git a/conf/alchemy/admin.conf b/conf/alchemy/admin.conf index 823978c..9d8be2c 100644 --- a/conf/alchemy/admin.conf +++ b/conf/alchemy/admin.conf @@ -18,7 +18,6 @@ server { set $upyun_password "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN"; set $upyun_bucket "alchemy"; set $upyun_directory "music-room"; - set $upyun_cdn "https://upyun.alchemy-studio.cn/"; set $upyun_domain "https://upyun.alchemy-studio.cn"; set $wx_domain "wx.alchemy-studio.cn"; set $upt_secret "0D32E581A445404FA4C306709724FA07"; diff --git a/conf/local_linux/admin.conf b/conf/local_linux/admin.conf index fa5eab6..5a9beda 100644 --- a/conf/local_linux/admin.conf +++ b/conf/local_linux/admin.conf @@ -14,7 +14,6 @@ server { set $upyun_password "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN"; set $upyun_bucket "moicen"; set $upyun_directory "music-room"; - set $upyun_cdn "https://upyun.dev.moicen.com/"; set $upyun_domain "https://upyun.alchemy-studio.cn"; set $wx_domain "dev.wx.moicen.com"; set $upt_secret "0D32E581A445404FA4C306709724FA07"; diff --git a/conf/local_macos/admin.conf b/conf/local_macos/admin.conf index 6cefb91..4f6e2cb 100644 --- a/conf/local_macos/admin.conf +++ b/conf/local_macos/admin.conf @@ -14,7 +14,6 @@ server { set $upyun_password "NyJ51zRwFApY9Wo9EHJMrb8GI9YtvpVN"; set $upyun_bucket "moicen"; set $upyun_directory "music-room"; - set $upyun_cdn "https://upyun.dev.moicen.com/"; set $upyun_domain "https://upyun.alchemy-studio.cn"; set $wx_domain "dev.wx.moicen.com"; set $upt_secret "0D32E581A445404FA4C306709724FA07"; diff --git a/scripts/lib/upyun_download.lua b/scripts/lib/upyun_download.lua index b8e6986..3160c9d 100644 --- a/scripts/lib/upyun_download.lua +++ b/scripts/lib/upyun_download.lua @@ -4,7 +4,7 @@ package.path = package.path .. ';/?.lua'; local _M = {} -function _M.upyun_download(httpc, Upt, pl, uri) +function _M.upyun_download(httpc, cjson, Upt, pl, uri) ngx.log(ngx.INFO, "UPYUN DOWNLOAD : URI -> " .. uri) @@ -22,6 +22,30 @@ function _M.upyun_download(httpc, Upt, pl, uri) method = "GET", }) + ngx.log(ngx.INFO, "RESP -> ", pl.write(resp)) + if no_exception == true then + if 200 ~= resp.status then + ngx.log(ngx.ERR, "UPYUN DOWNLOAD *FAILED*", pl.write(resp_err)) + ngx.status = resp.status + ngx.say(pl.write(resp_err)) + ngx.exit(resp.status) + else + ngx.log(ngx.ERR, "RESP IS OK -> ", pl.write(resp.body)) + -- return cjson.decode(resp.body).d + end + else + if resp == nil then + resp = "" + end + ngx.log(ngx.ERR, "FAILED TO CONNECT TO *UPYUN*: httpc throws runtime error, please check log. / ", pl.write(resp)) + -- 必须先设置ngx.status,否则ngx.say之后就直接被设置为200了,不会再被exit设为401 + -- https://github.com/openresty/lua-resty-redis/issues/15 + ngx.status = 401 + ngx.say(cjson.encode({r = false, d = "UpyunDownloadErr"})) + ngx.exit(401) + end + + -- TODO: send resp.body to Flask API (ai-api) -> convert_mxml_to_xml() -> XML string -- local xml = ai-api.convert_mxml_to_xml(resp.body) -- ngx.log(xml) diff --git a/scripts/lib/upyun_upload.lua b/scripts/lib/upyun_upload.lua index 3ded055..405f31b 100644 --- a/scripts/lib/upyun_upload.lua +++ b/scripts/lib/upyun_upload.lua @@ -35,7 +35,7 @@ function upyun_upload.upload(filepath, filename) return else ngx.status = 200 - local fullpath = ngx.var.upyun_cdn .. directory .. "/" .. filename + local fullpath = ngx.var.$upyun_domain .. "/" .. directory .. "/" .. filename ngx.log(ngx.INFO, "UPYUN URL -> ", fullpath) ngx.say(fullpath) end diff --git a/scripts/upyun_download.lua b/scripts/upyun_download.lua index 6b6c3a4..af7e8f2 100644 --- a/scripts/upyun_download.lua +++ b/scripts/upyun_download.lua @@ -5,6 +5,7 @@ package.path = package.path .. ';/?.lua'; local pl = require "pl.pretty" local http = require 'resty.http' +local cjson = require "cjson" local yun_download = require("lib.upyun_download") local Upt = require("lib.upt") @@ -16,7 +17,7 @@ local function upyun_download_file() local uri = ngx.unescape_uri(ngx.var.arg_uri) ngx.log(ngx.INFO, "REQUEST UPYUN DOWNLOAD : URI -> " .. uri) - yun_download.upyun_download(httpc, Upt, pl, uri) + yun_download.upyun_download(httpc, cjson, Upt, pl, uri) end