mirror of
https://github.com/misskey-dev/misskey.git
synced 2024-12-03 20:44:53 +01:00
Improve some API definitions
This commit is contained in:
parent
f51fdc0dbf
commit
162ace2fd6
2 changed files with 40 additions and 18 deletions
|
@ -3,8 +3,11 @@ import DriveFile from '../../../../../models/drive-file';
|
|||
import del from '../../../../../services/drive/delete-file';
|
||||
import { publishDriveStream } from '../../../../../stream';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
|
||||
desc: {
|
||||
'ja-JP': 'ドライブのファイルを削除します。',
|
||||
'en-US': 'Delete a file of drive.'
|
||||
|
@ -12,23 +15,31 @@ export const meta = {
|
|||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'drive-write'
|
||||
kind: 'drive-write',
|
||||
|
||||
params: {
|
||||
fileId: $.type(ID).note({
|
||||
desc: {
|
||||
'ja-JP': '対象のファイルID',
|
||||
'en-US': 'Target file ID'
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => {
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
||||
if (fileIdErr) throw 'invalid fileId param';
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
// Fetch file
|
||||
const file = await DriveFile
|
||||
.findOne({
|
||||
_id: fileId,
|
||||
_id: ps.fileId,
|
||||
'metadata.userId': user._id
|
||||
});
|
||||
|
||||
if (file === null) {
|
||||
throw 'file-not-found';
|
||||
return rej('file-not-found');
|
||||
}
|
||||
|
||||
// Delete
|
||||
|
@ -37,5 +48,5 @@ export default async (params: any, user: ILocalUser) => {
|
|||
// Publish file_deleted event
|
||||
publishDriveStream(user._id, 'file_deleted', file._id);
|
||||
|
||||
return;
|
||||
};
|
||||
res();
|
||||
});
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
|
||||
import DriveFile, { pack } from '../../../../../models/drive-file';
|
||||
import { ILocalUser } from '../../../../../models/user';
|
||||
import getParams from '../../../get-params';
|
||||
|
||||
export const meta = {
|
||||
stability: 'stable',
|
||||
|
||||
desc: {
|
||||
'ja-JP': '指定したドライブのファイルの情報を取得します。',
|
||||
'en-US': 'Get specified file of drive.'
|
||||
|
@ -10,24 +13,32 @@ export const meta = {
|
|||
|
||||
requireCredential: true,
|
||||
|
||||
kind: 'drive-read'
|
||||
kind: 'drive-read',
|
||||
|
||||
params: {
|
||||
fileId: $.type(ID).note({
|
||||
desc: {
|
||||
'ja-JP': '対象のファイルID',
|
||||
'en-US': 'Target file ID'
|
||||
}
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
export default async (params: any, user: ILocalUser) => {
|
||||
// Get 'fileId' parameter
|
||||
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
||||
if (fileIdErr) throw 'invalid fileId param';
|
||||
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||
const [ps, psErr] = getParams(meta, params);
|
||||
if (psErr) return rej(psErr);
|
||||
|
||||
// Fetch file
|
||||
const file = await DriveFile
|
||||
.findOne({
|
||||
_id: fileId,
|
||||
_id: ps.fileId,
|
||||
'metadata.userId': user._id,
|
||||
'metadata.deletedAt': { $exists: false }
|
||||
});
|
||||
|
||||
if (file === null) {
|
||||
throw 'file-not-found';
|
||||
return rej('file-not-found');
|
||||
}
|
||||
|
||||
// Serialize
|
||||
|
@ -35,5 +46,5 @@ export default async (params: any, user: ILocalUser) => {
|
|||
detail: true
|
||||
});
|
||||
|
||||
return _file;
|
||||
};
|
||||
res(_file);
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue