2019-01-18 18:50:38 -06:00
|
|
|
import $ from 'cafy';
|
|
|
|
import ID, { transform } from '../../../../../misc/cafy-id';
|
|
|
|
import define from '../../../define';
|
|
|
|
import DriveFile from '../../../../../models/drive-file';
|
2019-02-21 20:46:58 -06:00
|
|
|
import { ApiError } from '../../../error';
|
2019-01-18 18:50:38 -06:00
|
|
|
|
|
|
|
export const meta = {
|
|
|
|
requireCredential: true,
|
|
|
|
requireModerator: true,
|
|
|
|
|
|
|
|
params: {
|
|
|
|
fileId: {
|
|
|
|
validator: $.type(ID),
|
|
|
|
transform: transform,
|
|
|
|
},
|
2019-02-21 20:46:58 -06:00
|
|
|
},
|
|
|
|
|
|
|
|
errors: {
|
|
|
|
noSuchFile: {
|
|
|
|
message: 'No such file.',
|
|
|
|
code: 'NO_SUCH_FILE',
|
|
|
|
id: 'caf3ca38-c6e5-472e-a30c-b05377dcc240'
|
|
|
|
}
|
2019-01-18 18:50:38 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
export default define(meta, async (ps, me) => {
|
2019-01-18 18:50:38 -06:00
|
|
|
const file = await DriveFile.findOne({
|
|
|
|
_id: ps.fileId
|
|
|
|
});
|
|
|
|
|
|
|
|
if (file == null) {
|
2019-02-21 20:46:58 -06:00
|
|
|
throw new ApiError(meta.errors.noSuchFile);
|
2019-01-18 18:50:38 -06:00
|
|
|
}
|
|
|
|
|
2019-02-21 20:46:58 -06:00
|
|
|
return file;
|
|
|
|
});
|