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.

110 lines
2.7 KiB

  1. 'use strict'
  2. /* eslint-disable standard/no-callback-literal */
  3. const _ = require('lodash')
  4. module.exports = (socket) => {
  5. // -----------------------------------------
  6. // SEARCH
  7. // -----------------------------------------
  8. if (appconfig.public || socket.request.user.logged_in) {
  9. socket.on('search', (data, cb) => {
  10. cb = cb || _.noop
  11. search.find(data.terms).then((results) => {
  12. return cb(results) || true
  13. })
  14. })
  15. }
  16. // -----------------------------------------
  17. // TREE VIEW (LIST ALL PAGES)
  18. // -----------------------------------------
  19. if (socket.request.user.logged_in) {
  20. socket.on('treeFetch', (data, cb) => {
  21. cb = cb || _.noop
  22. entries.getFromTree(data.basePath).then((f) => {
  23. return cb(f) || true
  24. })
  25. })
  26. }
  27. // -----------------------------------------
  28. // UPLOADS
  29. // -----------------------------------------
  30. if (socket.request.user.logged_in) {
  31. socket.on('uploadsGetFolders', (data, cb) => {
  32. cb = cb || _.noop
  33. upl.getUploadsFolders().then((f) => {
  34. return cb(f) || true
  35. })
  36. })
  37. socket.on('uploadsCreateFolder', (data, cb) => {
  38. cb = cb || _.noop
  39. upl.createUploadsFolder(data.foldername).then((f) => {
  40. return cb(f) || true
  41. })
  42. })
  43. socket.on('uploadsGetImages', (data, cb) => {
  44. cb = cb || _.noop
  45. upl.getUploadsFiles('image', data.folder).then((f) => {
  46. return cb(f) || true
  47. })
  48. })
  49. socket.on('uploadsGetFiles', (data, cb) => {
  50. cb = cb || _.noop
  51. upl.getUploadsFiles('binary', data.folder).then((f) => {
  52. return cb(f) || true
  53. })
  54. })
  55. socket.on('uploadsDeleteFile', (data, cb) => {
  56. cb = cb || _.noop
  57. upl.deleteUploadsFile(data.uid).then((f) => {
  58. return cb(f) || true
  59. })
  60. })
  61. socket.on('uploadsFetchFileFromURL', (data, cb) => {
  62. cb = cb || _.noop
  63. upl.downloadFromUrl(data.folder, data.fetchUrl).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('uploadsRenameFile', (data, cb) => {
  73. cb = cb || _.noop
  74. upl.moveUploadsFile(data.uid, data.folder, data.filename).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. socket.on('uploadsMoveFile', (data, cb) => {
  84. cb = cb || _.noop
  85. upl.moveUploadsFile(data.uid, data.folder).then((f) => {
  86. return cb({ ok: true }) || true
  87. }).catch((err) => {
  88. return cb({
  89. ok: false,
  90. msg: err.message
  91. }) || true
  92. })
  93. })
  94. }
  95. }