separate image combine logic
This commit is contained in:
@@ -42,10 +42,21 @@ server {
|
|||||||
location /api/ngx/image/upload {
|
location /api/ngx/image/upload {
|
||||||
content_by_lua_file $resty_loc/nginx/scripts/upload.lua;
|
content_by_lua_file $resty_loc/nginx/scripts/upload.lua;
|
||||||
}
|
}
|
||||||
|
|
||||||
#Combine image files
|
#Combine image files
|
||||||
location /api/ngx/image/combine {
|
location /api/ngx/image/combine {
|
||||||
content_by_lua_file $resty_loc/nginx/scripts/combine.lua;
|
content_by_lua_file $resty_loc/nginx/scripts/combine.lua;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
location /api/ngx/image/check {
|
||||||
|
content_by_lua_file $resty_loc/nginx/scripts/check_file.lua;
|
||||||
|
}
|
||||||
|
|
||||||
|
location /api/ngx/image/upload_combined {
|
||||||
|
content_by_lua_file $resty_loc/nginx/scripts/upload_combined_image.lua;
|
||||||
|
}
|
||||||
|
|
||||||
#Audio file download
|
#Audio file download
|
||||||
location /api/ngx/audio/upload {
|
location /api/ngx/audio/upload {
|
||||||
content_by_lua_file $resty_loc/nginx/scripts/upload_audio.lua;
|
content_by_lua_file $resty_loc/nginx/scripts/upload_audio.lua;
|
||||||
|
|||||||
@@ -13,5 +13,9 @@ server {
|
|||||||
location /api/ngx/test/popen {
|
location /api/ngx/test/popen {
|
||||||
content_by_lua_file $resty_loc/nginx/scripts/tests/popen.lua;
|
content_by_lua_file $resty_loc/nginx/scripts/tests/popen.lua;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
location /api/ngx/test/uri {
|
||||||
|
content_by_lua_file $resty_loc/nginx/scripts/tests/uri.lua;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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())
|
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 data = req_body["payload"]["images"]
|
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)
|
local len = table.getn(data)
|
||||||
if len == 0 then
|
if len == 0 then
|
||||||
ngx.status = 500
|
ngx.status = 500
|
||||||
@@ -35,16 +38,19 @@ end
|
|||||||
|
|
||||||
local cmd = convert .. " -append " .. table.concat(origin, " ") .. " " .. combined
|
local cmd = convert .. " -append " .. table.concat(origin, " ") .. " " .. combined
|
||||||
ngx.log(ngx.INFO, 'CMD -> ', cmd)
|
ngx.log(ngx.INFO, 'CMD -> ', cmd)
|
||||||
local result, _, code = os.execute(cmd)
|
io.popen(cmd)
|
||||||
if result and code == 0 then
|
|
||||||
|
|
||||||
ngx.log(ngx.INFO, "IMAGE COMBINED -> ", combined)
|
ngx.say(combined_uuid)
|
||||||
|
|
||||||
ngx.log(ngx.INFO, "Upload combined image " .. combined .. " to upyun .")
|
-- local result, _, code = os.execute(cmd)
|
||||||
|
--
|
||||||
upyun_upload.upload(combined)
|
-- if result and code == 0 then
|
||||||
|
-- ngx.log(ngx.INFO, "IMAGE COMBINED -> ", combined)
|
||||||
else
|
--
|
||||||
ngx.status = 500
|
-- ngx.log(ngx.INFO, "Upload combined image " .. combined .. " to upyun .")
|
||||||
ngx.log(ngx.ERR, "IMAGE COMBINE *FAILED*")
|
--
|
||||||
end
|
-- 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)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
ngx.say(string.match(ngx.var.request_uri, ".*/(.*)"))
|
||||||
Reference in New Issue
Block a user