2018-07-07 12:19:00 +02:00
|
|
|
import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
|
2018-06-15 02:53:30 +02:00
|
|
|
import DriveFile from '../../../../../models/drive-file';
|
|
|
|
import del from '../../../../../services/drive/delete-file';
|
2018-07-07 12:19:00 +02:00
|
|
|
import { publishDriveStream } from '../../../../../stream';
|
2018-06-18 02:54:53 +02:00
|
|
|
import { ILocalUser } from '../../../../../models/user';
|
2018-06-15 02:53:30 +02:00
|
|
|
|
2018-07-16 21:36:44 +02:00
|
|
|
export const meta = {
|
|
|
|
desc: {
|
2018-08-28 23:59:43 +02:00
|
|
|
'ja-JP': 'ドライブのファイルを削除します。',
|
|
|
|
'en-US': 'Delete a file of drive.'
|
2018-07-16 21:36:44 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
requireCredential: true,
|
|
|
|
|
|
|
|
kind: 'drive-write'
|
|
|
|
};
|
|
|
|
|
2018-07-05 19:58:29 +02:00
|
|
|
export default async (params: any, user: ILocalUser) => {
|
2018-06-15 02:53:30 +02:00
|
|
|
// Get 'fileId' parameter
|
|
|
|
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
|
|
|
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';
|
|
|
|
}
|
|
|
|
|
|
|
|
// Delete
|
|
|
|
await del(file);
|
|
|
|
|
|
|
|
// Publish file_deleted event
|
|
|
|
publishDriveStream(user._id, 'file_deleted', file._id);
|
|
|
|
|
|
|
|
return;
|
|
|
|
};
|