|
|
|
@ -6,7 +6,7 @@ class FileBoxController extends Controller {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async create(req, res, next) {
|
|
|
|
|
const FileBox = this.models.get('models:files:FileBox')
|
|
|
|
|
const FileBox = this.models.get('api:files:FileBox')
|
|
|
|
|
|
|
|
|
|
if ( !req.body.name ) {
|
|
|
|
|
return res.message('Missing required field: name')
|
|
|
|
@ -60,6 +60,12 @@ class FileBoxController extends Controller {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await box.save()
|
|
|
|
|
|
|
|
|
|
if ( !req.body.rootUUID && !box.rootUUID ) {
|
|
|
|
|
box.rootUUID = box.UUID
|
|
|
|
|
await box.save()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res.api(await box.to_api())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -97,7 +103,7 @@ class FileBoxController extends Controller {
|
|
|
|
|
const { file_box, file } = req.form
|
|
|
|
|
|
|
|
|
|
if ( req.body.name ) {
|
|
|
|
|
file.name = req.body.name
|
|
|
|
|
file.original_name = req.body.name
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( req.body.parentUUID && req.body.parentUUID !== file_box.UUID ) {
|
|
|
|
@ -123,6 +129,11 @@ class FileBoxController extends Controller {
|
|
|
|
|
return res.api(this.file_to_api(file))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async download_file(req, res, next) {
|
|
|
|
|
const { file_box, file } = req.form
|
|
|
|
|
return file.send(res)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async upload_files(req, res, next) {
|
|
|
|
|
const { file_box } = req.form
|
|
|
|
|
|
|
|
|
@ -143,6 +154,12 @@ class FileBoxController extends Controller {
|
|
|
|
|
return res.api(await req.form.file_box.to_api())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async get_children(req, res, next) {
|
|
|
|
|
const { file_box } = req.form
|
|
|
|
|
const children = await file_box.children()
|
|
|
|
|
return res.api(await Promise.all(children.map(x => x.to_api())));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async get_files(req, res, next) {
|
|
|
|
|
const { file_box, page } = req.form
|
|
|
|
|
const files = await file_box.files()
|
|
|
|
@ -165,13 +182,51 @@ class FileBoxController extends Controller {
|
|
|
|
|
|
|
|
|
|
file_to_api(file) {
|
|
|
|
|
return {
|
|
|
|
|
name: file.upload_name,
|
|
|
|
|
type: 'file',
|
|
|
|
|
title: file.original_name,
|
|
|
|
|
mime: file.mime_type,
|
|
|
|
|
uploaded: file.upload_date,
|
|
|
|
|
category: this.get_file_category(file.mime_type),
|
|
|
|
|
id: file.id,
|
|
|
|
|
_id: file._id,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
get_file_category(mime) {
|
|
|
|
|
if ( mime.includes('opendocument.text') || mime.includes('.document') ) {
|
|
|
|
|
return 'document';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( mime.includes('.spreadsheet') || mime.includes('.sheet') ) {
|
|
|
|
|
return 'spreadsheet';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( mime.includes('.presentation') ) {
|
|
|
|
|
return 'presentation';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( mime.includes('image/') ) {
|
|
|
|
|
return 'image';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( mime === 'application/pdf' ) {
|
|
|
|
|
return 'pdf';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( mime.includes('video/') ) {
|
|
|
|
|
return 'video';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( mime.includes('script') ) {
|
|
|
|
|
return 'code';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ( mime.includes('text/') ) {
|
|
|
|
|
return 'text';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return 'other';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = exports = FileBoxController
|
|
|
|
|