Files
resty_functions/scripts/upyun_download.lua
T

26 lines
877 B
Lua
Raw Normal View History

2022-08-25 17:27:08 +08:00
-- 本地测试命令 curl 'http://admin.localhost:8088/api/ngx/upyun_download?uri=/music-room/17c832cb-bc6b-41f7-96cd-190b7fe4a3d7.jpeg'
-- 指定模块引用目录,否则无法加载同目录下的其他文件
--package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
2022-08-24 01:05:21 +08:00
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
local pl = require "pl.pretty"
2022-08-25 17:27:08 +08:00
local http = require 'resty.http'
2022-08-25 19:15:32 +08:00
local cjson = require "cjson"
2022-08-25 17:27:08 +08:00
local yun_download = require("lib.upyun_download")
local Upt = require("lib.upt")
2022-08-24 01:05:21 +08:00
2022-08-25 17:27:08 +08:00
local httpc = http:new()
2022-08-24 01:05:21 +08:00
2022-08-25 17:27:08 +08:00
-- ngx.log(ngx.INFO, "REQUEST UPYUN DOWNLOAD : HTTPC -> " .. pl.write(httpc))
2022-08-24 01:05:21 +08:00
2022-08-25 17:27:08 +08:00
local function upyun_download_file()
2022-08-24 01:05:21 +08:00
2022-08-25 17:27:08 +08:00
local uri = ngx.unescape_uri(ngx.var.arg_uri)
ngx.log(ngx.INFO, "REQUEST UPYUN DOWNLOAD : URI -> " .. uri)
2022-08-25 19:15:32 +08:00
yun_download.upyun_download(httpc, cjson, Upt, pl, uri)
2022-08-24 01:05:21 +08:00
2022-08-25 17:27:08 +08:00
end
2022-08-24 01:05:21 +08:00
2022-08-25 17:27:08 +08:00
upyun_download_file()
2022-08-24 01:05:21 +08:00