restruct project
This commit is contained in:
@@ -19,6 +19,7 @@ server {
|
|||||||
set $upyun_bucket "alchemy";
|
set $upyun_bucket "alchemy";
|
||||||
set $upyun_directory "music-room";
|
set $upyun_directory "music-room";
|
||||||
set $upyun_cdn "https://upyun.alchemy-studio.cn/";
|
set $upyun_cdn "https://upyun.alchemy-studio.cn/";
|
||||||
|
set $upyun_domain "https://upyun.alchemy-studio.cn";
|
||||||
set $wx_domain "wx.alchemy-studio.cn";
|
set $wx_domain "wx.alchemy-studio.cn";
|
||||||
set $upt_secret "0D32E581A445404FA4C306709724FA07";
|
set $upt_secret "0D32E581A445404FA4C306709724FA07";
|
||||||
set $upt_duration 3600;
|
set $upt_duration 3600;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ server {
|
|||||||
set $upyun_bucket "moicen";
|
set $upyun_bucket "moicen";
|
||||||
set $upyun_directory "music-room";
|
set $upyun_directory "music-room";
|
||||||
set $upyun_cdn "https://upyun.dev.moicen.com/";
|
set $upyun_cdn "https://upyun.dev.moicen.com/";
|
||||||
|
set $upyun_domain "https://upyun.alchemy-studio.cn";
|
||||||
set $wx_domain "dev.wx.moicen.com";
|
set $wx_domain "dev.wx.moicen.com";
|
||||||
set $upt_secret "0D32E581A445404FA4C306709724FA07";
|
set $upt_secret "0D32E581A445404FA4C306709724FA07";
|
||||||
set $upt_duration 3600;
|
set $upt_duration 3600;
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ server {
|
|||||||
set $upyun_bucket "moicen";
|
set $upyun_bucket "moicen";
|
||||||
set $upyun_directory "music-room";
|
set $upyun_directory "music-room";
|
||||||
set $upyun_cdn "https://upyun.dev.moicen.com/";
|
set $upyun_cdn "https://upyun.dev.moicen.com/";
|
||||||
|
set $upyun_domain "https://upyun.alchemy-studio.cn";
|
||||||
set $wx_domain "dev.wx.moicen.com";
|
set $wx_domain "dev.wx.moicen.com";
|
||||||
set $upt_secret "0D32E581A445404FA4C306709724FA07";
|
set $upt_secret "0D32E581A445404FA4C306709724FA07";
|
||||||
set $upt_duration 3600;
|
set $upt_duration 3600;
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
# Print table
|
||||||
|
opm get DevonStrawn/Penlight
|
||||||
|
|
||||||
|
# JWT
|
||||||
|
opm get SkyLothar/lua-resty-jwt
|
||||||
|
|
||||||
|
# Http client
|
||||||
|
opm get ledgetech/lua-resty-http
|
||||||
|
|
||||||
|
# UUID
|
||||||
|
opm get thibaultcha/lua-resty-jit-uuid
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
-- 指定模块引用目录,否则无法加载同目录下的其他文件
|
||||||
|
--package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
|
||||||
|
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||||
|
|
||||||
|
local _M = {}
|
||||||
|
|
||||||
|
function _M.upyun_download(httpc, Upt, pl, uri)
|
||||||
|
|
||||||
|
ngx.log(ngx.INFO, "UPYUN DOWNLOAD : URI -> " .. uri)
|
||||||
|
|
||||||
|
local upt = Upt.upt(uri)
|
||||||
|
ngx.log(ngx.INFO, "UPYUN DOWNLOAD : UPT -> " .. upt)
|
||||||
|
|
||||||
|
local remote_url = ngx.var.upyun_domain .. uri .. "?_upt=" .. upt
|
||||||
|
ngx.log(ngx.INFO, "UPYUN DOWNLOAD : REMOTE_URL -> " .. remote_url)
|
||||||
|
|
||||||
|
-- ngx.log(ngx.INFO, "REQUEST UPYUN DOWNLOAD : HTTPC -> " .. pl.write(httpc))
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return _M
|
||||||
+15
-47
@@ -1,56 +1,24 @@
|
|||||||
--➤ curl 'http://admin.localhost:8088/api/ngx/upyun_download?uri=%2Fmusic-room%2F17c832cb-bc6b-41f7-96cd-190b7fe4a3d7.jpeg'
|
-- 本地测试命令 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';
|
||||||
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
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 pl = require "pl.pretty"
|
||||||
|
local http = require 'resty.http'
|
||||||
local uri = ngx.unescape_uri(ngx.var.arg_uri)
|
local yun_download = require("lib.upyun_download")
|
||||||
|
local Upt = require("lib.upt")
|
||||||
-- 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 httpc = http:new()
|
||||||
|
|
||||||
-- local no_exception, resp, resp_err = pcall(httpc.request_uri, httpc, remote_url,
|
-- ngx.log(ngx.INFO, "REQUEST UPYUN DOWNLOAD : HTTPC -> " .. pl.write(httpc))
|
||||||
-- {
|
|
||||||
-- 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,
|
local function upyun_download_file()
|
||||||
{
|
|
||||||
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 uri = ngx.unescape_uri(ngx.var.arg_uri)
|
||||||
-- local xml = ai-api.convert_mxml_to_xml(resp.body)
|
ngx.log(ngx.INFO, "REQUEST UPYUN DOWNLOAD : URI -> " .. uri)
|
||||||
-- ngx.log(xml)
|
yun_download.upyun_download(httpc, Upt, pl, uri)
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
upyun_download_file()
|
||||||
|
|
||||||
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()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user