123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122 |
- 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
- --根据文件ID获取文件信息
- s.resp.get_file_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
- -- tools.dump(msg_body)
- if user_id==nil then
- return tools.response(fd,100,"user_id==nil get_file_info_by_id !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"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","get_file_info_by_id",{
- file_id = msg_body.file_id,
- user_id = user_id},fd
- )
- end
- --获取文件列表中已删除的文件
- s.resp.get_not_have_file_list_by_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_not_have_file_list_by_list !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"file_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_not_have_file_list_by_list",{
- file_id_list = msg_body.file_id_list,
- user_id = user_id},fd
- )
- end
- --存储数据
- s.resp.setItem = 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 setItem !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"key","base64value"},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","setItem",{
- key = msg_body.key,
- base64value = msg_body.base64value,
- user_id = user_id},fd
- )
- end
- --获取数据
- s.resp.getItem = 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 getItem !")
- end
- msg_body["user_id"] = user_id
- local isok ,key = tools.checkData({"key"},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","getItem",{
- key = msg_body.key,
- 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(...)
|