12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028 |
- local skynet = require "skynet"
- local s = require "service"
- local tools = require "tools"
- local cjson = require "cjson"
- --玩家列表
- local players = {}
- --用户详情列表
- local playersInfo = {
- user_folder_nums = {},
- user_file_type_nums = {}
- }
- --玩家类
- function mgrplayer()
- local m = {
- playerid = nil,
- node = nil,
- agent = nil,
- status = nil,
- gate = nil,
- }
- return m
- end
- --登录
- s.resp.login = function(fd,msg_body)
- msg_body = cjson.decode(msg_body)
- if msg_body.account == nil then
- return tools.response(fd,200,cjson.encode({code=1001,msg = "账号不能为空"}))
- end
- if msg_body.password == nil then
- return tools.response(fd,200,cjson.encode({code=1002,msg = "密码不能为空"}))
- end
- local isok,user_data = skynet.call("dbmgr","lua","on_recv","verify",msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=1003,msg = "账号密码错误!"}))
- end
- -- if msg_body.account~="123456" or msg_body.password~="abc" then
-
- -- end
- local index = 0
- if players[user_data.id] ~=nil then
- index = players[user_data.id].index+1
- end
- local token = tools.tokenEncode(cjson.encode({user_id=user_data.id,index=index}))
- local myTable = {code =10000, msg = "登录成功!", data = {user_id=user_data.id,user_name=user_data.name,group_id=user_data.group_id,permit_id=user_data.permit_id,token=token}}
- local jsonStr = cjson.encode(myTable)
- players[user_data.id] = {index = index}
- return tools.response(fd,200,jsonStr)
- end
- s.resp.account_is_other_user_login = function(source,user_id,index)
- if not players[user_id] then
- players[user_id] = {index = index}
- return false
- end
- if players[user_id].index~=index then
- return true
- end
- return false
- end
- --注册
- s.resp.register = function(fd,msg_body)
- msg_body = cjson.decode(msg_body)
- local isok,user_data = skynet.call("dbmgr","lua","on_recv","select_user_by_account",msg_body.account)
- if isok then
- return tools.response(fd,200,string.format("用户 %s 已存在",msg_body.account))
- end
- isok = skynet.call("dbmgr","lua","on_recv","add_new_user",msg_body)
- if not isok then
- return tools.response(fd,200,"创建失败!")
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "创建成功!"}))
- end
- --用户新建文件夹
- s.resp.new_folder = function(fd,msg_body,user_data)
- skynet.error("new_folder",msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if not user_id then
- return tools.response(fd,200,cjson.encode({code=9001,msg = "缺少user_id"}))
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"category_name","type","classification_id"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- msg_body["is_public"] = is_public
- local isok = skynet.call("dbmgr","lua","on_recv","new_folder",{
- user_id=user_id,
- folder_name=msg_body.category_name,
- classification_id = msg_body.classification_id,
- folder_type=msg_body.type,
- is_public=msg_body.is_public}
- ,fd)
- end
- --获取资源文件夹列表
- s.resp.folder_list = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil folder_list !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"type","page","count","classification_id"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- isok = skynet.call("dbmgr","lua","on_recv","folder_list",{user_id = user_id,
- type=msg_body.type,
- is_public=is_public,
- page=msg_body.page,
- count = msg_body.count,
- classification_id = msg_body.classification_id}
- ,fd)
-
- end
- --获取文件夹内的所有资源
- s.resp.folder_res_list = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil folder_res_list !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"folder_id","page","count"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- local duration = nil
- if msg_body.duration ~=nil then
- duration = msg_body.duration
- end
- isok = skynet.call("dbmgr","lua","on_recv","folder_res_list",{
- folder_id = msg_body.folder_id,
- user_id = user_id,
- is_public=is_public,
- page=msg_body.page,
- count = msg_body.count,
- duration = duration}
- ,fd)
- end
- --重命名资源
- s.resp.reset_res_name = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil reset_res_name !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"folder_id","file_id","name"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- isok = skynet.call("dbmgr","lua","on_recv","reset_res_name",{
- folder_id = msg_body.folder_id,
- file_id = msg_body.file_id,
- name = msg_body.name,
- is_public=is_public,
- user_id = user_id}
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "--重命名资源失败"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名资源成功"}))
- end
- --重命名文件夹
- s.resp.reset_folder_name = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil reset_folder_name !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"folder_id","name"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- isok = skynet.call("dbmgr","lua","on_recv","reset_folder_name",{
- folder_id = msg_body.folder_id,
- name = msg_body.name,
- is_public=is_public,
- user_id = user_id}
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "--重命名资源失败"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名资源成功"}))
- end
- --搜索
- s.resp.search_res = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil search_res !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"search_content","type","is_public","page","count","classification_id"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- isok = skynet.call("dbmgr","lua","on_recv","search_res",{
- type = msg_body.type,
- search_content = msg_body.search_content,
- is_public=is_public,
- page = msg_body.page,
- count = msg_body.count,
- classification_id = msg_body.classification_id,
- user_id = user_id}
- ,fd)
- end
- --删除资源
- s.resp.delete_res = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil delete_res !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"file_id_list","is_public"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- isok = skynet.call("dbmgr","lua","on_recv","delete_res",{
- file_id_list = msg_body.file_id_list,
- is_public=is_public,
- user_id = user_id}
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
- end
- --删除文件夹
- s.resp.delete_folder = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil delete_folder !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"folder_id_list","is_public"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- isok = skynet.call("dbmgr","lua","on_recv","delete_folder",{
- folder_id_list = msg_body.folder_id_list,
- is_public=is_public,
- user_id = user_id}
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
- end
- --获取指定类型所有文件
- s.resp.get_file_list_by_type = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil get_file_list_by_type !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"type","page","count"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local duration = nil
- if msg_body.duration ~=nil then
- duration = msg_body.duration
- end
- isok = skynet.call("dbmgr","lua","on_recv","get_file_list_by_type",{
- type = msg_body.type,
- count = msg_body.count,
- page = msg_body.page,
- user_id = user_id,
- duration = duration}
- ,fd)
- end
- --新建模板
- s.resp.create_template = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil create_template !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"project_name","book_name","ratio","video_stype","subtitles","subtitles_audio","video_nums","video_crop_time"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local error_info = ""
- if msg_body.video_stype == 1 then --1 解压
- isok,error_info = skynet.call("dbmgr","lua","on_recv","check_template_isRight", msg_body)
- if not isok then
- return tools.response(fd,200,error_info)
- end
- else --2 滚屏
- isok,error_info = skynet.call("dbmgr","lua","on_recv","check_template_scroll_isRight", msg_body)
- if not isok then
- return tools.response(fd,200,error_info)
- end
- end
- -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
- -- duration = 0,
- -- type = 1,
- -- limit = 1,
- -- user_id = user_id}
- -- )
- -- if not isok then
- -- return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败,片头资源不足!"}))
- -- end
- -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
- -- duration = 0,
- -- type = 3,
- -- limit = 1,
- -- user_id = user_id}
- -- )
- -- if not isok then
- -- return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败,片尾资源不足"}))
- -- end
- -- local subtitles_audio_duration = 0
- -- if msg_body.template_info ~=nil and msg_body.template_info~="" then
- -- local template_info = cjson.decode(msg_body.template_info)
- -- if template_info.subtitles_audio_duration~=nil then
- -- subtitles_audio_duration = tonumber(template_info.subtitles_audio_duration)
- -- end
- -- end
-
- -- local duration = msg_body.video_crop_time + 5
- -- local limit = math.floor(subtitles_audio_duration/duration)
- -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
- -- duration = duration,
- -- type = 2,
- -- limit =limit ,
- -- user_id = user_id}
- -- )
- -- if not isok then
- -- return tools.response(fd,200,cjson.encode({code=10001,msg = "正片资源不足"}))
- -- end
- -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
- -- duration = 0,
- -- type = 4,
- -- limit = 1,
- -- user_id = user_id}
- -- )
- -- if not isok then
- -- return tools.response(fd,200,cjson.encode({code=10001,msg = "BGM音效资源不足!"}))
- -- end
- -- tools.dump(msg_body)
- isok = skynet.call("dbmgr","lua","on_recv","create_template",msg_body,fd)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "新建模板成功"}))
- end
- -- 获取模板列表
- s.resp.get_template_list = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil get_template_list !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"video_stype","page","count"},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","get_template_list",msg_body,fd)
- end
- --删除模板
- s.resp.delete_template = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil get_template_list !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"template_id_list"},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","delete_template",msg_body,fd)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "删除模板失败"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "删除模板成功"}))
- end
- --保存/修改模板
- s.resp.save_template = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil save_template !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"template_id","project_name","book_name","ratio","video_stype","subtitles","subtitles_audio","video_nums","video_crop_time","template_info"},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","save_template",msg_body,fd)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "修改模板失败"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "修改模板成功"}))
- end
- --模板搜索
- s.resp.search_template = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil search_template !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"video_stype","search_content","page","count"},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","search_template",msg_body,fd)
- end
- --根据模板ID获取模板信息
- s.resp.get_template_info_by_id = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil get_template_info_by_id !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"template_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","get_template_info_by_id",msg_body,fd)
- end
- --生成视频
- s.resp.generate_video = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil generate_video !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"template_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","generate_video",msg_body,fd)
- end
- --获取生成视频文件夹列表
- s.resp.get_generate_video_folder_list = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil get_generate_video_folder_list !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"page","count","video_stype"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- isok = skynet.call("dbmgr","lua","on_recv","get_generate_video_folder_list",{user_id = user_id,
- page=msg_body.page,
- count = msg_body.count,
- video_stype=msg_body.video_stype}
- ,fd)
- end
- --获取文件夹内的生成视频
- s.resp.get_video_list_by_folder_id = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil get_video_list_by_folder_id !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"folder_id","page","count"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- local duration = nil
- if msg_body.duration ~=nil then
- duration = msg_body.duration
- end
- isok = skynet.call("dbmgr","lua","on_recv","get_video_list_by_folder_id",{
- folder_id = msg_body.folder_id,
- user_id = user_id,
- page=msg_body.page,
- count = msg_body.count}
- ,fd)
- end
- --删除生成视频文件夹
- s.resp.delete_generate_video_folder = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil delete_generate_video_folder !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"folder_id_list"},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","delete_generate_video_folder",{
- folder_id_list = msg_body.folder_id_list,
- user_id = user_id}
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
- end
- --删除生成视频
- s.resp.delete_generate_video = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,200,"user_id==nil delete_generate_video !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"generate_video_id_list"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- local is_public = 0
- if msg_body.is_public ~=nil then
- is_public = msg_body.is_public
- end
- isok = skynet.call("dbmgr","lua","on_recv","delete_generate_video",{
- file_id_list = msg_body.generate_video_id_list,
- user_id = user_id}
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!"}))
- end
- --重命名生成视频文件夹的名字
- s.resp.reset_generate_video_folder_name = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil reset_generate_video_folder_name !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"folder_id","file_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","reset_generate_video_folder_name",{
- folder_id = msg_body.folder_id,
- file_id = msg_body.file_id,
- user_id = user_id}
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "重命名生成视频文件夹的名字失败"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名生成视频文件夹的名字成功"}))
- end
- --生成视频搜索
- s.resp.search_generate_video_file = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil reset_generate_video_folder_name !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"page","count","video_stype","search_content"},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","search_generate_video_file",{
- search_content = msg_body.search_content,
- page = msg_body.page,
- count = msg_body.count,
- user_id = msg_body.user_id,
- video_stype = msg_body.video_stype},fd
- )
- end
- --检测指定类型文件是否够数量
- s.resp.checkNumsByType = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil checkNumsByType !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"type","limit"},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","checkNumsByType",{
- duration = msg_body.duration,
- type = msg_body.type,
- limit = msg_body.limit,
- user_id = user_id}
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "条件不足"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "条件成立"}))
- end
- --修改密码
- s.resp.reset_password = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil reset_password !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"new_pw","sure_pw"},msg_body)
- if not isok then
- return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
- end
- if msg_body.new_pw~=msg_body.sure_pw then
- return tools.response(fd,200,cjson.encode({code=9002,msg ="两次密码不一致!"}))
- end
- isok = skynet.call("dbmgr","lua","on_recv","reset_password",{
- new_pw = msg_body.new_pw,
- sure_pw = msg_body.sure_pw,
- user_id = user_id}
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "修改密码失败!"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "修改密码成功!"}))
- end
- s.resp.update_generate_video_custom = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- -- tools.dump(msg_body)
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil update_generate_video_custom !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"data"},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_generate_video_custom",{
- data = msg_body.data,
- user_id = user_id}
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "更新失败!"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "更新成功!"}))
- end
- --更新用户所有的文件数
- s.resp.update_user_folder_list_nums = function(user_id)
- skynet.fork(function()
- local count = skynet.call("dbmgr","lua","on_recv","get_user_folder_list_nums",{
- user_id = user_id}
- )
- playersInfo.user_folder_nums[user_id] = count
- end)
- end
- --更新用户指定类型的数量
- s.resp.update_user_file_count_by_type = function(user_id,file_type)
- skynet.fork(function()
- local key = user_id.."_"..file_type
- local count = skynet.call("dbmgr","lua","on_recv","get_user_file_count_by_type",{
- user_id = user_id,
- file_type = file_type}
- )
- playersInfo.user_file_type_nums[key] = count
- end)
- end
- --获取用户所有的文件数
- s.resp.get_user_folder_list_nums = function(user_id)
- if playersInfo.user_folder_nums[user_id]~=nil then
- return playersInfo.user_folder_nums[user_id]
- else
- local count = skynet.call("dbmgr","lua","on_recv","get_user_folder_list_nums",{
- user_id = user_id}
- )
- playersInfo.user_folder_nums[user_id] = count
- return count
- end
- end
- --获取用户指定类型的数量
- s.resp.get_user_file_count_by_type = function(user_id,file_type)
- local key = user_id.."_"..file_type
- if playersInfo.user_file_type_nums[key]~=nil then
- return playersInfo.user_file_type_nums[key]
- else
- local count = skynet.call("dbmgr","lua","on_recv","get_user_file_count_by_type",{
- user_id = user_id,
- file_type = file_type}
- )
- playersInfo.user_file_type_nums[key] = count
- return count
- end
- end
- --分享文件列表
- s.resp.share_file_list = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- -- tools.dump(msg_body)
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil share_file_list !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"file_id_list","target_user_id_list"},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","share_file_list",{
- file_id_list = msg_body.file_id_list,
- target_user_id_list = msg_body.target_user_id_list,
- user_id = user_id},fd
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "分享文件列表失败!"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "分享文件列表成功!"}))
- end
- --分享文件夹列表
- s.resp.share_folder_list = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- -- tools.dump(msg_body)
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil share_folder_list !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"folder_id_list","target_user_id_list"},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","share_folder_list",{
- folder_id_list = msg_body.folder_id_list,
- target_user_id_list = msg_body.target_user_id_list,
- user_id = user_id},fd
- )
- if not isok then
- return tools.response(fd,200,cjson.encode({code=10001,msg = "分享文件夹列表失败!"}))
- end
- return tools.response(fd,200,cjson.encode({code=10000,msg = "分享文件夹列表成功!"}))
- end
- --获取用户的分享用户列表
- s.resp.get_share_user_list = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- -- tools.dump(msg_body)
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil get_share_user_list !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"count","page"},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","get_share_user_list",{
- count = msg_body.count,
- page = msg_body.page,
- user_id = user_id},fd
- )
- end
- --检测文件夹下是否有相同命名的资源
- s.resp.check_file_name_list_is_repeat_by_folder_id = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- -- tools.dump(msg_body)
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil check_file_name_list_is_repeat_by_folder_id !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"folder_id","file_name_list"},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","check_file_name_list_is_repeat_by_folder_id",{
- folder_id = msg_body.folder_id,
- file_name_list = msg_body.file_name_list,
- user_id = user_id},fd
- )
- end
- s.resp.get_folder_info = function(fd,msg_body,user_data)
- msg_body = cjson.decode(msg_body)
- if type(user_data) ~= "table" then
- return tools.response(fd, 200, "token error!")
- end
- local user_id = user_data.user_id
- -- tools.dump(msg_body)
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil get_folder_info !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"folder_id_list"},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","get_folder_info",{
- folder_id_list = msg_body.folder_id_list,
- user_id = user_id},fd
- )
- end
- --踢掉
- s.resp.kick = function(fd,msg_body,user_data)
-
- end
- s.resp.on_recv = function (source, fd, msg_id, msg_body,user_data)
- skynet.error("接收一条客户端消息 ",msg_id,user_data)
- local func = string.gsub(msg_id, '/', '')
- if s.resp[func] ==nil then
- return ools.response(fd,200,"???")
- end
- if func ~= "login" then
- if not s.resp.account_is_other_user_login(source,user_data.user_id,user_data.index) then
-
- else
- skynet.error("用户被挤掉",user_data.user_id)
- return tools.response(fd,200,cjson.encode({code=999,msg = "您的账号被其他用户登录!"}))
- end
- end
- if s.resp[func] ~=nil then
- return s.resp[func](fd,msg_body,user_data)
- end
- return tools.response(fd,200,string.format("接口 %s 不存在",func))
- end
- s.start(...)
|