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.

87 lines
2.0 KiB

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