1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2024-11-03 21:04:03 +08:00
pigallery2/common/entities/DirectoryDTO.ts

58 lines
1.3 KiB
TypeScript
Raw Normal View History

2018-11-05 02:28:32 +08:00
import {MediaDTO} from './MediaDTO';
2018-11-19 03:26:29 +08:00
import {PhotoDTO} from './PhotoDTO';
2018-11-26 07:26:29 +08:00
import {FileDTO} from './FileDTO';
2016-12-28 03:55:51 +08:00
export interface DirectoryDTO {
id: number;
name: string;
path: string;
2017-07-20 02:47:09 +08:00
lastModified: number;
lastScanned: number;
2017-07-22 01:14:22 +08:00
isPartial?: boolean;
parent: DirectoryDTO;
directories: Array<DirectoryDTO>;
2018-11-05 02:28:32 +08:00
media: MediaDTO[];
2018-11-26 07:26:29 +08:00
metaFile: FileDTO[];
}
2017-07-08 06:18:24 +08:00
2017-07-09 18:03:17 +08:00
export module DirectoryDTO {
export const addReferences = (dir: DirectoryDTO): void => {
dir.media.forEach((media: MediaDTO) => {
media.directory = dir;
2017-07-08 06:18:24 +08:00
});
2018-11-30 22:37:01 +08:00
if (dir.metaFile) {
dir.metaFile.forEach((file: FileDTO) => {
file.directory = dir;
});
}
if (dir.directories) {
dir.directories.forEach((directory: DirectoryDTO) => {
addReferences(directory);
directory.parent = dir;
});
}
};
2018-11-19 03:26:29 +08:00
export const removeReferences = (dir: DirectoryDTO): void => {
2018-12-18 07:05:12 +08:00
if (dir.media) {
dir.media.forEach((media: MediaDTO) => {
media.directory = null;
});
}
2018-11-26 07:26:29 +08:00
if (dir.metaFile) {
dir.metaFile.forEach((file: FileDTO) => {
file.directory = null;
});
}
if (dir.directories) {
dir.directories.forEach((directory: DirectoryDTO) => {
removeReferences(directory);
directory.parent = null;
});
}
2018-11-19 03:26:29 +08:00
};
2017-07-08 06:18:24 +08:00
}