init.lua 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. local skynet = require "skynet"
  2. local s = require "service"
  3. local tools = require "tools"
  4. local cjson = require "cjson"
  5. local httpc = require "http.httpc"
  6. local runconfig = require "run_config"
  7. s.resp.upload_video_sync = function(fd,msg_body)
  8. -- skynet.error("msg_body",msg_body)
  9. msg_body = cjson.decode(msg_body)
  10. local isOk,key = tools.checkToolsSyncVideo(msg_body)
  11. if not isOk then
  12. local str = string.format("缺少字段: %s.", key)
  13. return tools.response(fd,200,cjson.encode({code=9001,msg = str}))
  14. end
  15. isOk = skynet.call("dbmgr","lua","on_recv","add_res_file",msg_body)
  16. if not isOk then
  17. return tools.response(fd,200,cjson.encode({code=10001,msg = "失败"}))
  18. else
  19. return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!"}))
  20. end
  21. end
  22. s.resp.upload_audio_sync = function(fd,msg_body)
  23. skynet.error("msg_body",msg_body)
  24. msg_body = cjson.decode(msg_body)
  25. local isOk,key = tools.checkData({"folder_id","stype","surl","path","file_name","classification_id"},msg_body)
  26. if not isOk then
  27. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  28. end
  29. isOk = skynet.call("dbmgr","lua","on_recv","add_res_file",msg_body)
  30. if not isOk then
  31. return tools.response(fd,200,cjson.encode({code=10001,msg = "失败"}))
  32. else
  33. return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!"}))
  34. end
  35. end
  36. s.resp.upload_img_sync = function(fd,msg_body)
  37. skynet.error("msg_body",msg_body)
  38. msg_body = cjson.decode(msg_body)
  39. local isOk,key = tools.checkData({"folder_id","stype","is_public","surl","path","file_name","classification_id"},msg_body)
  40. if not isOk then
  41. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  42. end
  43. isOk = skynet.call("dbmgr","lua","on_recv","add_res_file",msg_body)
  44. if not isOk then
  45. return tools.response(fd,200,cjson.encode({code=10001,msg = "失败"}))
  46. else
  47. return tools.response(fd,200,cjson.encode({code=10000,msg = "成功!"}))
  48. end
  49. end
  50. s.resp.generate_video_sync = function(fd,msg_body)
  51. skynet.error("generate_video_sync",msg_body)
  52. msg_body = cjson.decode(msg_body)
  53. local isOk,key = tools.checkData({"id","state","path","user_id","surl","custom"},msg_body)
  54. if not isOk then
  55. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  56. end
  57. isOk = skynet.call("dbmgr","lua","on_recv","update_gen_video_file_status",msg_body)
  58. if not isOk then
  59. return tools.response(fd,200,cjson.encode({code=2,msg = "失败"}))
  60. else
  61. return tools.response(fd,200,cjson.encode({code=1,msg = "成功!"}))
  62. end
  63. end
  64. s.resp.upload_public_res_info = function(fd,msg_body)
  65. msg_body = cjson.decode(msg_body)
  66. local isOk,key = tools.checkToolsSyncVideo(msg_body)
  67. if not isOk then
  68. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  69. end
  70. isOk = skynet.call("public_mgr","lua","tools_add_public_res_info",fd,msg_body)
  71. if not isOk then
  72. return tools.response(fd,200,cjson.encode({code=2,msg = "失败"}))
  73. else
  74. local code = 10000
  75. if msg_body.user_id ~= nil then
  76. if msg_body.user_id==-1 then
  77. code = 1
  78. end
  79. end
  80. return tools.response(fd,200,cjson.encode({code=code,msg = "成功!"}))
  81. end
  82. end
  83. s.resp.tools_create_folder = function(fd,msg_body)
  84. msg_body = cjson.decode(msg_body)
  85. local isOk,key = tools.checkData({"classification_id","stype", "folder_name","user_id"},msg_body)
  86. if not isOk then
  87. return tools.response(fd,200,cjson.encode({code=9001,msg = string.format("缺少字段: %s.", key)}))
  88. end
  89. isOk = skynet.call("public_mgr","lua","tools_create_folder",fd,msg_body)
  90. end
  91. s.resp.on_recv = function (source, fd, msg_id, msg_body)
  92. skynet.error("接收一条工具消息 ",msg_id)
  93. local func = string.gsub(msg_id, "/tools/", "")
  94. if s.resp[func] ~=nil then
  95. return s.resp[func](fd,msg_body)
  96. end
  97. return tools.response(fd,200,string.format("接口 %s 不存在",func))
  98. end
  99. s.resp.delete_file = function(source,file_paths)
  100. httpc.dns() -- set dns server
  101. httpc.timeout = 100 -- set timeout 1 second
  102. local func = '/file/deletes'
  103. local respheader = {}
  104. -- skynet.error("file_paths",file_paths)
  105. -- tools.dump(file_paths)
  106. local status, body = httpc.post(runconfig.tools_api,func,{file_paths=cjson.encode(file_paths)})
  107. if status == 200 then
  108. skynet.error("删除成功!")
  109. else
  110. skynet.error("删除失败!")
  111. end
  112. end
  113. s.resp.generate_video = function(source,msg_body)
  114. httpc.dns() -- set dns server
  115. httpc.timeout = 100 -- set timeout 1 second
  116. local func = '/video/generate'
  117. local respheader = {}
  118. -- skynet.error("file_paths",msg_body)
  119. -- tools.dump(msg_body)
  120. local status, body = httpc.post(runconfig.tools_api,func,{sdata=cjson.encode(msg_body)})
  121. if status == 200 then
  122. skynet.error("生成成功!")
  123. else
  124. skynet.error("生成失败!",status)
  125. end
  126. end
  127. s.start(...)