2022-02-07 19:04:21 +08:00
|
|
|
-- 指定模块引用目录,否则无法加载同目录下的其他文件
|
2022-02-08 13:57:15 +08:00
|
|
|
--package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
|
2022-02-08 14:14:57 +08:00
|
|
|
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
2022-02-08 13:57:15 +08:00
|
|
|
|
2021-12-30 00:46:59 +08:00
|
|
|
local uuid = require "resty.jit-uuid"
|
|
|
|
|
local cjson = require "cjson"
|
2022-08-23 00:32:24 +08:00
|
|
|
local pl = require "pl.pretty"
|
|
|
|
|
|
2022-08-31 23:42:45 +08:00
|
|
|
local http = require "resty.http"
|
|
|
|
|
local verify = require('lib.jwt_verify')
|
|
|
|
|
|
|
|
|
|
local httpc = http:new()
|
|
|
|
|
local authHeader = ngx.req.get_headers().Authorization
|
|
|
|
|
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
|
|
|
|
|
|
|
|
|
verify(httpc, authHeader, sudoerToken)
|
|
|
|
|
|
2021-09-06 18:56:59 +08:00
|
|
|
uuid.seed()
|
|
|
|
|
|
|
|
|
|
local file_dir = ngx.var.tmp_file_dir
|
|
|
|
|
ngx.req.read_body()
|
|
|
|
|
local req_body = cjson.decode(ngx.req.get_body_data())
|
2021-09-24 20:18:39 +08:00
|
|
|
ngx.log(ngx.INFO, 'REQ_BODY -> ', ngx.req.get_body_data())
|
2022-02-11 22:16:59 +08:00
|
|
|
local data = req_body["payload"]["images"]
|
2022-03-08 21:59:25 +08:00
|
|
|
|
2022-03-09 01:57:15 +08:00
|
|
|
local combined_uuid = uuid.generate_v4()
|
2022-08-22 23:59:02 +08:00
|
|
|
local combined = file_dir .. "/" .. combined_uuid .. ".png";
|
2022-03-08 21:59:25 +08:00
|
|
|
|
2021-09-06 18:56:59 +08:00
|
|
|
local len = table.getn(data)
|
2021-09-24 20:18:39 +08:00
|
|
|
if len == 0 then
|
|
|
|
|
ngx.status = 500
|
2021-11-20 03:37:12 +08:00
|
|
|
ngx.log(ngx.ERR, "No images to combine!")
|
2021-12-30 00:46:59 +08:00
|
|
|
return ;
|
2021-09-24 20:18:39 +08:00
|
|
|
end
|
2022-08-23 00:04:32 +08:00
|
|
|
|
2021-09-06 18:56:59 +08:00
|
|
|
local origin = {}
|
2022-08-23 00:04:32 +08:00
|
|
|
|
2021-09-12 11:01:41 +08:00
|
|
|
-- 从 nginx 变量取
|
2021-09-12 11:29:30 +08:00
|
|
|
local convert = ngx.var.convert
|
2021-09-12 11:01:41 +08:00
|
|
|
|
2021-12-30 00:46:59 +08:00
|
|
|
if not convert then
|
|
|
|
|
ngx.status = 500
|
|
|
|
|
ngx.log(ngx.ERR, "ImageMagick NOT FOUND.")
|
|
|
|
|
return
|
2021-09-06 18:56:59 +08:00
|
|
|
end
|
2021-09-07 21:54:52 +08:00
|
|
|
|
2022-08-23 00:04:32 +08:00
|
|
|
for i = 1, len do
|
|
|
|
|
ngx.log(ngx.INFO, "COMBINE FILE -> ", data[i])
|
2022-08-23 00:35:33 +08:00
|
|
|
incoming = file_dir .. "/" .. data[i]
|
|
|
|
|
origin[i] = incoming .. ".png "
|
|
|
|
|
local cmd = convert .. " -resize 1280x " .. incoming .. " " .. origin[i]
|
2022-08-23 00:32:24 +08:00
|
|
|
ngx.log(ngx.INFO, 'CMD RESIZE -> ', cmd)
|
|
|
|
|
local handle = io.popen(cmd)
|
|
|
|
|
local result = handle:read("*a")
|
|
|
|
|
ngx.log(ngx.INFO, 'CMD RESIZE -> RESULT ', pl.dump(result))
|
|
|
|
|
handle:close()
|
|
|
|
|
|
2022-08-23 00:04:32 +08:00
|
|
|
end
|
|
|
|
|
|
2021-12-30 00:46:59 +08:00
|
|
|
local cmd = convert .. " -append " .. table.concat(origin, " ") .. " " .. combined
|
2022-08-22 23:59:02 +08:00
|
|
|
ngx.log(ngx.INFO, 'CMD APPEND -> ', cmd)
|
2022-03-08 21:59:25 +08:00
|
|
|
io.popen(cmd)
|
|
|
|
|
ngx.say(combined_uuid)
|