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.

116 lines
2.9 KiB

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