yumechi-no-kuni/src/server/api/endpoints/drive/files/show.ts
2018-04-27 19:12:15 +09:00

32 lines
616 B
TypeScript

/**
* Module dependencies
*/
import $ from 'cafy'; import ID from '../../../../../cafy-id';
import DriveFile, { pack } from '../../../../../models/drive-file';
/**
* Show a file
*/
module.exports = async (params, user) => {
// Get 'fileId' parameter
const [fileId, fileIdErr] = $(params.fileId).type(ID).get();
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;
};