hippofish/src/server/api/endpoints/drive/folders/find.ts
2018-11-05 01:42:41 +09:00

35 lines
737 B
TypeScript

import $ from 'cafy'; import ID, { transform } from '../../../../../misc/cafy-id';
import DriveFolder, { pack } from '../../../../../models/drive-folder';
import define from '../../../define';
export const meta = {
requireCredential: true,
kind: 'drive-read',
params: {
name: {
validator: $.str
},
parentId: {
validator: $.type(ID).optional.nullable,
transform: transform,
default: null as any,
desc: {
'ja-JP': 'フォルダID'
}
},
}
};
export default define(meta, (ps, user) => new Promise(async (res, rej) => {
const folders = await DriveFolder
.find({
name: ps.name,
userId: user._id,
parentId: ps.parentId
});
res(await Promise.all(folders.map(folder => pack(folder))));
}));