sharkey/src/server/api/endpoints/drive/folders/find.ts
2019-02-13 16:33:07 +09:00

37 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: $.optional.nullable.type(ID),
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))));
}));