mirror of
https://github.com/xuthus83/pigallery2.git
synced 2024-11-03 21:04:03 +08:00
50 lines
1.2 KiB
TypeScript
50 lines
1.2 KiB
TypeScript
import {MediaDTO} from './MediaDTO';
|
|
import {PhotoDTO} from './PhotoDTO';
|
|
import {FileDTO} from './FileDTO';
|
|
|
|
export interface DirectoryDTO {
|
|
id: number;
|
|
name: string;
|
|
path: string;
|
|
lastModified: number;
|
|
lastScanned: number;
|
|
isPartial?: boolean;
|
|
parent: DirectoryDTO;
|
|
directories: Array<DirectoryDTO>;
|
|
media: MediaDTO[];
|
|
metaFile: FileDTO[];
|
|
}
|
|
|
|
export module DirectoryDTO {
|
|
export const addReferences = (dir: DirectoryDTO): void => {
|
|
dir.media.forEach((media: MediaDTO) => {
|
|
media.directory = dir;
|
|
});
|
|
dir.metaFile.forEach((file: FileDTO) => {
|
|
file.directory = dir;
|
|
});
|
|
dir.directories.forEach((directory: DirectoryDTO) => {
|
|
addReferences(directory);
|
|
directory.parent = dir;
|
|
});
|
|
};
|
|
|
|
export const removeReferences = (dir: DirectoryDTO): void => {
|
|
dir.media.forEach((media: MediaDTO) => {
|
|
media.directory = null;
|
|
});
|
|
if (dir.metaFile) {
|
|
dir.metaFile.forEach((file: FileDTO) => {
|
|
file.directory = null;
|
|
});
|
|
}
|
|
if (dir.directories) {
|
|
dir.directories.forEach((directory: DirectoryDTO) => {
|
|
removeReferences(directory);
|
|
directory.parent = null;
|
|
});
|
|
}
|
|
|
|
};
|
|
}
|