mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-12-23 11:08:13 +09:00
81c7db0744
* wip * wip * Update abuse-user-reports.ts * Update files.ts * Update list-remote.ts * Update list.ts * Update show-users.ts * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * Update search.ts * Update reactions.ts * Update search.ts * wip * wip * wip * wip * Update update.ts * Update relation.ts * Update available.ts * wip * wip * wip * Update packages/backend/src/server/api/define.ts Co-authored-by: Johann150 <johann.galle@protonmail.com> * Update define.ts * Update define.ts * typo * wip * wip * wip * wip * wip * wip * wip * wip * Update update.ts * wip * Update signup.ts * Update call.ts * minimum for limit * type * remove needless annotation * wip * Update signup.ts * wip * wip * fix * Update create.ts Co-authored-by: Johann150 <johann.galle@protonmail.com>
44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
import { EntityRepository, Repository } from 'typeorm';
|
|
import { DriveFolders, DriveFiles } from '../index';
|
|
import { DriveFolder } from '@/models/entities/drive-folder';
|
|
import { awaitAll } from '@/prelude/await-all';
|
|
import { Packed } from '@/misc/schema';
|
|
|
|
@EntityRepository(DriveFolder)
|
|
export class DriveFolderRepository extends Repository<DriveFolder> {
|
|
public async pack(
|
|
src: DriveFolder['id'] | DriveFolder,
|
|
options?: {
|
|
detail: boolean
|
|
}
|
|
): Promise<Packed<'DriveFolder'>> {
|
|
const opts = Object.assign({
|
|
detail: false,
|
|
}, options);
|
|
|
|
const folder = typeof src === 'object' ? src : await this.findOneOrFail(src);
|
|
|
|
return await awaitAll({
|
|
id: folder.id,
|
|
createdAt: folder.createdAt.toISOString(),
|
|
name: folder.name,
|
|
parentId: folder.parentId,
|
|
|
|
...(opts.detail ? {
|
|
foldersCount: DriveFolders.count({
|
|
parentId: folder.id,
|
|
}),
|
|
filesCount: DriveFiles.count({
|
|
folderId: folder.id,
|
|
}),
|
|
|
|
...(folder.parentId ? {
|
|
parent: this.pack(folder.parentId, {
|
|
detail: true,
|
|
}),
|
|
} : {}),
|
|
} : {}),
|
|
});
|
|
}
|
|
}
|