forked from FoundKeyGang/FoundKey
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 del from '../../../../../services/drive/delete-file';
|
||||||
import { publishDriveStream } from '../../../../../stream';
|
import { publishDriveStream } from '../../../../../stream';
|
||||||
import { ILocalUser } from '../../../../../models/user';
|
import { ILocalUser } from '../../../../../models/user';
|
||||||
|
import getParams from '../../../get-params';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
stability: 'stable',
|
||||||
|
|
||||||
desc: {
|
desc: {
|
||||||
'ja-JP': 'ドライブのファイルを削除します。',
|
'ja-JP': 'ドライブのファイルを削除します。',
|
||||||
'en-US': 'Delete a file of drive.'
|
'en-US': 'Delete a file of drive.'
|
||||||
|
@ -12,23 +15,31 @@ export const meta = {
|
||||||
|
|
||||||
requireCredential: true,
|
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) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'fileId' parameter
|
const [ps, psErr] = getParams(meta, params);
|
||||||
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
if (psErr) return rej(psErr);
|
||||||
if (fileIdErr) throw 'invalid fileId param';
|
|
||||||
|
|
||||||
// Fetch file
|
// Fetch file
|
||||||
const file = await DriveFile
|
const file = await DriveFile
|
||||||
.findOne({
|
.findOne({
|
||||||
_id: fileId,
|
_id: ps.fileId,
|
||||||
'metadata.userId': user._id
|
'metadata.userId': user._id
|
||||||
});
|
});
|
||||||
|
|
||||||
if (file === null) {
|
if (file === null) {
|
||||||
throw 'file-not-found';
|
return rej('file-not-found');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Delete
|
// Delete
|
||||||
|
@ -37,5 +48,5 @@ export default async (params: any, user: ILocalUser) => {
|
||||||
// Publish file_deleted event
|
// Publish file_deleted event
|
||||||
publishDriveStream(user._id, 'file_deleted', file._id);
|
publishDriveStream(user._id, 'file_deleted', file._id);
|
||||||
|
|
||||||
return;
|
res();
|
||||||
};
|
});
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
|
import $ from 'cafy'; import ID from '../../../../../misc/cafy-id';
|
||||||
import DriveFile, { pack } from '../../../../../models/drive-file';
|
import DriveFile, { pack } from '../../../../../models/drive-file';
|
||||||
import { ILocalUser } from '../../../../../models/user';
|
import { ILocalUser } from '../../../../../models/user';
|
||||||
|
import getParams from '../../../get-params';
|
||||||
|
|
||||||
export const meta = {
|
export const meta = {
|
||||||
|
stability: 'stable',
|
||||||
|
|
||||||
desc: {
|
desc: {
|
||||||
'ja-JP': '指定したドライブのファイルの情報を取得します。',
|
'ja-JP': '指定したドライブのファイルの情報を取得します。',
|
||||||
'en-US': 'Get specified file of drive.'
|
'en-US': 'Get specified file of drive.'
|
||||||
|
@ -10,24 +13,32 @@ export const meta = {
|
||||||
|
|
||||||
requireCredential: true,
|
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) => {
|
export default (params: any, user: ILocalUser) => new Promise(async (res, rej) => {
|
||||||
// Get 'fileId' parameter
|
const [ps, psErr] = getParams(meta, params);
|
||||||
const [fileId, fileIdErr] = $.type(ID).get(params.fileId);
|
if (psErr) return rej(psErr);
|
||||||
if (fileIdErr) throw 'invalid fileId param';
|
|
||||||
|
|
||||||
// Fetch file
|
// Fetch file
|
||||||
const file = await DriveFile
|
const file = await DriveFile
|
||||||
.findOne({
|
.findOne({
|
||||||
_id: fileId,
|
_id: ps.fileId,
|
||||||
'metadata.userId': user._id,
|
'metadata.userId': user._id,
|
||||||
'metadata.deletedAt': { $exists: false }
|
'metadata.deletedAt': { $exists: false }
|
||||||
});
|
});
|
||||||
|
|
||||||
if (file === null) {
|
if (file === null) {
|
||||||
throw 'file-not-found';
|
return rej('file-not-found');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serialize
|
// Serialize
|
||||||
|
@ -35,5 +46,5 @@ export default async (params: any, user: ILocalUser) => {
|
||||||
detail: true
|
detail: true
|
||||||
});
|
});
|
||||||
|
|
||||||
return _file;
|
res(_file);
|
||||||
};
|
});
|
||||||
|
|
Loading…
Reference in a new issue