Files
test1/packages/backend/src/server/api/endpoints/drive/files/find.ts
syuilo 4a64280a7c lint
2022-01-03 02:12:50 +09:00

45 lines
890 B
TypeScript

import $ from 'cafy';
import { ID } from '@/misc/cafy-id';
import define from '../../../define';
import { DriveFiles } from '@/models/index';
export const meta = {
requireCredential: true as const,
tags: ['drive'],
kind: 'read:drive',
params: {
name: {
validator: $.str,
},
folderId: {
validator: $.optional.nullable.type(ID),
default: null,
},
},
res: {
type: 'array' as const,
optional: false as const, nullable: false as const,
items: {
type: 'object' as const,
optional: false as const, nullable: false as const,
ref: 'DriveFile',
},
},
};
// eslint-disable-next-line import/no-default-export
export default define(meta, async (ps, user) => {
const files = await DriveFiles.find({
name: ps.name,
userId: user.id,
folderId: ps.folderId,
});
return await Promise.all(files.map(file => DriveFiles.pack(file, { self: true })));
});