init.lua 39 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122
  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. if msg_body.video_stype == 1 then --1 解压
  351. isok,error_info = skynet.call("dbmgr","lua","on_recv","check_template_isRight", msg_body)
  352. if not isok then
  353. return tools.response(fd,200,error_info)
  354. end
  355. else --2 滚屏
  356. isok,error_info = skynet.call("dbmgr","lua","on_recv","check_template_scroll_isRight", msg_body)
  357. if not isok then
  358. return tools.response(fd,200,error_info)
  359. end
  360. end
  361. -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
  362. -- duration = 0,
  363. -- type = 1,
  364. -- limit = 1,
  365. -- user_id = user_id}
  366. -- )
  367. -- if not isok then
  368. -- return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败,片头资源不足!"}))
  369. -- end
  370. -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
  371. -- duration = 0,
  372. -- type = 3,
  373. -- limit = 1,
  374. -- user_id = user_id}
  375. -- )
  376. -- if not isok then
  377. -- return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败,片尾资源不足"}))
  378. -- end
  379. -- local subtitles_audio_duration = 0
  380. -- if msg_body.template_info ~=nil and msg_body.template_info~="" then
  381. -- local template_info = cjson.decode(msg_body.template_info)
  382. -- if template_info.subtitles_audio_duration~=nil then
  383. -- subtitles_audio_duration = tonumber(template_info.subtitles_audio_duration)
  384. -- end
  385. -- end
  386. -- local duration = msg_body.video_crop_time + 5
  387. -- local limit = math.floor(subtitles_audio_duration/duration)
  388. -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
  389. -- duration = duration,
  390. -- type = 2,
  391. -- limit =limit ,
  392. -- user_id = user_id}
  393. -- )
  394. -- if not isok then
  395. -- return tools.response(fd,200,cjson.encode({code=10001,msg = "正片资源不足"}))
  396. -- end
  397. -- isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
  398. -- duration = 0,
  399. -- type = 4,
  400. -- limit = 1,
  401. -- user_id = user_id}
  402. -- )
  403. -- if not isok then
  404. -- return tools.response(fd,200,cjson.encode({code=10001,msg = "BGM音效资源不足!"}))
  405. -- end
  406. -- tools.dump(msg_body)
  407. isok = skynet.call("dbmgr","lua","on_recv","create_template",msg_body,fd)
  408. if not isok then
  409. return tools.response(fd,200,cjson.encode({code=10001,msg = "新建模板失败"}))
  410. end
  411. return tools.response(fd,200,cjson.encode({code=10000,msg = "新建模板成功"}))
  412. end
  413. -- 获取模板列表
  414. s.resp.get_template_list = function(fd,msg_body,user_data)
  415. msg_body = cjson.decode(msg_body)
  416. if type(user_data) ~= "table" then
  417. return tools.response(fd, 200, "token error!")
  418. end
  419. local user_id = user_data.user_id
  420. if user_id==nil then
  421. return tools.response(fd,200,"user_id==nil get_template_list !")
  422. end
  423. msg_body["user_id"] = user_id
  424. local isok ,key = tools.checkData({"video_stype","page","count"},msg_body)
  425. if not isok then
  426. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  427. end
  428. isok = skynet.call("dbmgr","lua","on_recv","get_template_list",msg_body,fd)
  429. end
  430. --删除模板
  431. s.resp.delete_template = function(fd,msg_body,user_data)
  432. msg_body = cjson.decode(msg_body)
  433. if type(user_data) ~= "table" then
  434. return tools.response(fd, 200, "token error!")
  435. end
  436. local user_id = user_data.user_id
  437. if user_id==nil then
  438. return tools.response(fd,200,"user_id==nil get_template_list !")
  439. end
  440. msg_body["user_id"] = user_id
  441. local isok ,key = tools.checkData({"template_id_list"},msg_body)
  442. if not isok then
  443. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  444. end
  445. isok = skynet.call("dbmgr","lua","on_recv","delete_template",msg_body,fd)
  446. if not isok then
  447. return tools.response(fd,200,cjson.encode({code=10001,msg = "删除模板失败"}))
  448. end
  449. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除模板成功"}))
  450. end
  451. --保存/修改模板
  452. s.resp.save_template = function(fd,msg_body,user_data)
  453. msg_body = cjson.decode(msg_body)
  454. if type(user_data) ~= "table" then
  455. return tools.response(fd, 200, "token error!")
  456. end
  457. local user_id = user_data.user_id
  458. if user_id==nil then
  459. return tools.response(fd,200,"user_id==nil save_template !")
  460. end
  461. msg_body["user_id"] = user_id
  462. 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)
  463. if not isok then
  464. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  465. end
  466. isok = skynet.call("dbmgr","lua","on_recv","save_template",msg_body,fd)
  467. if not isok then
  468. return tools.response(fd,200,cjson.encode({code=10001,msg = "修改模板失败"}))
  469. end
  470. return tools.response(fd,200,cjson.encode({code=10000,msg = "修改模板成功"}))
  471. end
  472. --模板搜索
  473. s.resp.search_template = function(fd,msg_body,user_data)
  474. msg_body = cjson.decode(msg_body)
  475. if type(user_data) ~= "table" then
  476. return tools.response(fd, 200, "token error!")
  477. end
  478. local user_id = user_data.user_id
  479. if user_id==nil then
  480. return tools.response(fd,200,"user_id==nil search_template !")
  481. end
  482. msg_body["user_id"] = user_id
  483. local isok ,key = tools.checkData({"video_stype","search_content","page","count"},msg_body)
  484. if not isok then
  485. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  486. end
  487. isok = skynet.call("dbmgr","lua","on_recv","search_template",msg_body,fd)
  488. end
  489. --根据模板ID获取模板信息
  490. s.resp.get_template_info_by_id = function(fd,msg_body,user_data)
  491. msg_body = cjson.decode(msg_body)
  492. if type(user_data) ~= "table" then
  493. return tools.response(fd, 200, "token error!")
  494. end
  495. local user_id = user_data.user_id
  496. if user_id==nil then
  497. return tools.response(fd,200,"user_id==nil get_template_info_by_id !")
  498. end
  499. msg_body["user_id"] = user_id
  500. local isok ,key = tools.checkData({"template_id"},msg_body)
  501. if not isok then
  502. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  503. end
  504. isok = skynet.call("dbmgr","lua","on_recv","get_template_info_by_id",msg_body,fd)
  505. end
  506. --生成视频
  507. s.resp.generate_video = function(fd,msg_body,user_data)
  508. msg_body = cjson.decode(msg_body)
  509. if type(user_data) ~= "table" then
  510. return tools.response(fd, 200, "token error!")
  511. end
  512. local user_id = user_data.user_id
  513. if user_id==nil then
  514. return tools.response(fd,200,"user_id==nil generate_video !")
  515. end
  516. msg_body["user_id"] = user_id
  517. local isok ,key = tools.checkData({"template_id"},msg_body)
  518. if not isok then
  519. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  520. end
  521. isok = skynet.call("dbmgr","lua","on_recv","generate_video",msg_body,fd)
  522. end
  523. --获取生成视频文件夹列表
  524. s.resp.get_generate_video_folder_list = function(fd,msg_body,user_data)
  525. msg_body = cjson.decode(msg_body)
  526. if type(user_data) ~= "table" then
  527. return tools.response(fd, 200, "token error!")
  528. end
  529. local user_id = user_data.user_id
  530. if user_id==nil then
  531. return tools.response(fd,100,"user_id==nil get_generate_video_folder_list !")
  532. end
  533. msg_body["user_id"] = user_id
  534. local isok ,key = tools.checkData({"page","count","video_stype"},msg_body)
  535. if not isok then
  536. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  537. end
  538. local is_public = 0
  539. if msg_body.is_public ~=nil then
  540. is_public = msg_body.is_public
  541. end
  542. isok = skynet.call("dbmgr","lua","on_recv","get_generate_video_folder_list",{user_id = user_id,
  543. page=msg_body.page,
  544. count = msg_body.count,
  545. video_stype=msg_body.video_stype}
  546. ,fd)
  547. end
  548. --获取文件夹内的生成视频
  549. s.resp.get_video_list_by_folder_id = function(fd,msg_body,user_data)
  550. msg_body = cjson.decode(msg_body)
  551. if type(user_data) ~= "table" then
  552. return tools.response(fd, 200, "token error!")
  553. end
  554. local user_id = user_data.user_id
  555. if user_id==nil then
  556. return tools.response(fd,100,"user_id==nil get_video_list_by_folder_id !")
  557. end
  558. msg_body["user_id"] = user_id
  559. local isok ,key = tools.checkData({"folder_id","page","count"},msg_body)
  560. if not isok then
  561. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  562. end
  563. local is_public = 0
  564. if msg_body.is_public ~=nil then
  565. is_public = msg_body.is_public
  566. end
  567. local duration = nil
  568. if msg_body.duration ~=nil then
  569. duration = msg_body.duration
  570. end
  571. isok = skynet.call("dbmgr","lua","on_recv","get_video_list_by_folder_id",{
  572. folder_id = msg_body.folder_id,
  573. user_id = user_id,
  574. page=msg_body.page,
  575. count = msg_body.count}
  576. ,fd)
  577. end
  578. --删除生成视频文件夹
  579. s.resp.delete_generate_video_folder = function(fd,msg_body,user_data)
  580. msg_body = cjson.decode(msg_body)
  581. if type(user_data) ~= "table" then
  582. return tools.response(fd, 200, "token error!")
  583. end
  584. local user_id = user_data.user_id
  585. if user_id==nil then
  586. return tools.response(fd,200,"user_id==nil delete_generate_video_folder !")
  587. end
  588. msg_body["user_id"] = user_id
  589. local isok ,key = tools.checkData({"folder_id_list"},msg_body)
  590. if not isok then
  591. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  592. end
  593. isok = skynet.call("dbmgr","lua","on_recv","delete_generate_video_folder",{
  594. folder_id_list = msg_body.folder_id_list,
  595. user_id = user_id}
  596. )
  597. if not isok then
  598. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!",data={}}))
  599. end
  600. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!",data={}}))
  601. end
  602. --删除生成视频
  603. s.resp.delete_generate_video = function(fd,msg_body,user_data)
  604. msg_body = cjson.decode(msg_body)
  605. if type(user_data) ~= "table" then
  606. return tools.response(fd, 200, "token error!")
  607. end
  608. local user_id = user_data.user_id
  609. if user_id==nil then
  610. return tools.response(fd,200,"user_id==nil delete_generate_video !")
  611. end
  612. msg_body["user_id"] = user_id
  613. local isok ,key = tools.checkData({"generate_video_id_list"},msg_body)
  614. if not isok then
  615. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  616. end
  617. local is_public = 0
  618. if msg_body.is_public ~=nil then
  619. is_public = msg_body.is_public
  620. end
  621. isok = skynet.call("dbmgr","lua","on_recv","delete_generate_video",{
  622. file_id_list = msg_body.generate_video_id_list,
  623. user_id = user_id}
  624. )
  625. if not isok then
  626. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除失败!"}))
  627. end
  628. return tools.response(fd,200,cjson.encode({code=10000,msg = "删除成功!"}))
  629. end
  630. --重命名生成视频文件夹的名字
  631. s.resp.reset_generate_video_folder_name = function(fd,msg_body,user_data)
  632. msg_body = cjson.decode(msg_body)
  633. if type(user_data) ~= "table" then
  634. return tools.response(fd, 200, "token error!")
  635. end
  636. local user_id = user_data.user_id
  637. if user_id==nil then
  638. return tools.response(fd,100,"user_id==nil reset_generate_video_folder_name !")
  639. end
  640. msg_body["user_id"] = user_id
  641. local isok ,key = tools.checkData({"folder_id","file_id"},msg_body)
  642. if not isok then
  643. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  644. end
  645. isok = skynet.call("dbmgr","lua","on_recv","reset_generate_video_folder_name",{
  646. folder_id = msg_body.folder_id,
  647. file_id = msg_body.file_id,
  648. user_id = user_id}
  649. )
  650. if not isok then
  651. return tools.response(fd,200,cjson.encode({code=10001,msg = "重命名生成视频文件夹的名字失败"}))
  652. end
  653. return tools.response(fd,200,cjson.encode({code=10000,msg = "重命名生成视频文件夹的名字成功"}))
  654. end
  655. --生成视频搜索
  656. s.resp.search_generate_video_file = function(fd,msg_body,user_data)
  657. msg_body = cjson.decode(msg_body)
  658. if type(user_data) ~= "table" then
  659. return tools.response(fd, 200, "token error!")
  660. end
  661. local user_id = user_data.user_id
  662. if user_id==nil then
  663. return tools.response(fd,100,"user_id==nil reset_generate_video_folder_name !")
  664. end
  665. msg_body["user_id"] = user_id
  666. local isok ,key = tools.checkData({"page","count","video_stype","search_content"},msg_body)
  667. if not isok then
  668. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  669. end
  670. isok = skynet.call("dbmgr","lua","on_recv","search_generate_video_file",{
  671. search_content = msg_body.search_content,
  672. page = msg_body.page,
  673. count = msg_body.count,
  674. user_id = msg_body.user_id,
  675. video_stype = msg_body.video_stype},fd
  676. )
  677. end
  678. --检测指定类型文件是否够数量
  679. s.resp.checkNumsByType = function(fd,msg_body,user_data)
  680. msg_body = cjson.decode(msg_body)
  681. if type(user_data) ~= "table" then
  682. return tools.response(fd, 200, "token error!")
  683. end
  684. local user_id = user_data.user_id
  685. if user_id==nil then
  686. return tools.response(fd,100,"user_id==nil checkNumsByType !")
  687. end
  688. msg_body["user_id"] = user_id
  689. local isok ,key = tools.checkData({"type","limit"},msg_body)
  690. if not isok then
  691. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  692. end
  693. isok = skynet.call("dbmgr","lua","on_recv","checkNumsByType",{
  694. duration = msg_body.duration,
  695. type = msg_body.type,
  696. limit = msg_body.limit,
  697. user_id = user_id}
  698. )
  699. if not isok then
  700. return tools.response(fd,200,cjson.encode({code=10001,msg = "条件不足"}))
  701. end
  702. return tools.response(fd,200,cjson.encode({code=10000,msg = "条件成立"}))
  703. end
  704. --修改密码
  705. s.resp.reset_password = function(fd,msg_body,user_data)
  706. msg_body = cjson.decode(msg_body)
  707. if type(user_data) ~= "table" then
  708. return tools.response(fd, 200, "token error!")
  709. end
  710. local user_id = user_data.user_id
  711. if user_id==nil then
  712. return tools.response(fd,100,"user_id==nil reset_password !")
  713. end
  714. msg_body["user_id"] = user_id
  715. local isok ,key = tools.checkData({"new_pw","sure_pw"},msg_body)
  716. if not isok then
  717. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  718. end
  719. if msg_body.new_pw~=msg_body.sure_pw then
  720. return tools.response(fd,200,cjson.encode({code=9002,msg ="两次密码不一致!"}))
  721. end
  722. isok = skynet.call("dbmgr","lua","on_recv","reset_password",{
  723. new_pw = msg_body.new_pw,
  724. sure_pw = msg_body.sure_pw,
  725. user_id = user_id}
  726. )
  727. if not isok then
  728. return tools.response(fd,200,cjson.encode({code=10001,msg = "修改密码失败!"}))
  729. end
  730. return tools.response(fd,200,cjson.encode({code=10000,msg = "修改密码成功!"}))
  731. end
  732. s.resp.update_generate_video_custom = function(fd,msg_body,user_data)
  733. msg_body = cjson.decode(msg_body)
  734. if type(user_data) ~= "table" then
  735. return tools.response(fd, 200, "token error!")
  736. end
  737. local user_id = user_data.user_id
  738. -- tools.dump(msg_body)
  739. if user_id==nil then
  740. return tools.response(fd,100,"user_id==nil update_generate_video_custom !")
  741. end
  742. msg_body["user_id"] = user_id
  743. local isok ,key = tools.checkData({"data"},msg_body)
  744. if not isok then
  745. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  746. end
  747. isok = skynet.call("dbmgr","lua","on_recv","update_generate_video_custom",{
  748. data = msg_body.data,
  749. user_id = user_id}
  750. )
  751. if not isok then
  752. return tools.response(fd,200,cjson.encode({code=10001,msg = "更新失败!"}))
  753. end
  754. return tools.response(fd,200,cjson.encode({code=10000,msg = "更新成功!"}))
  755. end
  756. --更新用户所有的文件数
  757. s.resp.update_user_folder_list_nums = function(user_id)
  758. skynet.fork(function()
  759. local count = skynet.call("dbmgr","lua","on_recv","get_user_folder_list_nums",{
  760. user_id = user_id}
  761. )
  762. playersInfo.user_folder_nums[user_id] = count
  763. end)
  764. end
  765. --更新用户指定类型的数量
  766. s.resp.update_user_file_count_by_type = function(user_id,file_type)
  767. skynet.fork(function()
  768. local key = user_id.."_"..file_type
  769. local count = skynet.call("dbmgr","lua","on_recv","get_user_file_count_by_type",{
  770. user_id = user_id,
  771. file_type = file_type}
  772. )
  773. playersInfo.user_file_type_nums[key] = count
  774. end)
  775. end
  776. --获取用户所有的文件数
  777. s.resp.get_user_folder_list_nums = function(user_id)
  778. if playersInfo.user_folder_nums[user_id]~=nil then
  779. return playersInfo.user_folder_nums[user_id]
  780. else
  781. local count = skynet.call("dbmgr","lua","on_recv","get_user_folder_list_nums",{
  782. user_id = user_id}
  783. )
  784. playersInfo.user_folder_nums[user_id] = count
  785. return count
  786. end
  787. end
  788. --获取用户指定类型的数量
  789. s.resp.get_user_file_count_by_type = function(user_id,file_type)
  790. local key = user_id.."_"..file_type
  791. if playersInfo.user_file_type_nums[key]~=nil then
  792. return playersInfo.user_file_type_nums[key]
  793. else
  794. local count = skynet.call("dbmgr","lua","on_recv","get_user_file_count_by_type",{
  795. user_id = user_id,
  796. file_type = file_type}
  797. )
  798. playersInfo.user_file_type_nums[key] = count
  799. return count
  800. end
  801. end
  802. --分享文件列表
  803. s.resp.share_file_list = function(fd,msg_body,user_data)
  804. msg_body = cjson.decode(msg_body)
  805. if type(user_data) ~= "table" then
  806. return tools.response(fd, 200, "token error!")
  807. end
  808. local user_id = user_data.user_id
  809. -- tools.dump(msg_body)
  810. if user_id==nil then
  811. return tools.response(fd,100,"user_id==nil share_file_list !")
  812. end
  813. msg_body["user_id"] = user_id
  814. local isok ,key = tools.checkData({"file_id_list","target_user_id_list"},msg_body)
  815. if not isok then
  816. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  817. end
  818. isok = skynet.call("dbmgr","lua","on_recv","share_file_list",{
  819. file_id_list = msg_body.file_id_list,
  820. target_user_id_list = msg_body.target_user_id_list,
  821. user_id = user_id},fd
  822. )
  823. if not isok then
  824. return tools.response(fd,200,cjson.encode({code=10001,msg = "分享文件列表失败!"}))
  825. end
  826. return tools.response(fd,200,cjson.encode({code=10000,msg = "分享文件列表成功!"}))
  827. end
  828. --分享文件夹列表
  829. s.resp.share_folder_list = function(fd,msg_body,user_data)
  830. msg_body = cjson.decode(msg_body)
  831. if type(user_data) ~= "table" then
  832. return tools.response(fd, 200, "token error!")
  833. end
  834. local user_id = user_data.user_id
  835. -- tools.dump(msg_body)
  836. if user_id==nil then
  837. return tools.response(fd,100,"user_id==nil share_folder_list !")
  838. end
  839. msg_body["user_id"] = user_id
  840. local isok ,key = tools.checkData({"folder_id_list","target_user_id_list"},msg_body)
  841. if not isok then
  842. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  843. end
  844. isok = skynet.call("dbmgr","lua","on_recv","share_folder_list",{
  845. folder_id_list = msg_body.folder_id_list,
  846. target_user_id_list = msg_body.target_user_id_list,
  847. user_id = user_id},fd
  848. )
  849. if not isok then
  850. return tools.response(fd,200,cjson.encode({code=10001,msg = "分享文件夹列表失败!"}))
  851. end
  852. return tools.response(fd,200,cjson.encode({code=10000,msg = "分享文件夹列表成功!"}))
  853. end
  854. --获取用户的分享用户列表
  855. s.resp.get_share_user_list = function(fd,msg_body,user_data)
  856. msg_body = cjson.decode(msg_body)
  857. if type(user_data) ~= "table" then
  858. return tools.response(fd, 200, "token error!")
  859. end
  860. local user_id = user_data.user_id
  861. -- tools.dump(msg_body)
  862. if user_id==nil then
  863. return tools.response(fd,100,"user_id==nil get_share_user_list !")
  864. end
  865. msg_body["user_id"] = user_id
  866. local isok ,key = tools.checkData({"count","page"},msg_body)
  867. if not isok then
  868. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  869. end
  870. isok = skynet.call("dbmgr","lua","on_recv","get_share_user_list",{
  871. count = msg_body.count,
  872. page = msg_body.page,
  873. user_id = user_id},fd
  874. )
  875. end
  876. --检测文件夹下是否有相同命名的资源
  877. s.resp.check_file_name_list_is_repeat_by_folder_id = function(fd,msg_body,user_data)
  878. msg_body = cjson.decode(msg_body)
  879. if type(user_data) ~= "table" then
  880. return tools.response(fd, 200, "token error!")
  881. end
  882. local user_id = user_data.user_id
  883. -- tools.dump(msg_body)
  884. if user_id==nil then
  885. return tools.response(fd,100,"user_id==nil check_file_name_list_is_repeat_by_folder_id !")
  886. end
  887. msg_body["user_id"] = user_id
  888. local isok ,key = tools.checkData({"folder_id","file_name_list"},msg_body)
  889. if not isok then
  890. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  891. end
  892. isok = skynet.call("dbmgr","lua","on_recv","check_file_name_list_is_repeat_by_folder_id",{
  893. folder_id = msg_body.folder_id,
  894. file_name_list = msg_body.file_name_list,
  895. user_id = user_id},fd
  896. )
  897. end
  898. s.resp.get_folder_info = function(fd,msg_body,user_data)
  899. msg_body = cjson.decode(msg_body)
  900. if type(user_data) ~= "table" then
  901. return tools.response(fd, 200, "token error!")
  902. end
  903. local user_id = user_data.user_id
  904. -- tools.dump(msg_body)
  905. if user_id==nil then
  906. return tools.response(fd,100,"user_id==nil get_folder_info !")
  907. end
  908. msg_body["user_id"] = user_id
  909. local isok ,key = tools.checkData({"folder_id_list"},msg_body)
  910. if not isok then
  911. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  912. end
  913. isok = skynet.call("dbmgr","lua","on_recv","get_folder_info",{
  914. folder_id_list = msg_body.folder_id_list,
  915. user_id = user_id},fd
  916. )
  917. end
  918. --根据文件ID获取文件信息
  919. s.resp.get_file_info_by_id = function(fd,msg_body,user_data)
  920. msg_body = cjson.decode(msg_body)
  921. if type(user_data) ~= "table" then
  922. return tools.response(fd, 200, "token error!")
  923. end
  924. local user_id = user_data.user_id
  925. -- tools.dump(msg_body)
  926. if user_id==nil then
  927. return tools.response(fd,100,"user_id==nil get_file_info_by_id !")
  928. end
  929. msg_body["user_id"] = user_id
  930. local isok ,key = tools.checkData({"file_id"},msg_body)
  931. if not isok then
  932. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  933. end
  934. isok = skynet.call("dbmgr","lua","on_recv","get_file_info_by_id",{
  935. file_id = msg_body.file_id,
  936. user_id = user_id},fd
  937. )
  938. end
  939. --获取文件列表中已删除的文件
  940. s.resp.get_not_have_file_list_by_list = function(fd,msg_body,user_data)
  941. msg_body = cjson.decode(msg_body)
  942. if type(user_data) ~= "table" then
  943. return tools.response(fd, 200, "token error!")
  944. end
  945. local user_id = user_data.user_id
  946. -- tools.dump(msg_body)
  947. if user_id==nil then
  948. return tools.response(fd,100,"user_id==nil get_not_have_file_list_by_list !")
  949. end
  950. msg_body["user_id"] = user_id
  951. local isok ,key = tools.checkData({"file_id_list"},msg_body)
  952. if not isok then
  953. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  954. end
  955. isok = skynet.call("dbmgr","lua","on_recv","get_not_have_file_list_by_list",{
  956. file_id_list = msg_body.file_id_list,
  957. user_id = user_id},fd
  958. )
  959. end
  960. --存储数据
  961. s.resp.setItem = function(fd,msg_body,user_data)
  962. msg_body = cjson.decode(msg_body)
  963. if type(user_data) ~= "table" then
  964. return tools.response(fd, 200, "token error!")
  965. end
  966. local user_id = user_data.user_id
  967. -- tools.dump(msg_body)
  968. if user_id==nil then
  969. return tools.response(fd,100,"user_id==nil setItem !")
  970. end
  971. msg_body["user_id"] = user_id
  972. local isok ,key = tools.checkData({"key","base64value"},msg_body)
  973. if not isok then
  974. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  975. end
  976. isok = skynet.call("dbmgr","lua","on_recv","setItem",{
  977. key = msg_body.key,
  978. base64value = msg_body.base64value,
  979. user_id = user_id},fd
  980. )
  981. end
  982. --获取数据
  983. s.resp.getItem = function(fd,msg_body,user_data)
  984. msg_body = cjson.decode(msg_body)
  985. if type(user_data) ~= "table" then
  986. return tools.response(fd, 200, "token error!")
  987. end
  988. local user_id = user_data.user_id
  989. -- tools.dump(msg_body)
  990. if user_id==nil then
  991. return tools.response(fd,100,"user_id==nil getItem !")
  992. end
  993. msg_body["user_id"] = user_id
  994. local isok ,key = tools.checkData({"key"},msg_body)
  995. if not isok then
  996. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  997. end
  998. isok = skynet.call("dbmgr","lua","on_recv","getItem",{
  999. key = msg_body.key,
  1000. user_id = user_id},fd
  1001. )
  1002. end
  1003. --踢掉
  1004. s.resp.kick = function(fd,msg_body,user_data)
  1005. end
  1006. s.resp.on_recv = function (source, fd, msg_id, msg_body,user_data)
  1007. skynet.error("接收一条客户端消息 ",msg_id,user_data)
  1008. local func = string.gsub(msg_id, '/', '')
  1009. if s.resp[func] ==nil then
  1010. return ools.response(fd,200,"???")
  1011. end
  1012. if func ~= "login" then
  1013. if not s.resp.account_is_other_user_login(source,user_data.user_id,user_data.index) then
  1014. else
  1015. skynet.error("用户被挤掉",user_data.user_id)
  1016. return tools.response(fd,200,cjson.encode({code=999,msg = "您的账号被其他用户登录!"}))
  1017. end
  1018. end
  1019. if s.resp[func] ~=nil then
  1020. return s.resp[func](fd,msg_body,user_data)
  1021. end
  1022. return tools.response(fd,200,string.format("接口 %s 不存在",func))
  1023. end
  1024. s.start(...)