add file exists checking in my_uuid
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||
local cjson = require "cjson"
|
||||
local http = require "resty.http"
|
||||
local create_task = require "lib.create_task"
|
||||
local TaskTypes = require 'lib.task_type'
|
||||
local verify = require('lib.jwt_verify')
|
||||
|
||||
local authHeader = ngx.req.get_headers().Authorization
|
||||
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
||||
verify(httpc, authHeader, sudoerToken)
|
||||
|
||||
local httpc = http.new()
|
||||
ngx.req.read_body()
|
||||
local req_body = cjson.decode(ngx.req.get_body_data())
|
||||
print('req_body...', ngx.req.get_body_data())
|
||||
local media_id = req_body['media_id']
|
||||
|
||||
local task_text = cjson.encode({ task_type = TaskTypes.CONVERT_AUDIO_FILE, payload = { media_id = media_id } })
|
||||
create_task(httpc, task_text, authHeader, sudoerToken)
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
local _M = {}
|
||||
|
||||
function _M.file_exists(name)
|
||||
local f = io.open(name, "r")
|
||||
if f ~= nil then
|
||||
io.close(f)
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
return _M
|
||||
+15
-6
@@ -1,14 +1,23 @@
|
||||
local commons = require("lib.commons")
|
||||
|
||||
local _M = {}
|
||||
|
||||
function _M.uuid()
|
||||
local uuid_cmd = "/usr/bin/uuid"
|
||||
|
||||
local handle = io.popen(uuid_cmd)
|
||||
local result = handle:read("*a")
|
||||
local r2 = string.gsub(result, "%s+", "")
|
||||
local r3 = string.gsub(r2,"\n","")
|
||||
ngx.log(ngx.INFO, "uuid -> ", r3)
|
||||
return r3
|
||||
if commons.file_exists(uuid_cmd) then
|
||||
local handle = io.popen(uuid_cmd)
|
||||
local result = handle:read("*a")
|
||||
local r2 = string.gsub(result, "%s+", "")
|
||||
local r3 = string.gsub(r2,"\n","")
|
||||
ngx.log(ngx.INFO, "uuid -> ", r3)
|
||||
return r3
|
||||
else
|
||||
ngx.status = 500
|
||||
ngx.log(ngx.ERR, "my_uuid *FAILED* `/usr/bin/uuid` not exists!")
|
||||
ngx.say("my_uuid *FAILED* `/usr/bin/uuid` not exists!")
|
||||
ngx.exit()
|
||||
end
|
||||
end
|
||||
|
||||
return _M
|
||||
@@ -1,21 +0,0 @@
|
||||
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||
local cjson = require "cjson"
|
||||
local http = require "resty.http"
|
||||
local create_task = require "lib.create_task"
|
||||
local TaskTypes = require 'lib.task_type'
|
||||
local verify = require('lib.jwt_verify')
|
||||
|
||||
local authHeader = ngx.req.get_headers().Authorization
|
||||
local sudoerToken = ngx.req.get_headers().HtySudoerToken
|
||||
verify(httpc, authHeader, sudoerToken)
|
||||
|
||||
local httpc = http.new()
|
||||
ngx.req.read_body()
|
||||
local req_body = cjson.decode(ngx.req.get_body_data())
|
||||
print('req_body...', ngx.req.get_body_data())
|
||||
local media_id = req_body['media_id']
|
||||
|
||||
local task_text = cjson.encode({ task_type = TaskTypes.CONVERT_AUDIO_FILE, payload = { media_id = media_id } })
|
||||
create_task(httpc, task_text, authHeader, sudoerToken)
|
||||
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
-- 指定模块引用目录,否则无法加载同目录下的其他文件
|
||||
--package.path = package.path .. ';/usr/local/opt/openresty/nginx/scripts/?.lua';
|
||||
package.path = package.path .. ';<SCRIPT_PATH>/?.lua';
|
||||
local http = require "resty.http"
|
||||
local cjson = require "cjson"
|
||||
local pl = require "pl.pretty"
|
||||
local uuid = require("lib.my_uuid")
|
||||
local upyun_upload = require("lib.upyun_upload")
|
||||
local get_wx_media = require("lib.wx_download")
|
||||
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)
|
||||
|
||||
local function run()
|
||||
|
||||
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 downloaded_file = get_wx_media(httpc, req_body["media_id"], cjson, pl);
|
||||
|
||||
upyun_upload.upload(downloaded_file, uuid.uuid() .. ".jpg")
|
||||
end
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user