Sharkey/packages/backend/src/server/api/endpoints/drive/folders.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

48 lines
1.3 KiB
TypeScript

import define from '../../define.js';
import { DriveFolders } from '@/models/index.js';
import { makePaginationQuery } from '../../common/make-pagination-query.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: {
limit: { type: 'integer', minimum: 1, maximum: 100, default: 10 },
sinceId: { type: 'string', format: 'misskey:id' },
untilId: { type: 'string', format: 'misskey:id' },
folderId: { type: 'string', format: 'misskey:id', nullable: true, default: null },
},
required: [],
} as const;
// eslint-disable-next-line import/no-default-export
export default define(meta, paramDef, async (ps, user) => {
const query = makePaginationQuery(DriveFolders.createQueryBuilder('folder'), ps.sinceId, ps.untilId)
.andWhere('folder.userId = :userId', { userId: user.id });
if (ps.folderId) {
query.andWhere('folder.parentId = :parentId', { parentId: ps.folderId });
} else {
query.andWhere('folder.parentId IS NULL');
}
const folders = await query.take(ps.limit).getMany();
return await Promise.all(folders.map(folder => DriveFolders.pack(folder)));
});