add upyun_download
This commit is contained in:
@@ -95,4 +95,8 @@ server {
|
|||||||
location /api/v1/uc/ {
|
location /api/v1/uc/ {
|
||||||
proxy_pass http://127.0.0.1:3000/api/v1/uc/;
|
proxy_pass http://127.0.0.1:3000/api/v1/uc/;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /api/ngx/upyun_download {
|
||||||
|
content_by_lua_file $resty_loc/nginx/scripts/upyun_download.lua;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
server {
|
server {
|
||||||
# https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx#
|
# https://serverfault.com/questions/798734/use-variable-for-server-name-in-nginx#
|
||||||
# server_name $servername;
|
# server_name $servername;
|
||||||
server_name "test.localhost";
|
server_name "test2.localhost";
|
||||||
listen 8088;
|
listen 8088;
|
||||||
|
|
||||||
set $resty_loc "/usr/local/opt/openresty";
|
set $resty_loc "/usr/local/opt/openresty";
|
||||||
|
|||||||
@@ -0,0 +1,56 @@
|
|||||||
|
--➤ curl 'http://admin.localhost:8088/api/ngx/upyun_download?uri=%2Fmusic-room%2F17c832cb-bc6b-41f7-96cd-190b7fe4a3d7.jpeg'
|
||||||
|
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||||
|
|
||||||
|
local Upt = require("lib.upt")
|
||||||
|
-- local yun = require("lib.upyun")
|
||||||
|
local http = require 'resty.http'
|
||||||
|
local pl = require "pl.pretty"
|
||||||
|
|
||||||
|
local uri = ngx.unescape_uri(ngx.var.arg_uri)
|
||||||
|
|
||||||
|
-- ngx.log(ngx.INFO, 'Upyun download uri -> ' .. uri)
|
||||||
|
ngx.log(ngx.INFO, "URI -> " .. uri)
|
||||||
|
|
||||||
|
-- local encode_http_uri = ngx.escape_uri(uri)
|
||||||
|
--local encode_http_uri = uri
|
||||||
|
--ngx.log(ngx.INFO, encode_http_uri)
|
||||||
|
|
||||||
|
local _upt = Upt.upt(uri)
|
||||||
|
|
||||||
|
ngx.log(ngx.INFO, "UPT -> " .. _upt)
|
||||||
|
|
||||||
|
local remote_url = "https://upyun.alchemy-studio.cn" .. uri .. "?_upt=" .. _upt
|
||||||
|
|
||||||
|
ngx.log(ngx.INFO, "REMOTE_URL -> " .. remote_url)
|
||||||
|
|
||||||
|
local httpc = http:new()
|
||||||
|
|
||||||
|
-- local no_exception, resp, resp_err = pcall(httpc.request_uri, httpc, remote_url,
|
||||||
|
-- {
|
||||||
|
-- ssl_verify = false, -- 设置参数 ssl_verify 为false 不校验ssl证书
|
||||||
|
-- method = "GET",
|
||||||
|
-- })
|
||||||
|
--
|
||||||
|
-- ngx.log("RESP -> ", pl.write(resp)
|
||||||
|
--
|
||||||
|
-- local file = assert(io.open('test.jpg', 'wb')
|
||||||
|
-- f:write(resp.body)
|
||||||
|
--
|
||||||
|
-- f:close()
|
||||||
|
|
||||||
|
local no_exception, resp, resp_err = pcall(httpc.request_uri, httpc, remote_url,
|
||||||
|
{
|
||||||
|
ssl_verify = false, -- 设置参数 ssl_verify 为false 不校验ssl证书
|
||||||
|
method = "GET",
|
||||||
|
})
|
||||||
|
|
||||||
|
--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)
|
||||||
|
|
||||||
|
ngx.log(ngx.INFO, "RESP -> ", pl.write(resp))
|
||||||
|
---- save the content to a file
|
||||||
|
local f = assert(io.open('/tmp/test.jpg', 'wb')) -- open in "binary" mode
|
||||||
|
f:write(resp.body)
|
||||||
|
--
|
||||||
|
f:close()
|
||||||
@@ -10,6 +10,6 @@ local r = nested_e()
|
|||||||
ngx.log(ngx.INFO, r)
|
ngx.log(ngx.INFO, r)
|
||||||
ngx.say("OK")
|
ngx.say("OK")
|
||||||
|
|
||||||
-- ➤ curl test.localhost:8088/api/ngx/test/nested_exit
|
-- ➤ curl test2.localhost:8088/api/ngx/test/nested_exit
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user