2017-02-09 01:52:37 +00:00
|
|
|
'use strict'
|
|
|
|
|
2017-04-05 02:04:17 +00:00
|
|
|
/* eslint-disable standard/no-callback-literal */
|
|
|
|
|
2017-02-09 01:52:37 +00:00
|
|
|
const _ = require('lodash')
|
2016-10-16 05:34:34 +00:00
|
|
|
|
|
|
|
module.exports = (socket) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
if (!socket.request.user.logged_in) {
|
|
|
|
return
|
2016-10-31 03:03:36 +00:00
|
|
|
}
|
2016-10-16 05:34:34 +00:00
|
|
|
|
2017-02-09 01:52:37 +00:00
|
|
|
// -----------------------------------------
|
2016-10-16 05:34:34 +00:00
|
|
|
// SEARCH
|
2017-02-09 01:52:37 +00:00
|
|
|
// -----------------------------------------
|
2016-10-16 05:34:34 +00:00
|
|
|
|
|
|
|
socket.on('search', (data, cb) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
cb = cb || _.noop
|
2017-02-12 20:40:43 +00:00
|
|
|
search.find(data.terms).then((results) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb(results) || true
|
|
|
|
})
|
|
|
|
})
|
2016-10-16 05:34:34 +00:00
|
|
|
|
2017-02-09 01:52:37 +00:00
|
|
|
// -----------------------------------------
|
2016-10-16 05:34:34 +00:00
|
|
|
// UPLOADS
|
2017-02-09 01:52:37 +00:00
|
|
|
// -----------------------------------------
|
2016-10-16 05:34:34 +00:00
|
|
|
|
|
|
|
socket.on('uploadsGetFolders', (data, cb) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
cb = cb || _.noop
|
2016-10-16 05:34:34 +00:00
|
|
|
upl.getUploadsFolders().then((f) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb(f) || true
|
|
|
|
})
|
|
|
|
})
|
2016-10-16 05:34:34 +00:00
|
|
|
|
|
|
|
socket.on('uploadsCreateFolder', (data, cb) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
cb = cb || _.noop
|
2016-10-16 05:34:34 +00:00
|
|
|
upl.createUploadsFolder(data.foldername).then((f) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb(f) || true
|
|
|
|
})
|
|
|
|
})
|
2016-10-16 05:34:34 +00:00
|
|
|
|
|
|
|
socket.on('uploadsGetImages', (data, cb) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
cb = cb || _.noop
|
2016-10-16 05:34:34 +00:00
|
|
|
upl.getUploadsFiles('image', data.folder).then((f) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb(f) || true
|
|
|
|
})
|
|
|
|
})
|
2016-10-16 05:34:34 +00:00
|
|
|
|
2016-12-22 01:38:12 +00:00
|
|
|
socket.on('uploadsGetFiles', (data, cb) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
cb = cb || _.noop
|
2016-12-22 01:38:12 +00:00
|
|
|
upl.getUploadsFiles('binary', data.folder).then((f) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb(f) || true
|
|
|
|
})
|
|
|
|
})
|
2016-12-22 01:38:12 +00:00
|
|
|
|
2016-10-16 05:34:34 +00:00
|
|
|
socket.on('uploadsDeleteFile', (data, cb) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
cb = cb || _.noop
|
2016-10-16 05:34:34 +00:00
|
|
|
upl.deleteUploadsFile(data.uid).then((f) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb(f) || true
|
|
|
|
})
|
|
|
|
})
|
2016-10-16 23:09:43 +00:00
|
|
|
|
|
|
|
socket.on('uploadsFetchFileFromURL', (data, cb) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
cb = cb || _.noop
|
2016-10-16 23:09:43 +00:00
|
|
|
upl.downloadFromUrl(data.folder, data.fetchUrl).then((f) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb({ ok: true }) || true
|
2016-10-16 23:09:43 +00:00
|
|
|
}).catch((err) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb({
|
|
|
|
ok: false,
|
|
|
|
msg: err.message
|
|
|
|
}) || true
|
|
|
|
})
|
|
|
|
})
|
2016-10-16 05:34:34 +00:00
|
|
|
|
2016-10-17 03:24:19 +00:00
|
|
|
socket.on('uploadsRenameFile', (data, cb) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
cb = cb || _.noop
|
2016-10-17 03:24:19 +00:00
|
|
|
upl.moveUploadsFile(data.uid, data.folder, data.filename).then((f) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb({ ok: true }) || true
|
2016-10-17 03:24:19 +00:00
|
|
|
}).catch((err) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb({
|
|
|
|
ok: false,
|
|
|
|
msg: err.message
|
|
|
|
}) || true
|
|
|
|
})
|
|
|
|
})
|
2016-10-17 03:24:19 +00:00
|
|
|
|
|
|
|
socket.on('uploadsMoveFile', (data, cb) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
cb = cb || _.noop
|
2016-10-17 03:24:19 +00:00
|
|
|
upl.moveUploadsFile(data.uid, data.folder).then((f) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb({ ok: true }) || true
|
2016-10-17 03:24:19 +00:00
|
|
|
}).catch((err) => {
|
2017-02-09 01:52:37 +00:00
|
|
|
return cb({
|
|
|
|
ok: false,
|
|
|
|
msg: err.message
|
|
|
|
}) || true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|