2022-08-23 23:48:00 +08:00
|
|
|
-- retrieve the content of a URL
|
2022-08-24 00:26:46 +08:00
|
|
|
local http = require "resty.http"
|
|
|
|
|
local pl = require "pl.pretty"
|
|
|
|
|
--local Upt = require "lib/upt"
|
|
|
|
|
local httpc = http:new()
|
2022-08-23 23:48:00 +08:00
|
|
|
|
2022-08-24 00:26:46 +08:00
|
|
|
local uri = "/music-room/17c832cb-bc6b-41f7-96cd-190b7fe4a3d7.jpeg"
|
|
|
|
|
local secret = "0D32E581A445404FA4C306709724FA07"
|
|
|
|
|
local duration = "3600"
|
|
|
|
|
local etime = os.time() + duration
|
|
|
|
|
local sign = ngx.md5(secret .. '&' .. etime .. '&' .. uri)
|
|
|
|
|
--ngx.log(ngx.INFO, 'sign...' .. sign .. ' etime..' .. etime)
|
|
|
|
|
|
|
|
|
|
ngx.say('sign...' .. sign .. ' etime..' .. etime)
|
|
|
|
|
|
|
|
|
|
local _upt = string.sub(sign, 13, 13 + 7) .. etime
|
|
|
|
|
|
|
|
|
|
--local _upt = Upt.upt()
|
|
|
|
|
|
|
|
|
|
ngx.say("UPT -> ", _upt)
|
2022-08-23 23:48:00 +08:00
|
|
|
|
2022-08-24 00:26:46 +08:00
|
|
|
local remote_url = "https://upyun.alchemy-studio.cn/music-room/17c832cb-bc6b-41f7-96cd-190b7fe4a3d7.jpeg?_upt=" .. _upt
|
|
|
|
|
|
|
|
|
|
local no_exception, resp, resp_err = pcall(httpc.request_uri, httpc, remote_url,
|
|
|
|
|
{
|
|
|
|
|
ssl_verify = false, -- 设置参数 ssl_verify 为false 不校验ssl证书
|
|
|
|
|
method = "GET",
|
|
|
|
|
})
|
|
|
|
|
|
2022-08-24 00:29:59 +08:00
|
|
|
--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.say(xml)
|
|
|
|
|
|
|
|
|
|
--ngx.say("RESP -> ", pl.write(resp))
|
|
|
|
|
------ save the content to a file
|
|
|
|
|
--local f = assert(io.open('test.jpg', 'wb')) -- open in "binary" mode
|
|
|
|
|
--f:write(resp.body)
|
|
|
|
|
----
|
|
|
|
|
--f:close()
|