1
0
mirror of https://github.com/misskey-dev/misskey synced 2024-12-23 19:19:05 +09:00
misskey/src/server/api/endpoints/drive/files/delete.ts

42 lines
970 B
TypeScript
Raw Normal View History

2018-07-07 19:19:00 +09:00
import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
import DriveFile from '../../../../../models/drive-file';
import del from '../../../../../services/drive/delete-file';
2018-07-07 19:19:00 +09:00
import { publishDriveStream } from '../../../../../stream';
2018-06-18 09:54:53 +09:00
import { ILocalUser } from '../../../../../models/user';
2018-07-17 04:36:44 +09:00
export const meta = {
desc: {
ja: 'ドライブのファイルを削除します。',
en: 'Delete a file of drive.'
},
requireCredential: true,
kind: 'drive-write'
};
2018-07-06 02:58:29 +09:00
export default async (params: any, user: ILocalUser) => {
// 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;
};