separate image combine logic
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||
|
||||
-- https://stackoverflow.com/questions/4990990/check-if-a-file-exists-with-lua
|
||||
local function file_exists(name)
|
||||
local f = io.open(name,"r")
|
||||
if f~=nil then io.close(f) return true else return false end
|
||||
end
|
||||
|
||||
|
||||
local file_to_check = string.match(ngx.var.request_uri, ".*/(.*)")
|
||||
local file_dir = ngx.var.tmp_file_dir
|
||||
|
||||
local fullpath = file_dir .. "/" .. file_to_check .. ".jpeg";
|
||||
|
||||
ngx.say(file_exists(fullpath))
|
||||
|
||||
+18
-12
@@ -12,7 +12,10 @@ ngx.req.read_body()
|
||||
local req_body = cjson.decode(ngx.req.get_body_data())
|
||||
ngx.log(ngx.INFO, 'REQ_BODY -> ', ngx.req.get_body_data())
|
||||
local data = req_body["payload"]["images"]
|
||||
local combined = file_dir .. "/" .. uuid.generate_v4() .. ".jpeg";
|
||||
|
||||
let combined_uuid = uuid.generate_v4()
|
||||
local combined = file_dir .. "/" .. combined_uuid .. ".jpeg";
|
||||
|
||||
local len = table.getn(data)
|
||||
if len == 0 then
|
||||
ngx.status = 500
|
||||
@@ -35,16 +38,19 @@ end
|
||||
|
||||
local cmd = convert .. " -append " .. table.concat(origin, " ") .. " " .. combined
|
||||
ngx.log(ngx.INFO, 'CMD -> ', cmd)
|
||||
local result, _, code = os.execute(cmd)
|
||||
if result and code == 0 then
|
||||
io.popen(cmd)
|
||||
|
||||
ngx.log(ngx.INFO, "IMAGE COMBINED -> ", combined)
|
||||
ngx.say(combined_uuid)
|
||||
|
||||
ngx.log(ngx.INFO, "Upload combined image " .. combined .. " to upyun .")
|
||||
|
||||
upyun_upload.upload(combined)
|
||||
|
||||
else
|
||||
ngx.status = 500
|
||||
ngx.log(ngx.ERR, "IMAGE COMBINE *FAILED*")
|
||||
end
|
||||
-- local result, _, code = os.execute(cmd)
|
||||
--
|
||||
-- if result and code == 0 then
|
||||
-- ngx.log(ngx.INFO, "IMAGE COMBINED -> ", combined)
|
||||
--
|
||||
-- ngx.log(ngx.INFO, "Upload combined image " .. combined .. " to upyun .")
|
||||
--
|
||||
-- upyun_upload.upload(combined)
|
||||
-- else
|
||||
-- ngx.status = 500
|
||||
-- ngx.log(ngx.ERR, "IMAGE COMBINE *FAILED*")
|
||||
-- end
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||
|
||||
local upyun_upload = require("upyun_upload")
|
||||
|
||||
local file_to_upload = string.match(ngx.var.request_uri, ".*/(.*)")
|
||||
local file_dir = ngx.var.tmp_file_dir
|
||||
local fullpath = file_dir .. "/" .. file_to_upload .. ".jpeg";
|
||||
|
||||
upyun_upload.upload(fullpath)
|
||||
Reference in New Issue
Block a user