update
This commit is contained in:
+40
-12
@@ -2,34 +2,44 @@
|
|||||||
--package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
|
--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';
|
||||||
|
|
||||||
|
-- Requires
|
||||||
local uuid = require "resty.jit-uuid"
|
local uuid = require "resty.jit-uuid"
|
||||||
local cjson = require "cjson"
|
local cjson = require "cjson"
|
||||||
local pl = require "pl.pretty"
|
local pl = require "pl.pretty"
|
||||||
|
|
||||||
local http = require "resty.http"
|
local http = require "resty.http"
|
||||||
local verify = require('lib.jwt_verify')
|
local verify = require('lib.jwt_verify')
|
||||||
|
|
||||||
|
-- Verify token
|
||||||
local httpc = http:new()
|
local httpc = http:new()
|
||||||
local authHeader = ngx.req.get_headers().Authorization
|
local authHeader = ngx.req.get_headers().Authorization
|
||||||
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
||||||
|
|
||||||
verify(httpc, authHeader, sudoerToken)
|
verify(httpc, authHeader, sudoerToken)
|
||||||
|
|
||||||
uuid.seed()
|
uuid.seed()
|
||||||
|
|
||||||
|
-- Get ngx var
|
||||||
local file_dir = ngx.var.tmp_file_dir
|
local file_dir = ngx.var.tmp_file_dir
|
||||||
|
|
||||||
|
-- Read request body
|
||||||
ngx.req.read_body()
|
ngx.req.read_body()
|
||||||
local req_body = cjson.decode(ngx.req.get_body_data())
|
local req_body = cjson.decode(ngx.req.get_body_data())
|
||||||
ngx.log(ngx.INFO, 'REQ_BODY -> ', ngx.req.get_body_data())
|
ngx.log(ngx.INFO, 'REQ_BODY -> ', ngx.req.get_body_data())
|
||||||
local image_origin = read_body["payload"]["image_origin"]
|
|
||||||
local images = req_body["payload"]["images"]
|
local images = req_body["payload"]["images"]
|
||||||
|
|
||||||
ngx.log(ngx.INFO, "IMAGE ORIGIN -> ", image_origin)
|
local image_origin = read_body["payload"]["image_origin"]
|
||||||
|
|
||||||
local combined_uuid = uuid.generate_v4()
|
-- Judge payload image origin
|
||||||
local output_filename = combined_uuid .. ".jpeg";
|
if image_origin == "WX" then
|
||||||
local output_filepath = file_dir .. "/" .. output_filename
|
ngx.log(ngx.INFO, "IMAGE ORIGIN -> ", image_origin)
|
||||||
|
elseif image_origin == "LOCAL" then
|
||||||
|
ngx.log(ngx.INFO, "IMAGE ORIGIN -> ", image_origin)
|
||||||
|
else
|
||||||
|
ngx.status = 400
|
||||||
|
ngx.log(ngx.ERR, "COMBINE REQUEST PAYLOAD IMAGES ORIGIN NOT FOUND.")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Judge payload images para length
|
||||||
local len = table.getn(images)
|
local len = table.getn(images)
|
||||||
if len == 0 then
|
if len == 0 then
|
||||||
ngx.status = 500
|
ngx.status = 500
|
||||||
@@ -37,6 +47,20 @@ if len == 0 then
|
|||||||
return ;
|
return ;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- If combine images from WX
|
||||||
|
local wx_download_images = {}
|
||||||
|
if image_origin == "WX" then
|
||||||
|
for i = 1, len do
|
||||||
|
ngx.log(ngx.INFO, "DOWNLOAD WX URL -> ", images[i])
|
||||||
|
wx_download_images[i] = get_wx_media(httpc, images[i], cjson, pl);
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Prepare combined file name and path
|
||||||
|
local combined_uuid = uuid.generate_v4()
|
||||||
|
local output_filename = combined_uuid .. ".jpeg";
|
||||||
|
local output_filepath = file_dir .. "/" .. output_filename
|
||||||
|
|
||||||
local origin = {}
|
local origin = {}
|
||||||
|
|
||||||
-- 从 nginx 变量取
|
-- 从 nginx 变量取
|
||||||
@@ -53,11 +77,15 @@ for i = 1, len do
|
|||||||
local incoming
|
local incoming
|
||||||
|
|
||||||
if image_origin == "WX" then
|
if image_origin == "WX" then
|
||||||
ngx.log(ngx.INFO, "DOWNLOAD WX FILE -> ", images[i])
|
ngx.log(ngx.INFO, "DOWNLOAD WX FILE -> ", wx_download_images[i])
|
||||||
incoming = get_wx_media(httpc, images[i], cjson, pl);
|
incoming = wx_download_images[i]
|
||||||
else
|
elseif image_origin == "LOCAL" then
|
||||||
ngx.log(ngx.INFO, "COMBINE FILE -> ", images[i])
|
ngx.log(ngx.INFO, "LOCAL FILE -> ", images[i])
|
||||||
incoming = file_dir .. "/" .. images[i]
|
incoming = file_dir .. "/" .. images[i]
|
||||||
|
else
|
||||||
|
ngx.status = 400
|
||||||
|
ngx.log(ngx.ERR, "COMBINE REQUEST PAYLOAD IMAGES ORIGIN NOT FOUND.")
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
origin[i] = incoming .. ".png "
|
origin[i] = incoming .. ".png "
|
||||||
|
|||||||
Reference in New Issue
Block a user