mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-13 18:23:08 +02:00
36 lines
634 B
TypeScript
36 lines
634 B
TypeScript
/**
|
|
* Module dependencies
|
|
*/
|
|
import $ from 'cafy';
|
|
import DriveFile, { pack } from '../../../models/drive-file';
|
|
|
|
/**
|
|
* Show a file
|
|
*
|
|
* @param {any} params
|
|
* @param {any} user
|
|
* @return {Promise<any>}
|
|
*/
|
|
module.exports = async (params, user) => {
|
|
// Get 'fileId' parameter
|
|
const [fileId, fileIdErr] = $(params.fileId).id().$;
|
|
if (fileIdErr) throw 'invalid fileId param';
|
|
|
|
// Fetch file
|
|
const file = await DriveFile
|
|
.findOne({
|
|
_id: fileId,
|
|
'metadata.userId': user._id
|
|
});
|
|
|
|
if (file === null) {
|
|
throw 'file-not-found';
|
|
}
|
|
|
|
// Serialize
|
|
const _file = await pack(file, {
|
|
detail: true
|
|
});
|
|
|
|
return _file;
|
|
};
|