init.lua 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. local skynet = require "skynet"
  2. local s = require "service"
  3. local tools = require "tools"
  4. local cjson = require "cjson"
  5. --玩家列表
  6. local players = {}
  7. --用户详情列表
  8. local playersInfo = {
  9. user_folder_nums = {},
  10. user_file_type_nums = {}
  11. }
  12. --玩家类
  13. function mgrplayer()
  14. local m = {
  15. playerid = nil,
  16. node = nil,
  17. agent = nil,
  18. status = nil,
  19. gate = nil,
  20. }
  21. return m
  22. end
  23. --登录
  24. s.resp.login = function(fd,msg_body)
  25. msg_body = cjson.decode(msg_body)
  26. if msg_body.account == nil then
  27. return tools.response(fd,200,cjson.encode({code=1001,msg = "账号不能为空"}))
  28. end
  29. if msg_body.password == nil then
  30. return tools.response(fd,200,cjson.encode({code=1002,msg = "密码不能为空"}))
  31. end
  32. local isok,user_data = skynet.call("dbmgr","lua","on_recv","verify",msg_body)
  33. if not isok then
  34. return tools.response(fd,200,cjson.encode({code=1003,msg = "账号密码错误!"}))
  35. end
  36. -- if msg_body.account~="123456" or msg_body.password~="abc" then
  37. -- end
  38. local index = 0
  39. if players[user_data.id] ~=nil then
  40. index = players[user_data.id].index+1
  41. end
  42. local token = tools.tokenEncode(cjson.encode({user_id=user_data.id,index=index}))
  43. 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}}
  44. local jsonStr = cjson.encode(myTable)
  45. players[user_data.id] = {index = index}
  46. return tools.response(fd,200,jsonStr)
  47. end
  48. s.resp.account_is_other_user_login = function(source,user_id,index)
  49. if not players[user_id] then
  50. players[user_id] = {index = index}
  51. return false
  52. end
  53. if players[user_id].index~=index then
  54. return true
  55. end
  56. return false
  57. end
  58. --注册
  59. s.resp.register = function(fd,msg_body)
  60. msg_body = cjson.decode(msg_body)
  61. local isok,user_data = skynet.call("dbmgr","lua","on_recv","select_user_by_account",msg_body.account)
  62. if isok then
  63. return tools.response(fd,200,string.format("用户 %s 已存在",msg_body.account))
  64. end
  65. isok = skynet.call("dbmgr","lua","on_recv","add_new_user",msg_body)
  66. if not isok then
  67. return tools.response(fd,200,"创建失败!")
  68. end
  69. return tools.response(fd,200,cjson.encode({code=10000,msg = "创建成功!"}))
  70. end
  71. --用户新建文件夹
  72. s.resp.new_folder = function(fd,msg_body,user_data)
  73. skynet.error("new_folder",msg_body,user_data)
  74. msg_body = cjson.decode(msg_body)
  75. if type(user_data) ~= "table" then
  76. return tools.response(fd, 200, "token error!")
  77. end
  78. local user_id = user_data.user_id
  79. if not user_id then
  80. return tools.response(fd,200,cjson.encode({code=9001,msg = "缺少user_id"}))
  81. end
  82. msg_body["user_id"] = user_id
  83. local isok ,key = tools.checkData({"category_name","type","classification_id"},msg_body)
  84. if not isok then
  85. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: '%s'.", key)}))
  86. end
  87. local is_public = 0
  88. if msg_body.is_public ~=nil then
  89. is_public = msg_body.is_public
  90. end
  91. msg_body["is_public"] = is_public
  92. local isok = skynet.call("dbmgr","lua","on_recv","new_folder",{
  93. user_id=user_id,
  94. folder_name=msg_body.category_name,
  95. classification_id = msg_body.classification_id,
  96. folder_type=msg_body.type,
  97. is_public=msg_body.is_public}
  98. ,fd)
  99. end
  100. --获取资源文件夹列表
  101. s.resp.folder_list = function(fd,msg_body,user_data)
  102. msg_body = cjson.decode(msg_body)
  103. if type(user_data) ~= "table" then
  104. return tools.response(fd, 200, "token error!")
  105. end
  106. local user_id = user_data.user_id
  107. if user_id==nil then
  108. return tools.response(fd,100,"user_id==nil folder_list !")
  109. end
  110. msg_body["user_id"] = user_id
  111. local isok ,key = tools.checkData({"type","page","count","classification_id"},msg_body)
  112. if not isok then
  113. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  114. end
  115. local is_public = 0
  116. if msg_body.is_public ~=nil then
  117. is_public = msg_body.is_public
  118. end
  119. isok = skynet.call("dbmgr","lua","on_recv","folder_list",{user_id = user_id,
  120. type=msg_body.type,
  121. is_public=is_public,
  122. page=msg_body.page,
  123. count = msg_body.count,
  124. classification_id = msg_body.classification_id}
  125. ,fd)
  126. end
  127. --获取文件夹内的所有资源
  128. s.resp.folder_res_list = function(fd,msg_body,user_data)
  129. msg_body = cjson.decode(msg_body)
  130. if type(user_data) ~= "table" then
  131. return tools.response(fd, 200, "token error!")
  132. end
  133. local user_id = user_data.user_id
  134. if user_id==nil then
  135. return tools.response(fd,100,"user_id==nil folder_res_list !")
  136. end
  137. msg_body["user_id"] = user_id
  138. local isok ,key = tools.checkData({"folder_id","page","count"},msg_body)
  139. if not isok then
  140. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  141. end
  142. local is_public = 0
  143. if msg_body.is_public ~=nil then
  144. is_public = msg_body.is_public
  145. end
  146. local duration = nil
  147. if msg_body.duration ~=nil then
  148. duration = msg_body.duration
  149. end
  150. isok = skynet.call("dbmgr","lua","on_recv","folder_res_list",{
  151. folder_id = msg_body.folder_id,
  152. user_id = user_id,
  153. is_public=is_public,
  154. page=msg_body.page,
  155. count = msg_body.count,
  156. duration = duration}
  157. ,fd)
  158. end
  159. --重命名资源
  160. s.resp.reset_res_name = function(fd,msg_body,user_data)
  161. msg_body = cjson.decode(msg_body)
  162. if type(user_data) ~= "table" then
  163. return tools.response(fd, 200, "token error!")
  164. end
  165. local user_id = user_data.user_id
  166. if user_id==nil then
  167. return tools.response(fd,100,"user_id==nil reset_res_name !")
  168. end
  169. msg_body["user_id"] = user_id
  170. local isok ,key = tools.checkData({"folder_id","file_id","name"},msg_body)
  171. if not isok then
  172. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  173. end
  174. local is_public = 0
  175. if msg_body.is_public ~=nil then
  176. is_public = msg_body.is_public
  177. end
  178. isok = skynet.call("dbmgr","lua","on_recv","reset_res_name",{
  179. folder_id = msg_body.folder_id,
  180. file_id = msg_body.file_id,
  181. name = msg_body.name,
  182. is_public=is_public,
  183. user_id = user_id}
  184. )
  185. if not isok then
  186. return tools.response(fd,200,cjson.encode({code=10001,msg = "--重命名资源失败"}))
  187. end
  188. return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名资源成功"}))
  189. end
  190. --重命名文件夹
  191. s.resp.reset_folder_name = function(fd,msg_body,user_data)
  192. msg_body = cjson.decode(msg_body)
  193. if type(user_data) ~= "table" then
  194. return tools.response(fd, 200, "token error!")
  195. end
  196. local user_id = user_data.user_id
  197. if user_id==nil then
  198. return tools.response(fd,100,"user_id==nil reset_folder_name !")
  199. end
  200. msg_body["user_id"] = user_id
  201. local isok ,key = tools.checkData({"folder_id","name"},msg_body)
  202. if not isok then
  203. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  204. end
  205. local is_public = 0
  206. if msg_body.is_public ~=nil then
  207. is_public = msg_body.is_public
  208. end
  209. isok = skynet.call("dbmgr","lua","on_recv","reset_folder_name",{
  210. folder_id = msg_body.folder_id,
  211. name = msg_body.name,
  212. is_public=is_public,
  213. user_id = user_id}
  214. )
  215. if not isok then
  216. return tools.response(fd,200,cjson.encode({code=10001,msg = "--重命名资源失败"}))
  217. end
  218. return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名资源成功"}))
  219. end
  220. --搜索
  221. s.resp.search_res = function(fd,msg_body,user_data)
  222. msg_body = cjson.decode(msg_body)
  223. if type(user_data) ~= "table" then
  224. return tools.response(fd, 200, "token error!")
  225. end
  226. local user_id = user_data.user_id
  227. if user_id==nil then
  228. return tools.response(fd,100,"user_id==nil search_res !")
  229. end
  230. msg_body["user_id"] = user_id
  231. local isok ,key = tools.checkData({"search_content","type","is_public","page","count","classification_id"},msg_body)
  232. if not isok then
  233. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  234. end
  235. local is_public = 0
  236. if msg_body.is_public ~=nil then
  237. is_public = msg_body.is_public
  238. end
  239. isok = skynet.call("dbmgr","lua","on_recv","search_res",{
  240. type = msg_body.type,
  241. search_content = msg_body.search_content,
  242. is_public=is_public,
  243. page = msg_body.page,
  244. count = msg_body.count,
  245. classification_id = msg_body.classification_id,
  246. user_id = user_id}
  247. ,fd)
  248. end
  249. --删除资源
  250. s.resp.delete_res = function(fd,msg_body,user_data)
  251. msg_body = cjson.decode(msg_body)
  252. if type(user_data) ~= "table" then
  253. return tools.response(fd, 200, "token error!")
  254. end
  255. local user_id = user_data.user_id
  256. if user_id==nil then
  257. return tools.response(fd,200,"user_id==nil delete_res !")
  258. end
  259. msg_body["user_id"] = user_id
  260. local isok ,key = tools.checkData({"file_id_list","is_public"},msg_body)
  261. if not isok then
  262. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  263. end
  264. local is_public = 0
  265. if msg_body.is_public ~=nil then
  266. is_public = msg_body.is_public
  267. end
  268. isok = skynet.call("dbmgr","lua","on_recv","delete_res",{
  269. file_id_list = msg_body.file_id_list,
  270. is_public=is_public,
  271. user_id = user_id}
  272. )
  273. if not isok then
  274. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
  275. end
  276. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
  277. end
  278. --删除文件夹
  279. s.resp.delete_folder = function(fd,msg_body,user_data)
  280. msg_body = cjson.decode(msg_body)
  281. if type(user_data) ~= "table" then
  282. return tools.response(fd, 200, "token error!")
  283. end
  284. local user_id = user_data.user_id
  285. if user_id==nil then
  286. return tools.response(fd,200,"user_id==nil delete_folder !")
  287. end
  288. msg_body["user_id"] = user_id
  289. local isok ,key = tools.checkData({"folder_id_list","is_public"},msg_body)
  290. if not isok then
  291. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  292. end
  293. local is_public = 0
  294. if msg_body.is_public ~=nil then
  295. is_public = msg_body.is_public
  296. end
  297. isok = skynet.call("dbmgr","lua","on_recv","delete_folder",{
  298. folder_id_list = msg_body.folder_id_list,
  299. is_public=is_public,
  300. user_id = user_id}
  301. )
  302. if not isok then
  303. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
  304. end
  305. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
  306. end
  307. --获取指定类型所有文件
  308. s.resp.get_file_list_by_type = function(fd,msg_body,user_data)
  309. msg_body = cjson.decode(msg_body)
  310. if type(user_data) ~= "table" then
  311. return tools.response(fd, 200, "token error!")
  312. end
  313. local user_id = user_data.user_id
  314. if user_id==nil then
  315. return tools.response(fd,200,"user_id==nil get_file_list_by_type !")
  316. end
  317. msg_body["user_id"] = user_id
  318. local isok ,key = tools.checkData({"type","page","count"},msg_body)
  319. if not isok then
  320. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  321. end
  322. local duration = nil
  323. if msg_body.duration ~=nil then
  324. duration = msg_body.duration
  325. end
  326. isok = skynet.call("dbmgr","lua","on_recv","get_file_list_by_type",{
  327. type = msg_body.type,
  328. count = msg_body.count,
  329. page = msg_body.page,
  330. user_id = user_id,
  331. duration = duration}
  332. ,fd)
  333. end
  334. --新建模板
  335. s.resp.create_template = function(fd,msg_body,user_data)
  336. msg_body = cjson.decode(msg_body)
  337. if type(user_data) ~= "table" then
  338. return tools.response(fd, 200, "token error!")
  339. end
  340. local user_id = user_data.user_id
  341. if user_id==nil then
  342. return tools.response(fd,200,"user_id==nil create_template !")
  343. end
  344. msg_body["user_id"] = user_id
  345. local isok ,key = tools.checkData({"project_name","book_name","ratio","video_stype","subtitles","subtitles_audio","video_nums","video_crop_time"},msg_body)
  346. if not isok then
  347. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  348. end
  349. local error_info = ""
  350. isok,error_info = skynet.call("dbmgr","lua","on_recv","check_template_isRight", msg_body)
  351. if not isok then
  352. return tools.response(fd,200,error_info)
  353. end
  354. -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
  355. -- duration = 0,
  356. -- type = 1,
  357. -- limit = 1,
  358. -- user_id = user_id}
  359. -- )
  360. -- if not isok then
  361. -- return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败,片头资源不足!"}))
  362. -- end
  363. -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
  364. -- duration = 0,
  365. -- type = 3,
  366. -- limit = 1,
  367. -- user_id = user_id}
  368. -- )
  369. -- if not isok then
  370. -- return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败,片尾资源不足"}))
  371. -- end
  372. -- local subtitles_audio_duration = 0
  373. -- if msg_body.template_info ~=nil and msg_body.template_info~="" then
  374. -- local template_info = cjson.decode(msg_body.template_info)
  375. -- if template_info.subtitles_audio_duration~=nil then
  376. -- subtitles_audio_duration = tonumber(template_info.subtitles_audio_duration)
  377. -- end
  378. -- end
  379. -- local duration = msg_body.video_crop_time + 5
  380. -- local limit = math.floor(subtitles_audio_duration/duration)
  381. -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
  382. -- duration = duration,
  383. -- type = 2,
  384. -- limit =limit ,
  385. -- user_id = user_id}
  386. -- )
  387. -- if not isok then
  388. -- return tools.response(fd,200,cjson.encode({code=10001,msg = "正片资源不足"}))
  389. -- end
  390. -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
  391. -- duration = 0,
  392. -- type = 4,
  393. -- limit = 1,
  394. -- user_id = user_id}
  395. -- )
  396. -- if not isok then
  397. -- return tools.response(fd,200,cjson.encode({code=10001,msg = "BGM音效资源不足!"}))
  398. -- end
  399. isok = skynet.call("dbmgr","lua","on_recv","create_template",msg_body,fd)
  400. if not isok then
  401. return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败"}))
  402. end
  403. return tools.response(fd,200,cjson.encode({code=10000,msg = "新建模板成功"}))
  404. end
  405. -- 获取模板列表
  406. s.resp.get_template_list = function(fd,msg_body,user_data)
  407. msg_body = cjson.decode(msg_body)
  408. if type(user_data) ~= "table" then
  409. return tools.response(fd, 200, "token error!")
  410. end
  411. local user_id = user_data.user_id
  412. if user_id==nil then
  413. return tools.response(fd,200,"user_id==nil get_template_list !")
  414. end
  415. msg_body["user_id"] = user_id
  416. local isok ,key = tools.checkData({"video_stype","page","count"},msg_body)
  417. if not isok then
  418. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  419. end
  420. isok = skynet.call("dbmgr","lua","on_recv","get_template_list",msg_body,fd)
  421. end
  422. --删除模板
  423. s.resp.delete_template = function(fd,msg_body,user_data)
  424. msg_body = cjson.decode(msg_body)
  425. if type(user_data) ~= "table" then
  426. return tools.response(fd, 200, "token error!")
  427. end
  428. local user_id = user_data.user_id
  429. if user_id==nil then
  430. return tools.response(fd,200,"user_id==nil get_template_list !")
  431. end
  432. msg_body["user_id"] = user_id
  433. local isok ,key = tools.checkData({"template_id_list"},msg_body)
  434. if not isok then
  435. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  436. end
  437. isok = skynet.call("dbmgr","lua","on_recv","delete_template",msg_body,fd)
  438. if not isok then
  439. return tools.response(fd,200,cjson.encode({code=10001,msg = "删除模板失败"}))
  440. end
  441. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除模板成功"}))
  442. end
  443. --保存/修改模板
  444. s.resp.save_template = function(fd,msg_body,user_data)
  445. msg_body = cjson.decode(msg_body)
  446. if type(user_data) ~= "table" then
  447. return tools.response(fd, 200, "token error!")
  448. end
  449. local user_id = user_data.user_id
  450. if user_id==nil then
  451. return tools.response(fd,200,"user_id==nil save_template !")
  452. end
  453. msg_body["user_id"] = user_id
  454. 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)
  455. if not isok then
  456. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  457. end
  458. isok = skynet.call("dbmgr","lua","on_recv","save_template",msg_body,fd)
  459. if not isok then
  460. return tools.response(fd,200,cjson.encode({code=10001,msg = "修改模板失败"}))
  461. end
  462. return tools.response(fd,200,cjson.encode({code=10000,msg = "修改模板成功"}))
  463. end
  464. --模板搜索
  465. s.resp.search_template = function(fd,msg_body,user_data)
  466. msg_body = cjson.decode(msg_body)
  467. if type(user_data) ~= "table" then
  468. return tools.response(fd, 200, "token error!")
  469. end
  470. local user_id = user_data.user_id
  471. if user_id==nil then
  472. return tools.response(fd,200,"user_id==nil search_template !")
  473. end
  474. msg_body["user_id"] = user_id
  475. local isok ,key = tools.checkData({"video_stype","search_content","page","count"},msg_body)
  476. if not isok then
  477. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  478. end
  479. isok = skynet.call("dbmgr","lua","on_recv","search_template",msg_body,fd)
  480. end
  481. --根据模板ID获取模板信息
  482. s.resp.get_template_info_by_id = function(fd,msg_body,user_data)
  483. msg_body = cjson.decode(msg_body)
  484. if type(user_data) ~= "table" then
  485. return tools.response(fd, 200, "token error!")
  486. end
  487. local user_id = user_data.user_id
  488. if user_id==nil then
  489. return tools.response(fd,200,"user_id==nil get_template_info_by_id !")
  490. end
  491. msg_body["user_id"] = user_id
  492. local isok ,key = tools.checkData({"template_id"},msg_body)
  493. if not isok then
  494. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  495. end
  496. isok = skynet.call("dbmgr","lua","on_recv","get_template_info_by_id",msg_body,fd)
  497. end
  498. --生成视频
  499. s.resp.generate_video = function(fd,msg_body,user_data)
  500. msg_body = cjson.decode(msg_body)
  501. if type(user_data) ~= "table" then
  502. return tools.response(fd, 200, "token error!")
  503. end
  504. local user_id = user_data.user_id
  505. if user_id==nil then
  506. return tools.response(fd,200,"user_id==nil generate_video !")
  507. end
  508. msg_body["user_id"] = user_id
  509. local isok ,key = tools.checkData({"template_id"},msg_body)
  510. if not isok then
  511. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  512. end
  513. isok = skynet.call("dbmgr","lua","on_recv","generate_video",msg_body,fd)
  514. end
  515. --获取生成视频文件夹列表
  516. s.resp.get_generate_video_folder_list = function(fd,msg_body,user_data)
  517. msg_body = cjson.decode(msg_body)
  518. if type(user_data) ~= "table" then
  519. return tools.response(fd, 200, "token error!")
  520. end
  521. local user_id = user_data.user_id
  522. if user_id==nil then
  523. return tools.response(fd,100,"user_id==nil get_generate_video_folder_list !")
  524. end
  525. msg_body["user_id"] = user_id
  526. local isok ,key = tools.checkData({"page","count","video_stype"},msg_body)
  527. if not isok then
  528. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  529. end
  530. local is_public = 0
  531. if msg_body.is_public ~=nil then
  532. is_public = msg_body.is_public
  533. end
  534. isok = skynet.call("dbmgr","lua","on_recv","get_generate_video_folder_list",{user_id = user_id,
  535. page=msg_body.page,
  536. count = msg_body.count,
  537. video_stype=msg_body.video_stype}
  538. ,fd)
  539. end
  540. --获取文件夹内的生成视频
  541. s.resp.get_video_list_by_folder_id = function(fd,msg_body,user_data)
  542. msg_body = cjson.decode(msg_body)
  543. if type(user_data) ~= "table" then
  544. return tools.response(fd, 200, "token error!")
  545. end
  546. local user_id = user_data.user_id
  547. if user_id==nil then
  548. return tools.response(fd,100,"user_id==nil get_video_list_by_folder_id !")
  549. end
  550. msg_body["user_id"] = user_id
  551. local isok ,key = tools.checkData({"folder_id","page","count"},msg_body)
  552. if not isok then
  553. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  554. end
  555. local is_public = 0
  556. if msg_body.is_public ~=nil then
  557. is_public = msg_body.is_public
  558. end
  559. local duration = nil
  560. if msg_body.duration ~=nil then
  561. duration = msg_body.duration
  562. end
  563. isok = skynet.call("dbmgr","lua","on_recv","get_video_list_by_folder_id",{
  564. folder_id = msg_body.folder_id,
  565. user_id = user_id,
  566. page=msg_body.page,
  567. count = msg_body.count}
  568. ,fd)
  569. end
  570. --删除生成视频文件夹
  571. s.resp.delete_generate_video_folder = function(fd,msg_body,user_data)
  572. msg_body = cjson.decode(msg_body)
  573. if type(user_data) ~= "table" then
  574. return tools.response(fd, 200, "token error!")
  575. end
  576. local user_id = user_data.user_id
  577. if user_id==nil then
  578. return tools.response(fd,200,"user_id==nil delete_generate_video_folder !")
  579. end
  580. msg_body["user_id"] = user_id
  581. local isok ,key = tools.checkData({"folder_id_list"},msg_body)
  582. if not isok then
  583. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  584. end
  585. isok = skynet.call("dbmgr","lua","on_recv","delete_generate_video_folder",{
  586. folder_id_list = msg_body.folder_id_list,
  587. user_id = user_id}
  588. )
  589. if not isok then
  590. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
  591. end
  592. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
  593. end
  594. --删除生成视频
  595. s.resp.delete_generate_video = function(fd,msg_body,user_data)
  596. msg_body = cjson.decode(msg_body)
  597. if type(user_data) ~= "table" then
  598. return tools.response(fd, 200, "token error!")
  599. end
  600. local user_id = user_data.user_id
  601. if user_id==nil then
  602. return tools.response(fd,200,"user_id==nil delete_generate_video !")
  603. end
  604. msg_body["user_id"] = user_id
  605. local isok ,key = tools.checkData({"generate_video_id_list"},msg_body)
  606. if not isok then
  607. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  608. end
  609. local is_public = 0
  610. if msg_body.is_public ~=nil then
  611. is_public = msg_body.is_public
  612. end
  613. isok = skynet.call("dbmgr","lua","on_recv","delete_generate_video",{
  614. file_id_list = msg_body.generate_video_id_list,
  615. user_id = user_id}
  616. )
  617. if not isok then
  618. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!"}))
  619. end
  620. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!"}))
  621. end
  622. --重命名生成视频文件夹的名字
  623. s.resp.reset_generate_video_folder_name = function(fd,msg_body,user_data)
  624. msg_body = cjson.decode(msg_body)
  625. if type(user_data) ~= "table" then
  626. return tools.response(fd, 200, "token error!")
  627. end
  628. local user_id = user_data.user_id
  629. if user_id==nil then
  630. return tools.response(fd,100,"user_id==nil reset_generate_video_folder_name !")
  631. end
  632. msg_body["user_id"] = user_id
  633. local isok ,key = tools.checkData({"folder_id","file_id"},msg_body)
  634. if not isok then
  635. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  636. end
  637. isok = skynet.call("dbmgr","lua","on_recv","reset_generate_video_folder_name",{
  638. folder_id = msg_body.folder_id,
  639. file_id = msg_body.file_id,
  640. user_id = user_id}
  641. )
  642. if not isok then
  643. return tools.response(fd,200,cjson.encode({code=10001,msg = "重命名生成视频文件夹的名字失败"}))
  644. end
  645. return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名生成视频文件夹的名字成功"}))
  646. end
  647. --生成视频搜索
  648. s.resp.search_generate_video_file = function(fd,msg_body,user_data)
  649. msg_body = cjson.decode(msg_body)
  650. if type(user_data) ~= "table" then
  651. return tools.response(fd, 200, "token error!")
  652. end
  653. local user_id = user_data.user_id
  654. if user_id==nil then
  655. return tools.response(fd,100,"user_id==nil reset_generate_video_folder_name !")
  656. end
  657. msg_body["user_id"] = user_id
  658. local isok ,key = tools.checkData({"page","count","video_stype","search_content"},msg_body)
  659. if not isok then
  660. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  661. end
  662. isok = skynet.call("dbmgr","lua","on_recv","search_generate_video_file",{
  663. search_content = msg_body.search_content,
  664. page = msg_body.page,
  665. count = msg_body.count,
  666. video_stype = msg_body.video_stype},fd
  667. )
  668. end
  669. --检测指定类型文件是否够数量
  670. s.resp.checkNumsByType = function(fd,msg_body,user_data)
  671. msg_body = cjson.decode(msg_body)
  672. if type(user_data) ~= "table" then
  673. return tools.response(fd, 200, "token error!")
  674. end
  675. local user_id = user_data.user_id
  676. if user_id==nil then
  677. return tools.response(fd,100,"user_id==nil checkNumsByType !")
  678. end
  679. msg_body["user_id"] = user_id
  680. local isok ,key = tools.checkData({"type","limit"},msg_body)
  681. if not isok then
  682. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  683. end
  684. isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
  685. duration = msg_body.duration,
  686. type = msg_body.type,
  687. limit = msg_body.limit,
  688. user_id = user_id}
  689. )
  690. if not isok then
  691. return tools.response(fd,200,cjson.encode({code=10001,msg = "条件不足"}))
  692. end
  693. return tools.response(fd,200,cjson.encode({code=10000,msg = "条件成立"}))
  694. end
  695. --修改密码
  696. s.resp.reset_password = function(fd,msg_body,user_data)
  697. msg_body = cjson.decode(msg_body)
  698. if type(user_data) ~= "table" then
  699. return tools.response(fd, 200, "token error!")
  700. end
  701. local user_id = user_data.user_id
  702. if user_id==nil then
  703. return tools.response(fd,100,"user_id==nil reset_password !")
  704. end
  705. msg_body["user_id"] = user_id
  706. local isok ,key = tools.checkData({"new_pw","sure_pw"},msg_body)
  707. if not isok then
  708. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  709. end
  710. if msg_body.new_pw~=msg_body.sure_pw then
  711. return tools.response(fd,200,cjson.encode({code=9002,msg ="两次密码不一致!"}))
  712. end
  713. isok = skynet.call("dbmgr","lua","on_recv","reset_password",{
  714. new_pw = msg_body.new_pw,
  715. sure_pw = msg_body.sure_pw,
  716. user_id = user_id}
  717. )
  718. if not isok then
  719. return tools.response(fd,200,cjson.encode({code=10001,msg = "修改密码失败!"}))
  720. end
  721. return tools.response(fd,200,cjson.encode({code=10000,msg = "修改密码成功!"}))
  722. end
  723. s.resp.update_generate_video_custom = function(fd,msg_body,user_data)
  724. msg_body = cjson.decode(msg_body)
  725. if type(user_data) ~= "table" then
  726. return tools.response(fd, 200, "token error!")
  727. end
  728. local user_id = user_data.user_id
  729. -- tools.dump(msg_body)
  730. if user_id==nil then
  731. return tools.response(fd,100,"user_id==nil update_generate_video_custom !")
  732. end
  733. msg_body["user_id"] = user_id
  734. local isok ,key = tools.checkData({"data"},msg_body)
  735. if not isok then
  736. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  737. end
  738. isok = skynet.call("dbmgr","lua","on_recv","update_generate_video_custom",{
  739. data = msg_body.data,
  740. user_id = user_id}
  741. )
  742. if not isok then
  743. return tools.response(fd,200,cjson.encode({code=10001,msg = "更新失败!"}))
  744. end
  745. return tools.response(fd,200,cjson.encode({code=10000,msg = "更新成功!"}))
  746. end
  747. --更新用户所有的文件数
  748. s.resp.update_user_folder_list_nums = function(user_id)
  749. skynet.fork(function()
  750. local count = skynet.call("dbmgr","lua","on_recv","get_user_folder_list_nums",{
  751. user_id = user_id}
  752. )
  753. playersInfo.user_folder_nums[user_id] = count
  754. end)
  755. end
  756. --更新用户指定类型的数量
  757. s.resp.update_user_file_count_by_type = function(user_id,file_type)
  758. skynet.fork(function()
  759. local key = user_id.."_"..file_type
  760. local count = skynet.call("dbmgr","lua","on_recv","get_user_file_count_by_type",{
  761. user_id = user_id,
  762. file_type = file_type}
  763. )
  764. playersInfo.user_file_type_nums[key] = count
  765. end)
  766. end
  767. --获取用户所有的文件数
  768. s.resp.get_user_folder_list_nums = function(user_id)
  769. if playersInfo.user_folder_nums[user_id]~=nil then
  770. return playersInfo.user_folder_nums[user_id]
  771. else
  772. local count = skynet.call("dbmgr","lua","on_recv","get_user_folder_list_nums",{
  773. user_id = user_id}
  774. )
  775. playersInfo.user_folder_nums[user_id] = count
  776. return count
  777. end
  778. end
  779. --获取用户指定类型的数量
  780. s.resp.get_user_file_count_by_type = function(user_id,file_type)
  781. local key = user_id.."_"..file_type
  782. if playersInfo.user_file_type_nums[key]~=nil then
  783. return playersInfo.user_file_type_nums[key]
  784. else
  785. local count = skynet.call("dbmgr","lua","on_recv","get_user_file_count_by_type",{
  786. user_id = user_id,
  787. file_type = file_type}
  788. )
  789. playersInfo.user_file_type_nums[key] = count
  790. return count
  791. end
  792. end
  793. --踢掉
  794. s.resp.kick = function(fd,msg_body,user_data)
  795. end
  796. s.resp.on_recv = function (source, fd, msg_id, msg_body,user_data)
  797. skynet.error("接收一条客户端消息 ",msg_id,user_data)
  798. local func = string.gsub(msg_id, '/', '')
  799. if func ~= "login" then
  800. if not s.resp.account_is_other_user_login(source,user_data.user_id,user_data.index) then
  801. else
  802. skynet.error("用户被挤掉",user_data.user_id)
  803. return tools.response(fd,200,cjson.encode({code=999,msg = "您的账号被其他用户登录!"}))
  804. end
  805. end
  806. if s.resp[func] ~=nil then
  807. return s.resp[func](fd,msg_body,user_data)
  808. end
  809. return tools.response(fd,200,string.format("接口 %s 不存在",func))
  810. end
  811. s.start(...)