hippofish/packages/backend/src/server/api/endpoints/drive/folders/find.ts
syuilo d071d18dd7
refactor: Use ESM (#8358)
* wip

* wip

* fix

* clean up

* Update tsconfig.json

* Update activitypub.ts

* wip
2022-02-27 11:07:39 +09:00

40 lines
868 B
TypeScript

import define from '../../../define.js';
import { DriveFolders } from '@/models/index.js';
export const meta = {
tags: ['drive'],
requireCredential: true,
kind: 'read:drive',
res: {
type: 'array',
optional: false, nullable: false,
items: {
type: 'object',
optional: false, nullable: false,
ref: 'DriveFolder',
},
},
} as const;
export const paramDef = {
type: 'object',
properties: {
name: { type: 'string' },
parentId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
},
required: ['name'],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => {
const folders = await DriveFolders.find({
name: ps.name,
userId: user.id,
parentId: ps.parentId,
});
return await Promise.all(folders.map(folder => DriveFolders.pack(folder)));
});