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.

95 lines
2.2 KiB

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