From 3d2e03be827105e7d17c9545cf1421b6cc87c939 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E9=80=B8=E8=BE=B0?= Date: Tue, 7 Sep 2021 21:54:52 +0800 Subject: [PATCH] Handle error with combine (#16) * check if failed when combine image * add status code when combine failed --- prod/upload/combine.lua | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/prod/upload/combine.lua b/prod/upload/combine.lua index 96353d2..feb50e6 100644 --- a/prod/upload/combine.lua +++ b/prod/upload/combine.lua @@ -13,20 +13,24 @@ local origin = {} for i = 1, len do origin[i] = file_dir .. "/" .. data[i] .. " " end --- in linux +-- linux local magick = "/usr/local/ImageMagick/bin/magick" local tmp = io.open(magick,"r") if tmp == nil then - -- in mac os + -- mac os magick = "/usr/local/bin/magick" else io.close(tmp) end -local file = io.popen(magick .. " convert -append " .. table.concat(origin, " ") .. " " .. combined) -file:read("*all") -file:close() -file = io.open(combined) -local content = file:read("*all") -file:close() -os.remove(combined) -ngx.say(content) \ No newline at end of file + +local result, _, code = os.execute(magick .. " convert -append " .. table.concat(origin, " ") .. " " .. combined) +if result and code == 0 then + local file = io.open(combined) + local content = file:read("*all") + file:close() + os.remove(combined) + ngx.say(content) +else + ngx.status = 500 + ngx.say("image combine failed.") +end \ No newline at end of file