2019-12-15 00:27:01 +08:00
|
|
|
import {IUserManager} from './database/interfaces/IUserManager';
|
|
|
|
import {IGalleryManager} from './database/interfaces/IGalleryManager';
|
|
|
|
import {ISearchManager} from './database/interfaces/ISearchManager';
|
|
|
|
import {SQLConnection} from './database/sql/SQLConnection';
|
|
|
|
import {ISharingManager} from './database/interfaces/ISharingManager';
|
2018-03-31 03:30:30 +08:00
|
|
|
import {Logger} from '../Logger';
|
2019-12-15 00:27:01 +08:00
|
|
|
import {IIndexingManager} from './database/interfaces/IIndexingManager';
|
|
|
|
import {IPersonManager} from './database/interfaces/IPersonManager';
|
|
|
|
import {IVersionManager} from './database/interfaces/IVersionManager';
|
2019-12-24 19:22:25 +08:00
|
|
|
import {IJobManager} from './database/interfaces/IJobManager';
|
2021-01-16 23:59:59 +08:00
|
|
|
import {LocationManager} from './database/LocationManager';
|
2021-05-29 01:46:22 +08:00
|
|
|
import {IAlbumManager} from './database/interfaces/IAlbumManager';
|
|
|
|
import {JobManager} from './jobs/JobManager';
|
2021-07-07 03:37:19 +08:00
|
|
|
import {IPreviewManager} from './database/interfaces/IPreviewManager';
|
2021-08-08 00:09:46 +08:00
|
|
|
import {ParentDirectoryDTO} from '../../common/entities/DirectoryDTO';
|
|
|
|
import {IObjectManager} from './database/interfaces/IObjectManager';
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2021-05-16 17:11:53 +08:00
|
|
|
const LOG_TAG = '[ObjectManagers]';
|
|
|
|
|
2019-02-16 00:47:09 +08:00
|
|
|
export class ObjectManagers {
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
private static instance: ObjectManagers = null;
|
2018-05-13 00:19:51 +08:00
|
|
|
|
2021-08-08 00:09:46 +08:00
|
|
|
private readonly managers: IObjectManager[];
|
2021-04-18 21:48:35 +08:00
|
|
|
private galleryManager: IGalleryManager;
|
|
|
|
private userManager: IUserManager;
|
|
|
|
private searchManager: ISearchManager;
|
|
|
|
private sharingManager: ISharingManager;
|
|
|
|
private indexingManager: IIndexingManager;
|
|
|
|
private personManager: IPersonManager;
|
2021-07-07 03:37:19 +08:00
|
|
|
private previewManager: IPreviewManager;
|
2021-04-18 21:48:35 +08:00
|
|
|
private versionManager: IVersionManager;
|
|
|
|
private jobManager: IJobManager;
|
|
|
|
private locationManager: LocationManager;
|
2021-05-29 01:46:22 +08:00
|
|
|
private albumManager: IAlbumManager;
|
2019-02-16 00:47:09 +08:00
|
|
|
|
|
|
|
|
2021-08-08 00:09:46 +08:00
|
|
|
constructor() {
|
|
|
|
this.managers = [];
|
|
|
|
}
|
|
|
|
|
2019-02-16 00:47:09 +08:00
|
|
|
get VersionManager(): IVersionManager {
|
2021-04-18 21:48:35 +08:00
|
|
|
return this.versionManager;
|
2019-02-16 00:47:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set VersionManager(value: IVersionManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.versionManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.versionManager), 1);
|
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
this.versionManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.versionManager);
|
2019-02-16 00:47:09 +08:00
|
|
|
}
|
2019-01-14 00:38:39 +08:00
|
|
|
|
2021-01-16 23:59:59 +08:00
|
|
|
get LocationManager(): LocationManager {
|
2021-04-18 21:48:35 +08:00
|
|
|
return this.locationManager;
|
2021-01-16 23:59:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set LocationManager(value: LocationManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.locationManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.locationManager), 1);
|
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
this.locationManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.locationManager);
|
2021-01-16 23:59:59 +08:00
|
|
|
}
|
|
|
|
|
2021-05-29 01:46:22 +08:00
|
|
|
get AlbumManager(): IAlbumManager {
|
|
|
|
return this.albumManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
set AlbumManager(value: IAlbumManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.albumManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.albumManager), 1);
|
|
|
|
}
|
2021-05-29 01:46:22 +08:00
|
|
|
this.albumManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.albumManager);
|
2021-05-29 01:46:22 +08:00
|
|
|
}
|
|
|
|
|
2019-01-14 00:38:39 +08:00
|
|
|
get PersonManager(): IPersonManager {
|
2021-04-18 21:48:35 +08:00
|
|
|
return this.personManager;
|
2019-01-14 00:38:39 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set PersonManager(value: IPersonManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.personManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.personManager), 1);
|
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
this.personManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.personManager);
|
2019-01-14 00:38:39 +08:00
|
|
|
}
|
2021-08-08 00:09:46 +08:00
|
|
|
|
2021-07-07 03:37:19 +08:00
|
|
|
get PreviewManager(): IPreviewManager {
|
|
|
|
return this.previewManager;
|
|
|
|
}
|
|
|
|
|
|
|
|
set PreviewManager(value: IPreviewManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.previewManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.previewManager), 1);
|
|
|
|
}
|
2021-07-07 03:37:19 +08:00
|
|
|
this.previewManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.previewManager);
|
2021-07-07 03:37:19 +08:00
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-26 03:09:37 +08:00
|
|
|
get IndexingManager(): IIndexingManager {
|
2021-04-18 21:48:35 +08:00
|
|
|
return this.indexingManager;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
|
|
|
|
2017-07-26 03:09:37 +08:00
|
|
|
set IndexingManager(value: IIndexingManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.indexingManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.indexingManager), 1);
|
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
this.indexingManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.indexingManager);
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-09 23:04:56 +08:00
|
|
|
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
get GalleryManager(): IGalleryManager {
|
2021-04-18 21:48:35 +08:00
|
|
|
return this.galleryManager;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
set GalleryManager(value: IGalleryManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.galleryManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.galleryManager), 1);
|
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
this.galleryManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.galleryManager);
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
get UserManager(): IUserManager {
|
2021-04-18 21:48:35 +08:00
|
|
|
return this.userManager;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
set UserManager(value: IUserManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.userManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.userManager), 1);
|
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
this.userManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.userManager);
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-04-22 19:23:44 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
get SearchManager(): ISearchManager {
|
2021-04-18 21:48:35 +08:00
|
|
|
return this.searchManager;
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-05 00:34:54 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
set SearchManager(value: ISearchManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.searchManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.searchManager), 1);
|
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
this.searchManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.searchManager);
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|
2016-05-05 00:34:54 +08:00
|
|
|
|
2017-07-04 01:17:49 +08:00
|
|
|
get SharingManager(): ISharingManager {
|
2021-04-18 21:48:35 +08:00
|
|
|
return this.sharingManager;
|
2017-07-04 01:17:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
set SharingManager(value: ISharingManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.sharingManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.sharingManager), 1);
|
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
this.sharingManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.sharingManager);
|
2017-07-04 01:17:49 +08:00
|
|
|
}
|
|
|
|
|
2019-12-24 19:22:25 +08:00
|
|
|
get JobManager(): IJobManager {
|
2021-04-18 21:48:35 +08:00
|
|
|
return this.jobManager;
|
2019-07-28 04:56:12 +08:00
|
|
|
}
|
|
|
|
|
2019-12-24 19:22:25 +08:00
|
|
|
set JobManager(value: IJobManager) {
|
2021-08-08 00:09:46 +08:00
|
|
|
if (this.jobManager) {
|
|
|
|
this.managers.splice(this.managers.indexOf(this.jobManager), 1);
|
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
this.jobManager = value;
|
2021-08-08 00:09:46 +08:00
|
|
|
this.managers.push(this.jobManager);
|
2019-07-28 04:56:12 +08:00
|
|
|
}
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
public static getInstance(): ObjectManagers {
|
|
|
|
if (this.instance === null) {
|
|
|
|
this.instance = new ObjectManagers();
|
2019-01-14 00:38:39 +08:00
|
|
|
}
|
2021-04-18 21:48:35 +08:00
|
|
|
return this.instance;
|
2019-01-14 00:38:39 +08:00
|
|
|
}
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
public static async reset(): Promise<void> {
|
2021-08-08 00:09:46 +08:00
|
|
|
Logger.silly(LOG_TAG, 'Object manager reset begin');
|
2021-01-04 17:32:19 +08:00
|
|
|
if (ObjectManagers.getInstance().IndexingManager &&
|
|
|
|
ObjectManagers.getInstance().IndexingManager.IsSavingInProgress) {
|
|
|
|
await ObjectManagers.getInstance().IndexingManager.SavingReady;
|
|
|
|
}
|
2019-12-24 19:22:25 +08:00
|
|
|
if (ObjectManagers.getInstance().JobManager) {
|
|
|
|
ObjectManagers.getInstance().JobManager.stopSchedules();
|
2019-12-06 22:53:34 +08:00
|
|
|
}
|
2019-01-14 00:38:39 +08:00
|
|
|
await SQLConnection.close();
|
2021-04-18 21:48:35 +08:00
|
|
|
this.instance = null;
|
2021-05-24 04:26:27 +08:00
|
|
|
Logger.debug(LOG_TAG, 'Object manager reset');
|
2019-01-14 00:38:39 +08:00
|
|
|
}
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
public static async InitMemoryManagers(): Promise<void> {
|
2019-02-16 00:47:09 +08:00
|
|
|
await ObjectManagers.reset();
|
2021-05-29 01:46:22 +08:00
|
|
|
this.initManagers('memory');
|
|
|
|
Logger.debug(LOG_TAG, 'Memory DB inited');
|
2017-07-26 03:09:37 +08:00
|
|
|
}
|
|
|
|
|
2021-04-18 21:48:35 +08:00
|
|
|
public static async InitSQLManagers(): Promise<void> {
|
2019-02-16 00:47:09 +08:00
|
|
|
await ObjectManagers.reset();
|
2017-07-26 03:09:37 +08:00
|
|
|
await SQLConnection.init();
|
2021-05-29 01:46:22 +08:00
|
|
|
this.initManagers('sql');
|
2021-05-16 17:11:53 +08:00
|
|
|
Logger.debug(LOG_TAG, 'SQL DB inited');
|
2017-07-26 03:09:37 +08:00
|
|
|
}
|
|
|
|
|
2021-05-29 01:46:22 +08:00
|
|
|
private static initManagers(type: 'memory' | 'sql'): void {
|
|
|
|
ObjectManagers.getInstance().AlbumManager = new (require(`./database/${type}/AlbumManager`).AlbumManager)();
|
|
|
|
ObjectManagers.getInstance().GalleryManager = new (require(`./database/${type}/GalleryManager`).GalleryManager)();
|
|
|
|
ObjectManagers.getInstance().IndexingManager = new (require(`./database/${type}/IndexingManager`).IndexingManager)();
|
|
|
|
ObjectManagers.getInstance().PersonManager = new (require(`./database/${type}/PersonManager`).PersonManager)();
|
2021-07-07 03:37:19 +08:00
|
|
|
ObjectManagers.getInstance().PreviewManager = new (require(`./database/${type}/PreviewManager`).PreviewManager)();
|
2021-05-29 01:46:22 +08:00
|
|
|
ObjectManagers.getInstance().SearchManager = new (require(`./database/${type}/SearchManager`).SearchManager)();
|
|
|
|
ObjectManagers.getInstance().SharingManager = new (require(`./database/${type}/SharingManager`).SharingManager)();
|
|
|
|
ObjectManagers.getInstance().UserManager = new (require(`./database/${type}/UserManager`).UserManager)();
|
|
|
|
ObjectManagers.getInstance().VersionManager = new (require(`./database/${type}/VersionManager`).VersionManager)();
|
|
|
|
ObjectManagers.getInstance().JobManager = new JobManager();
|
|
|
|
ObjectManagers.getInstance().LocationManager = new LocationManager();
|
|
|
|
}
|
|
|
|
|
2021-08-08 00:09:46 +08:00
|
|
|
public async onDataChange(changedDir: ParentDirectoryDTO = null): Promise<void> {
|
|
|
|
await this.VersionManager.onNewDataVersion(changedDir);
|
|
|
|
|
|
|
|
for (const manager of this.managers) {
|
|
|
|
if (manager === this.versionManager) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (manager.onNewDataVersion) {
|
|
|
|
await manager.onNewDataVersion(changedDir);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 04:32:56 +08:00
|
|
|
}
|