2016-10-16 05:34:34 +00:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
module.exports = (socket) => {
|
2016-10-30 22:41:10 +00:00
|
|
|
|
2016-10-31 03:03:36 +00:00
|
|
|
if(!socket.request.user.logged_in) {
|
|
|
|
return;
|
|
|
|
}
|
2016-10-16 05:34:34 +00:00
|
|
|
|
|
|
|
//-----------------------------------------
|
|
|
|
// SEARCH
|
|
|
|
//-----------------------------------------
|
|
|
|
|
|
|
|
socket.on('search', (data, cb) => {
|
|
|
|
cb = cb || _.noop;
|
|
|
|
entries.search(data.terms).then((results) => {
|
2016-10-16 23:09:43 +00:00
|
|
|
return cb(results) || true;
|
2016-10-16 05:34:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
//-----------------------------------------
|
|
|
|
// UPLOADS
|
|
|
|
//-----------------------------------------
|
|
|
|
|
|
|
|
socket.on('uploadsGetFolders', (data, cb) => {
|
|
|
|
cb = cb || _.noop;
|
|
|
|
upl.getUploadsFolders().then((f) => {
|
2016-10-16 23:09:43 +00:00
|
|
|
return cb(f) || true;
|
2016-10-17 23:52:04 +00:00
|
|
|
});
|
2016-10-16 05:34:34 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('uploadsCreateFolder', (data, cb) => {
|
|
|
|
cb = cb || _.noop;
|
|
|
|
upl.createUploadsFolder(data.foldername).then((f) => {
|
2016-10-16 23:09:43 +00:00
|
|
|
return cb(f) || true;
|
2016-10-16 05:34:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
socket.on('uploadsGetImages', (data, cb) => {
|
|
|
|
cb = cb || _.noop;
|
|
|
|
upl.getUploadsFiles('image', data.folder).then((f) => {
|
2016-10-16 23:09:43 +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) => {
|
|
|
|
cb = cb || _.noop;
|
|
|
|
upl.getUploadsFiles('binary', data.folder).then((f) => {
|
|
|
|
return cb(f) || true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-10-16 05:34:34 +00:00
|
|
|
socket.on('uploadsDeleteFile', (data, cb) => {
|
|
|
|
cb = cb || _.noop;
|
|
|
|
upl.deleteUploadsFile(data.uid).then((f) => {
|
2016-10-16 23:09:43 +00:00
|
|
|
return cb(f) || true;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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;
|
2016-10-16 05:34:34 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-10-17 03:24: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;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-10-16 05:34:34 +00:00
|
|
|
};
|