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.

83 lines
1.9 KiB

  1. "use strict";
  2. module.exports = (socket) => {
  3. //-----------------------------------------
  4. // SEARCH
  5. //-----------------------------------------
  6. socket.on('search', (data, cb) => {
  7. cb = cb || _.noop;
  8. entries.search(data.terms).then((results) => {
  9. return cb(results) || true;
  10. });
  11. });
  12. //-----------------------------------------
  13. // UPLOADS
  14. //-----------------------------------------
  15. socket.on('uploadsGetFolders', (data, cb) => {
  16. cb = cb || _.noop;
  17. upl.getUploadsFolders().then((f) => {
  18. return cb(f) || true;
  19. });
  20. });
  21. socket.on('uploadsCreateFolder', (data, cb) => {
  22. cb = cb || _.noop;
  23. upl.createUploadsFolder(data.foldername).then((f) => {
  24. return cb(f) || true;
  25. });
  26. });
  27. socket.on('uploadsGetImages', (data, cb) => {
  28. cb = cb || _.noop;
  29. upl.getUploadsFiles('image', data.folder).then((f) => {
  30. return cb(f) || true;
  31. });
  32. });
  33. socket.on('uploadsDeleteFile', (data, cb) => {
  34. cb = cb || _.noop;
  35. upl.deleteUploadsFile(data.uid).then((f) => {
  36. return cb(f) || true;
  37. });
  38. });
  39. socket.on('uploadsFetchFileFromURL', (data, cb) => {
  40. cb = cb || _.noop;
  41. upl.downloadFromUrl(data.folder, data.fetchUrl).then((f) => {
  42. return cb({ ok: true }) || true;
  43. }).catch((err) => {
  44. return cb({
  45. ok: false,
  46. msg: err.message
  47. }) || true;
  48. });
  49. });
  50. socket.on('uploadsRenameFile', (data, cb) => {
  51. cb = cb || _.noop;
  52. upl.moveUploadsFile(data.uid, data.folder, data.filename).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('uploadsMoveFile', (data, cb) => {
  62. cb = cb || _.noop;
  63. upl.moveUploadsFile(data.uid, data.folder).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. };