wikijs-fork/controllers/ws.js

96 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-02-09 01:52:37 +00:00
'use strict'
const _ = require('lodash')
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
}
2017-02-09 01:52:37 +00:00
// -----------------------------------------
// SEARCH
2017-02-09 01:52:37 +00:00
// -----------------------------------------
socket.on('search', (data, cb) => {
2017-02-09 01:52:37 +00:00
cb = cb || _.noop
entries.search(data.terms).then((results) => {
2017-02-09 01:52:37 +00:00
return cb(results) || true
})
})
2017-02-09 01:52:37 +00:00
// -----------------------------------------
// UPLOADS
2017-02-09 01:52:37 +00:00
// -----------------------------------------
socket.on('uploadsGetFolders', (data, cb) => {
2017-02-09 01:52:37 +00:00
cb = cb || _.noop
upl.getUploadsFolders().then((f) => {
2017-02-09 01:52:37 +00:00
return cb(f) || true
})
})
socket.on('uploadsCreateFolder', (data, cb) => {
2017-02-09 01:52:37 +00:00
cb = cb || _.noop
upl.createUploadsFolder(data.foldername).then((f) => {
2017-02-09 01:52:37 +00:00
return cb(f) || true
})
})
socket.on('uploadsGetImages', (data, cb) => {
2017-02-09 01:52:37 +00:00
cb = cb || _.noop
upl.getUploadsFiles('image', data.folder).then((f) => {
2017-02-09 01:52:37 +00:00
return cb(f) || true
})
})
socket.on('uploadsGetFiles', (data, cb) => {
2017-02-09 01:52:37 +00:00
cb = cb || _.noop
upl.getUploadsFiles('binary', data.folder).then((f) => {
2017-02-09 01:52:37 +00:00
return cb(f) || true
})
})
socket.on('uploadsDeleteFile', (data, cb) => {
2017-02-09 01:52:37 +00:00
cb = cb || _.noop
upl.deleteUploadsFile(data.uid).then((f) => {
2017-02-09 01:52:37 +00:00
return cb(f) || true
})
})
socket.on('uploadsFetchFileFromURL', (data, cb) => {
2017-02-09 01:52:37 +00:00
cb = cb || _.noop
upl.downloadFromUrl(data.folder, data.fetchUrl).then((f) => {
2017-02-09 01:52:37 +00:00
return cb({ ok: true }) || true
}).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('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
})
})
}