init.lua 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028
  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. --踢掉
  919. s.resp.kick = function(fd,msg_body,user_data)
  920. end
  921. s.resp.on_recv = function (source, fd, msg_id, msg_body,user_data)
  922. skynet.error("接收一条客户端消息 ",msg_id,user_data)
  923. local func = string.gsub(msg_id, '/', '')
  924. if s.resp[func] ==nil then
  925. return ools.response(fd,200,"???")
  926. end
  927. if func ~= "login" then
  928. if not s.resp.account_is_other_user_login(source,user_data.user_id,user_data.index) then
  929. else
  930. skynet.error("用户被挤掉",user_data.user_id)
  931. return tools.response(fd,200,cjson.encode({code=999,msg = "您的账号被其他用户登录!"}))
  932. end
  933. end
  934. if s.resp[func] ~=nil then
  935. return s.resp[func](fd,msg_body,user_data)
  936. end
  937. return tools.response(fd,200,string.format("接口 %s 不存在",func))
  938. end
  939. s.start(...)