mirror of
https://github.com/paricafe/misskey.git
synced 2024-11-26 17:56:43 -06:00
987168b863
* wip * wip * wip * wip * wip * wip * wip * wip * wip * wip * wip
50 lines
1.1 KiB
TypeScript
50 lines
1.1 KiB
TypeScript
import { EntityRepository, Repository } from 'typeorm';
|
|
import { DriveFolders, DriveFiles } from '..';
|
|
import rap from '@prezzemolo/rap';
|
|
import { DriveFolder } from '../entities/drive-folder';
|
|
import { ensure } from '../../prelude/ensure';
|
|
|
|
@EntityRepository(DriveFolder)
|
|
export class DriveFolderRepository extends Repository<DriveFolder> {
|
|
public validateFolderName(name: string): boolean {
|
|
return (
|
|
(name.trim().length > 0) &&
|
|
(name.length <= 200)
|
|
);
|
|
}
|
|
|
|
public async pack(
|
|
src: DriveFolder['id'] | DriveFolder,
|
|
options?: {
|
|
detail: boolean
|
|
}
|
|
): Promise<Record<string, any>> {
|
|
const opts = Object.assign({
|
|
detail: false
|
|
}, options);
|
|
|
|
const folder = typeof src === 'object' ? src : await this.findOne(src).then(ensure);
|
|
|
|
return await rap({
|
|
id: folder.id,
|
|
createdAt: folder.createdAt,
|
|
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
|
|
})
|
|
} : {})
|
|
} : {})
|
|
});
|
|
}
|
|
}
|