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
|
|
|
// -----------------------------------------
|
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
|
|
|
|
2017-04-16 16:30:19 +00:00
|
|
|
if (appconfig.public || socket.request.user.logged_in) {
|
|
|
|
socket.on('search', (data, cb) => {
|
|
|
|
cb = cb || _.noop
|
|
|
|
search.find(data.terms).then((results) => {
|
|
|
|
return cb(results) || true
|
|
|
|
})
|
2017-02-09 01:52:37 +00:00
|
|
|
})
|
2017-04-16 16:30:19 +00:00
|
|
|
}
|
2016-10-16 05:34:34 +00:00
|
|
|
|
2017-04-18 02:44:04 +00:00
|
|
|
// -----------------------------------------
|
|
|
|
// TREE VIEW (LIST ALL PAGES)
|
|
|
|
// -----------------------------------------
|
|
|
|
|
|
|
|
if (socket.request.user.logged_in) {
|
|
|
|
socket.on('treeFetch', (data, cb) => {
|
|
|
|
cb = cb || _.noop
|
2017-04-29 16:28:59 +00:00
|
|
|
entries.getFromTree(data.basePath, socket.request.user).then((f) => {
|
2017-04-18 02:44:04 +00:00
|
|
|
return cb(f) || true
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2017-04-16 16:30:19 +00:00
|
|
|
if (socket.request.user.logged_in) {
|
|
|
|
socket.on('uploadsGetFolders', (data, cb) => {
|
|
|
|
cb = cb || _.noop
|
|
|
|
upl.getUploadsFolders().then((f) => {
|
|
|
|
return cb(f) || true
|
|
|
|
})
|
2017-02-09 01:52:37 +00:00
|
|
|
})
|
2016-10-16 05:34:34 +00:00
|
|
|
|
2017-04-16 16:30:19 +00:00
|
|
|
socket.on('uploadsCreateFolder', (data, cb) => {
|
|
|
|
cb = cb || _.noop
|
|
|
|
upl.createUploadsFolder(data.foldername).then((f) => {
|
|
|
|
return cb(f) || true
|
|
|
|
})
|
2017-02-09 01:52:37 +00:00
|
|
|
})
|
2016-10-16 05:34:34 +00:00
|
|
|
|
2017-04-16 16:30:19 +00:00
|
|
|
socket.on('uploadsGetImages', (data, cb) => {
|
|
|
|
cb = cb || _.noop
|
|
|
|
upl.getUploadsFiles('image', data.folder).then((f) => {
|
|
|
|
return cb(f) || true
|
|
|
|
})
|
2017-02-09 01:52:37 +00:00
|
|
|
})
|
2016-10-16 05:34:34 +00:00
|
|
|
|
2017-04-16 16:30:19 +00:00
|
|
|
socket.on('uploadsGetFiles', (data, cb) => {
|
|
|
|
cb = cb || _.noop
|
|
|
|
upl.getUploadsFiles('binary', data.folder).then((f) => {
|
|
|
|
return cb(f) || true
|
|
|
|
})
|
2017-02-09 01:52:37 +00:00
|
|
|
})
|
2016-12-22 01:38:12 +00:00
|
|
|
|
2017-04-16 16:30:19 +00:00
|
|
|
socket.on('uploadsDeleteFile', (data, cb) => {
|
|
|
|
cb = cb || _.noop
|
|
|
|
upl.deleteUploadsFile(data.uid).then((f) => {
|
|
|
|
return cb(f) || true
|
|
|
|
})
|
2017-02-09 01:52:37 +00:00
|
|
|
})
|
2016-10-16 23:09:43 +00:00
|
|
|
|
2017-04-16 16:30:19 +00:00
|
|
|
socket.on('uploadsFetchFileFromURL', (data, cb) => {
|
|
|
|
cb = cb || _.noop
|
|
|
|
upl.downloadFromUrl(data.folder, data.fetchUrl).then((f) => {
|
|
|
|
return cb({ ok: true }) || true
|
|
|
|
}).catch((err) => {
|
|
|
|
return cb({
|
|
|
|
ok: false,
|
|
|
|
msg: err.message
|
|
|
|
}) || true
|
|
|
|
})
|
2017-02-09 01:52:37 +00:00
|
|
|
})
|
2016-10-16 05:34:34 +00:00
|
|
|
|
2017-04-16 16:30:19 +00:00
|
|
|
socket.on('uploadsRenameFile', (data, cb) => {
|
|
|
|
cb = cb || _.noop
|
|
|
|
upl.moveUploadsFile(data.uid, data.folder, data.filename).then((f) => {
|
|
|
|
return cb({ ok: true }) || true
|
|
|
|
}).catch((err) => {
|
|
|
|
return cb({
|
|
|
|
ok: false,
|
|
|
|
msg: err.message
|
|
|
|
}) || true
|
|
|
|
})
|
2017-02-09 01:52:37 +00:00
|
|
|
})
|
2016-10-17 03:24:19 +00:00
|
|
|
|
2017-04-16 16:30:19 +00:00
|
|
|
socket.on('uploadsMoveFile', (data, cb) => {
|
|
|
|
cb = cb || _.noop
|
|
|
|
upl.moveUploadsFile(data.uid, data.folder).then((f) => {
|
|
|
|
return cb({ ok: true }) || true
|
|
|
|
}).catch((err) => {
|
|
|
|
return cb({
|
|
|
|
ok: false,
|
|
|
|
msg: err.message
|
|
|
|
}) || true
|
|
|
|
})
|
2017-02-09 01:52:37 +00:00
|
|
|
})
|
2017-04-16 16:30:19 +00:00
|
|
|
}
|
2017-02-09 01:52:37 +00:00
|
|
|
}
|