You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
2.2 KiB

  1. 'use strict'
  2. /* eslint-disable standard/no-callback-literal */
  3. const _ = require('lodash')
  4. module.exports = (socket) => {
  5. if (!socket.request.user.logged_in) {
  6. return
  7. }
  8. // -----------------------------------------
  9. // SEARCH
  10. // -----------------------------------------
  11. socket.on('search', (data, cb) => {
  12. cb = cb || _.noop
  13. search.find(data.terms).then((results) => {
  14. return cb(results) || true
  15. })
  16. })
  17. // -----------------------------------------
  18. // UPLOADS
  19. // -----------------------------------------
  20. socket.on('uploadsGetFolders', (data, cb) => {
  21. cb = cb || _.noop
  22. upl.getUploadsFolders().then((f) => {
  23. return cb(f) || true
  24. })
  25. })
  26. socket.on('uploadsCreateFolder', (data, cb) => {
  27. cb = cb || _.noop
  28. upl.createUploadsFolder(data.foldername).then((f) => {
  29. return cb(f) || true
  30. })
  31. })
  32. socket.on('uploadsGetImages', (data, cb) => {
  33. cb = cb || _.noop
  34. upl.getUploadsFiles('image', data.folder).then((f) => {
  35. return cb(f) || true
  36. })
  37. })
  38. socket.on('uploadsGetFiles', (data, cb) => {
  39. cb = cb || _.noop
  40. upl.getUploadsFiles('binary', data.folder).then((f) => {
  41. return cb(f) || true
  42. })
  43. })
  44. socket.on('uploadsDeleteFile', (data, cb) => {
  45. cb = cb || _.noop
  46. upl.deleteUploadsFile(data.uid).then((f) => {
  47. return cb(f) || true
  48. })
  49. })
  50. socket.on('uploadsFetchFileFromURL', (data, cb) => {
  51. cb = cb || _.noop
  52. upl.downloadFromUrl(data.folder, data.fetchUrl).then((f) => {
  53. return cb({ ok: true }) || true
  54. }).catch((err) => {
  55. return cb({
  56. ok: false,
  57. msg: err.message
  58. }) || true
  59. })
  60. })
  61. socket.on('uploadsRenameFile', (data, cb) => {
  62. cb = cb || _.noop
  63. upl.moveUploadsFile(data.uid, data.folder, data.filename).then((f) => {
  64. return cb({ ok: true }) || true
  65. }).catch((err) => {
  66. return cb({
  67. ok: false,
  68. msg: err.message
  69. }) || true
  70. })
  71. })
  72. socket.on('uploadsMoveFile', (data, cb) => {
  73. cb = cb || _.noop
  74. upl.moveUploadsFile(data.uid, data.folder).then((f) => {
  75. return cb({ ok: true }) || true
  76. }).catch((err) => {
  77. return cb({
  78. ok: false,
  79. msg: err.message
  80. }) || true
  81. })
  82. })
  83. }