123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- local skynet = require "skynet"
- local s = require "service"
- local tools = require "tools"
- local cjson = require "cjson"
- local httpc = require "http.httpc"
- local runconfig = require "run_config"
- s.resp.upload_video_sync = function(fd,msg_body)
- -- skynet.error("msg_body",msg_body)
- msg_body = cjson.decode(msg_body)
- local isOk,key = tools.checkToolsSyncVideo(msg_body)
- if not isOk then
- local str = string.format("缺少字段: %s.", key)
- return tools.response(fd,200,cjson.encode({code=9001,msg = str}))
- end
- isOk = skynet.call("dbmgr","lua","on_recv","add_res_file",msg_body)
- if not isOk then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "失败"}))
- else
- return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!"}))
- end
- end
- s.resp.upload_audio_sync = function(fd,msg_body)
- skynet.error("msg_body",msg_body)
- msg_body = cjson.decode(msg_body)
- local isOk,key = tools.checkData({"folder_id","stype","surl","path","file_name","classification_id"},msg_body)
- if not isOk then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- isOk = skynet.call("dbmgr","lua","on_recv","add_res_file",msg_body)
- if not isOk then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "失败"}))
- else
- return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!"}))
- end
- end
- s.resp.upload_img_sync = function(fd,msg_body)
- skynet.error("msg_body",msg_body)
- msg_body = cjson.decode(msg_body)
- local isOk,key = tools.checkData({"folder_id","stype","is_public","surl","path","file_name","classification_id"},msg_body)
- if not isOk then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- isOk = skynet.call("dbmgr","lua","on_recv","add_res_file",msg_body)
- if not isOk then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "失败"}))
- else
- return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!"}))
- end
- end
- s.resp.generate_video_sync = function(fd,msg_body)
- skynet.error("generate_video_sync",msg_body)
- msg_body = cjson.decode(msg_body)
- local isOk,key = tools.checkData({"id","state","path","user_id","surl","custom"},msg_body)
- if not isOk then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- isOk = skynet.call("dbmgr","lua","on_recv","update_gen_video_file_status",msg_body)
- if not isOk then
- return tools.response(fd,200,cjson.encode({code=2,msg = "失败"}))
- else
- return tools.response(fd,200,cjson.encode({code=1,msg = "成功!"}))
- end
- end
- s.resp.upload_public_res_info = function(fd,msg_body)
- msg_body = cjson.decode(msg_body)
- local isOk,key = tools.checkToolsSyncVideo(msg_body)
- if not isOk then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- isOk = skynet.call("public_mgr","lua","tools_add_public_res_info",fd,msg_body)
- if not isOk then
- return tools.response(fd,200,cjson.encode({code=2,msg = "失败"}))
- else
- local code = 10000
- if msg_body.user_id ~= nil then
- if msg_body.user_id==-1 then
- code = 1
- end
- end
- return tools.response(fd,200,cjson.encode({code=code,msg = "成功!"}))
- end
- end
- s.resp.tools_create_folder = function(fd,msg_body)
- msg_body = cjson.decode(msg_body)
- local isOk,key = tools.checkData({"classification_id","stype", "folder_name","user_id"},msg_body)
- if not isOk then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- isOk = skynet.call("public_mgr","lua","tools_create_folder",fd,msg_body)
- end
- s.resp.on_recv = function (source, fd, msg_id, msg_body)
- skynet.error("接收一条工具消息 ",msg_id)
- local func = string.gsub(msg_id, "/tools/", "")
- if s.resp[func] ~=nil then
- return s.resp[func](fd,msg_body)
- end
- return tools.response(fd,200,string.format("接口 %s 不存在",func))
- end
- s.resp.delete_file = function(source,file_paths)
- httpc.dns() -- set dns server
- httpc.timeout = 100 -- set timeout 1 second
- local func = '/file/deletes'
- local respheader = {}
- -- skynet.error("file_paths",file_paths)
- -- tools.dump(file_paths)
- local status, body = httpc.post(runconfig.tools_api,func,{file_paths=cjson.encode(file_paths)})
- if status == 200 then
- skynet.error("删除成功!")
- else
- skynet.error("删除失败!")
- end
- end
- s.resp.generate_video = function(source,msg_body)
- httpc.dns() -- set dns server
- httpc.timeout = 100 -- set timeout 1 second
- local func = '/video/generate'
- local respheader = {}
- -- skynet.error("file_paths",msg_body)
- -- tools.dump(msg_body)
- local status, body = httpc.post(runconfig.tools_api,func,{sdata=cjson.encode(msg_body)})
- if status == 200 then
- skynet.error("生成成功!")
- else
- skynet.error("生成失败!",status)
- end
- end
- s.start(...)
|