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

452 lines
20 KiB
TypeScript
Raw Normal View History

2018-03-31 03:30:30 +08:00
import {NextFunction, Request, Response} from 'express';
import {ErrorCodes, ErrorDTO} from '../../common/entities/Error';
import {ObjectManagerRepository} from '../model/ObjectManagerRepository';
import {Logger} from '../Logger';
import {SQLConnection} from '../model/sql/SQLConnection';
2018-12-10 06:25:39 +08:00
import {DataBaseConfig, DatabaseType, IndexingConfig, ThumbnailConfig} from '../../common/config/private/IPrivateConfig';
2018-03-31 03:30:30 +08:00
import {Config} from '../../common/config/private/Config';
2018-11-19 03:26:29 +08:00
import {ConfigDiagnostics} from '../model/diagnostics/ConfigDiagnostics';
2018-03-31 03:30:30 +08:00
import {ClientConfig} from '../../common/config/public/ConfigClass';
import {BasicConfigDTO} from '../../common/entities/settings/BasicConfigDTO';
import {OtherConfigDTO} from '../../common/entities/settings/OtherConfigDTO';
import {ProjectPath} from '../ProjectPath';
import {PrivateConfigClass} from '../../common/config/private/PrivateConfigClass';
2018-11-24 20:08:34 +08:00
import {IndexingDTO} from '../../common/entities/settings/IndexingDTO';
2018-12-10 06:25:39 +08:00
import {ISQLGalleryManager} from '../model/sql/IGalleryManager';
2018-03-31 03:30:30 +08:00
const LOG_TAG = '[AdminMWs]';
2017-07-26 03:09:37 +08:00
2017-07-08 18:43:42 +08:00
export class AdminMWs {
2018-12-10 06:25:39 +08:00
public static async loadStatistic(req: Request, res: Response, next: NextFunction) {
if (Config.Server.database.type === DatabaseType.memory) {
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Statistic is only available for indexed content'));
}
const galleryManager = <ISQLGalleryManager>ObjectManagerRepository.getInstance().GalleryManager;
try {
req.resultPipe = {
directories: await galleryManager.countDirectories(),
photos: await galleryManager.countPhotos(),
videos: await galleryManager.countVideos(),
diskUsage: await galleryManager.countMediaSize(),
};
return next();
} catch (err) {
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Error while getting statistic: ' + err.toString(), err));
}
return next(new ErrorDTO(ErrorCodes.GENERAL_ERROR, 'Error while getting statistic', err));
}
}
2017-07-08 18:43:42 +08:00
public static async updateDatabaseSettings(req: Request, res: Response, next: NextFunction) {
2017-07-14 05:39:09 +08:00
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
2017-07-08 18:43:42 +08:00
}
2017-07-14 05:39:09 +08:00
const databaseSettings = <DataBaseConfig>req.body.settings;
2017-07-08 18:43:42 +08:00
try {
2018-03-31 03:30:30 +08:00
if (databaseSettings.type !== DatabaseType.memory) {
await SQLConnection.tryConnection(databaseSettings);
2017-07-08 18:43:42 +08:00
}
Config.Server.database = databaseSettings;
2018-03-31 03:30:30 +08:00
// only updating explicitly set config (not saving config set by the diagnostics)
2017-07-14 05:39:09 +08:00
const original = Config.original();
original.Server.database = databaseSettings;
2018-03-31 03:30:30 +08:00
if (databaseSettings.type === DatabaseType.memory) {
2017-07-15 23:29:40 +08:00
original.Client.Sharing.enabled = false;
original.Client.Search.enabled = false;
}
2017-07-14 05:39:09 +08:00
original.save();
await ConfigDiagnostics.runDiagnostics();
2018-03-31 03:30:30 +08:00
Logger.info(LOG_TAG, 'new config:');
2017-07-08 18:43:42 +08:00
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
2018-11-21 23:07:37 +08:00
await ObjectManagerRepository.reset();
2018-03-31 03:30:30 +08:00
if (Config.Server.database.type !== DatabaseType.memory) {
await ObjectManagerRepository.InitSQLManagers();
2017-07-08 18:43:42 +08:00
} else {
await ObjectManagerRepository.InitMemoryManagers();
}
return next();
} catch (err) {
2017-07-15 23:29:40 +08:00
if (err instanceof Error) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Error while saving database settings: ' + err.toString(), err));
2017-07-15 23:29:40 +08:00
}
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Error while saving database settings', err));
2017-07-08 18:43:42 +08:00
}
}
2017-07-15 18:47:11 +08:00
public static async updateMapSettings(req: Request, res: Response, next: NextFunction) {
2017-07-14 05:39:09 +08:00
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
2017-07-08 18:43:42 +08:00
}
try {
2017-07-15 18:47:11 +08:00
await ConfigDiagnostics.testMapConfig(<ClientConfig.MapConfig>req.body.settings);
Config.Client.Map = <ClientConfig.MapConfig>req.body.settings;
2018-03-31 03:30:30 +08:00
// only updating explicitly set config (not saving config set by the diagnostics)
2017-07-15 18:47:11 +08:00
const original = Config.original();
original.Client.Map = <ClientConfig.MapConfig>req.body.settings;
original.save();
await ConfigDiagnostics.runDiagnostics();
2018-03-31 03:30:30 +08:00
Logger.info(LOG_TAG, 'new config:');
2017-07-15 18:47:11 +08:00
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
2017-07-08 18:43:42 +08:00
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-08 18:43:42 +08:00
}
}
2018-11-21 23:07:37 +08:00
2018-11-19 03:26:29 +08:00
public static async updateVideoSettings(req: Request, res: Response, next: NextFunction) {
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
}
try {
await ConfigDiagnostics.testVideoConfig(<ClientConfig.VideoConfig>req.body.settings);
Config.Client.Video = <ClientConfig.VideoConfig>req.body.settings;
// only updating explicitly set config (not saving config set by the diagnostics)
const original = Config.original();
original.Client.Video = <ClientConfig.VideoConfig>req.body.settings;
original.save();
await ConfigDiagnostics.runDiagnostics();
Logger.info(LOG_TAG, 'new config:');
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2018-11-19 03:26:29 +08:00
}
}
2017-07-14 05:39:09 +08:00
2018-12-02 06:53:35 +08:00
public static async updateMetaFileSettings(req: Request, res: Response, next: NextFunction) {
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
}
try {
const original = Config.original();
await ConfigDiagnostics.testMetaFileConfig(<ClientConfig.MetaFileConfig>req.body.settings, original);
Config.Client.MetaFile = <ClientConfig.MetaFileConfig>req.body.settings;
// only updating explicitly set config (not saving config set by the diagnostics)
original.Client.MetaFile = <ClientConfig.MetaFileConfig>req.body.settings;
original.save();
await ConfigDiagnostics.runDiagnostics();
Logger.info(LOG_TAG, 'new config:');
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2018-12-02 06:53:35 +08:00
}
}
2017-07-15 21:29:04 +08:00
public static async updateShareSettings(req: Request, res: Response, next: NextFunction) {
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
2017-07-15 21:29:04 +08:00
}
try {
2018-03-31 03:30:30 +08:00
// only updating explicitly set config (not saving config set by the diagnostics)
2017-07-15 21:29:04 +08:00
const original = Config.original();
await ConfigDiagnostics.testSharingConfig(<ClientConfig.SharingConfig>req.body.settings, original);
Config.Client.Sharing = <ClientConfig.SharingConfig>req.body.settings;
original.Client.Sharing = <ClientConfig.SharingConfig>req.body.settings;
original.save();
await ConfigDiagnostics.runDiagnostics();
2018-03-31 03:30:30 +08:00
Logger.info(LOG_TAG, 'new config:');
2017-07-15 21:29:04 +08:00
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-15 21:29:04 +08:00
}
}
public static async updateRandomPhotoSettings(req: Request, res: Response, next: NextFunction) {
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
}
try {
// only updating explicitly set config (not saving config set by the diagnostics)
const original = Config.original();
await ConfigDiagnostics.testRandomPhotoConfig(<ClientConfig.RandomPhotoConfig>req.body.settings, original);
Config.Client.RandomPhoto = <ClientConfig.RandomPhotoConfig>req.body.settings;
original.Client.RandomPhoto = <ClientConfig.RandomPhotoConfig>req.body.settings;
original.save();
await ConfigDiagnostics.runDiagnostics();
Logger.info(LOG_TAG, 'new config:');
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
}
}
2017-07-15 20:27:12 +08:00
public static async updateSearchSettings(req: Request, res: Response, next: NextFunction) {
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
2017-07-15 20:27:12 +08:00
}
try {
2018-03-31 03:30:30 +08:00
// only updating explicitly set config (not saving config set by the diagnostics)
2017-07-15 20:27:12 +08:00
const original = Config.original();
await ConfigDiagnostics.testSearchConfig(<ClientConfig.SearchConfig>req.body.settings, original);
Config.Client.Search = <ClientConfig.SearchConfig>req.body.settings;
original.Client.Search = <ClientConfig.SearchConfig>req.body.settings;
original.save();
await ConfigDiagnostics.runDiagnostics();
2018-03-31 03:30:30 +08:00
Logger.info(LOG_TAG, 'new config:');
2017-07-15 20:27:12 +08:00
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-15 20:27:12 +08:00
}
}
2017-07-26 03:09:37 +08:00
public static async updateAuthenticationSettings(req: Request, res: Response, next: NextFunction) {
2017-07-14 05:39:09 +08:00
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
2017-07-14 05:39:09 +08:00
}
try {
2017-07-15 18:47:11 +08:00
Config.Client.authenticationRequired = <boolean>req.body.settings;
2018-03-31 03:30:30 +08:00
// only updating explicitly set config (not saving config set by the diagnostics)
2017-07-14 05:39:09 +08:00
const original = Config.original();
2017-07-15 18:47:11 +08:00
original.Client.authenticationRequired = <boolean>req.body.settings;
2018-05-25 09:29:05 +08:00
if (original.Client.authenticationRequired === false) {
original.Client.Sharing.enabled = false;
}
2017-07-14 05:39:09 +08:00
original.save();
await ConfigDiagnostics.runDiagnostics();
2018-03-31 03:30:30 +08:00
Logger.info(LOG_TAG, 'new config:');
2017-07-14 05:39:09 +08:00
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-14 05:39:09 +08:00
}
}
2017-07-26 03:09:37 +08:00
public static async updateThumbnailSettings(req: Request, res: Response, next: NextFunction) {
2017-07-14 05:39:09 +08:00
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
2017-07-14 05:39:09 +08:00
}
try {
2017-07-15 18:47:11 +08:00
const settings: {
server: ThumbnailConfig,
client: ClientConfig.ThumbnailConfig
} = req.body.settings;
await ConfigDiagnostics.testServerThumbnailConfig(settings.server);
await ConfigDiagnostics.testClientThumbnailConfig(settings.client);
Config.Server.thumbnail = settings.server;
Config.Client.Thumbnail = settings.client;
2018-03-31 03:30:30 +08:00
// only updating explicitly set config (not saving config set by the diagnostics)
2017-07-15 18:47:11 +08:00
const original = Config.original();
original.Server.thumbnail = settings.server;
original.Client.Thumbnail = settings.client;
original.save();
2017-07-19 16:21:52 +08:00
ProjectPath.reset();
2017-07-15 18:47:11 +08:00
await ConfigDiagnostics.runDiagnostics();
2018-03-31 03:30:30 +08:00
Logger.info(LOG_TAG, 'new config:');
2017-07-15 18:47:11 +08:00
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
2017-07-14 05:39:09 +08:00
return next();
} catch (err) {
2017-07-15 18:47:11 +08:00
if (err instanceof Error) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
2017-07-15 18:47:11 +08:00
}
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-14 05:39:09 +08:00
}
}
2017-07-15 18:47:11 +08:00
2017-07-26 03:09:37 +08:00
public static async updateBasicSettings(req: Request, res: Response, next: NextFunction) {
2017-07-15 22:09:48 +08:00
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
2017-07-15 22:09:48 +08:00
}
try {
const settings: BasicConfigDTO = req.body.settings;
2017-07-15 23:44:33 +08:00
await ConfigDiagnostics.testImageFolder(settings.imagesFolder);
2017-07-15 22:09:48 +08:00
Config.Server.port = settings.port;
Config.Server.host = settings.host;
2017-07-15 22:09:48 +08:00
Config.Server.imagesFolder = settings.imagesFolder;
Config.Client.publicUrl = settings.publicUrl;
Config.Client.urlBase = settings.urlBase;
2017-07-15 22:09:48 +08:00
Config.Client.applicationTitle = settings.applicationTitle;
2018-03-31 03:30:30 +08:00
// only updating explicitly set config (not saving config set by the diagnostics)
2017-07-15 22:09:48 +08:00
const original = Config.original();
original.Server.port = settings.port;
original.Server.host = settings.host;
2017-07-15 22:09:48 +08:00
original.Server.imagesFolder = settings.imagesFolder;
original.Client.publicUrl = settings.publicUrl;
original.Client.urlBase = settings.urlBase;
2017-07-15 22:09:48 +08:00
original.Client.applicationTitle = settings.applicationTitle;
original.save();
2017-07-19 16:21:52 +08:00
ProjectPath.reset();
2017-07-15 22:09:48 +08:00
await ConfigDiagnostics.runDiagnostics();
2018-03-31 03:30:30 +08:00
Logger.info(LOG_TAG, 'new config:');
2017-07-15 22:09:48 +08:00
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-15 22:09:48 +08:00
}
}
2017-07-26 03:09:37 +08:00
public static async updateOtherSettings(req: Request, res: Response, next: NextFunction) {
2017-07-15 22:31:43 +08:00
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
2017-07-15 22:31:43 +08:00
}
try {
const settings: OtherConfigDTO = req.body.settings;
Config.Client.Other.enableCache = settings.Client.enableCache;
Config.Client.Other.captionFirstNaming = settings.Client.captionFirstNaming;
Config.Client.Other.enableOnScrollRendering = settings.Client.enableOnScrollRendering;
Config.Client.Other.enableOnScrollThumbnailPrioritising = settings.Client.enableOnScrollThumbnailPrioritising;
Config.Client.Other.defaultPhotoSortingMethod = settings.Client.defaultPhotoSortingMethod;
Config.Client.Other.NavBar.showItemCount = settings.Client.NavBar.showItemCount;
2017-07-15 22:31:43 +08:00
2018-03-31 03:30:30 +08:00
// only updating explicitly set config (not saving config set by the diagnostics)
const original: PrivateConfigClass = Config.original();
original.Client.Other.enableCache = settings.Client.enableCache;
original.Client.Other.captionFirstNaming = settings.Client.captionFirstNaming;
original.Client.Other.enableOnScrollRendering = settings.Client.enableOnScrollRendering;
original.Client.Other.enableOnScrollThumbnailPrioritising = settings.Client.enableOnScrollThumbnailPrioritising;
original.Client.Other.defaultPhotoSortingMethod = settings.Client.defaultPhotoSortingMethod;
original.Client.Other.NavBar.showItemCount = settings.Client.NavBar.showItemCount;
original.Server.threading.enable = settings.Server.enable;
original.Server.threading.thumbnailThreads = settings.Server.thumbnailThreads;
2017-07-15 22:31:43 +08:00
original.save();
await ConfigDiagnostics.runDiagnostics();
2018-03-31 03:30:30 +08:00
Logger.info(LOG_TAG, 'new config:');
2017-07-15 22:31:43 +08:00
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-15 22:31:43 +08:00
}
}
2017-07-28 05:10:16 +08:00
public static async updateIndexingSettings(req: Request, res: Response, next: NextFunction) {
if ((typeof req.body === 'undefined') || (typeof req.body.settings === 'undefined')) {
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.INPUT_ERROR, 'settings is needed'));
2017-07-28 05:10:16 +08:00
}
try {
const settings: IndexingConfig = req.body.settings;
Config.Server.indexing = settings;
2018-03-31 03:30:30 +08:00
// only updating explicitly set config (not saving config set by the diagnostics)
2017-07-28 05:10:16 +08:00
const original = Config.original();
original.Server.indexing = settings;
original.save();
await ConfigDiagnostics.runDiagnostics();
2018-03-31 03:30:30 +08:00
Logger.info(LOG_TAG, 'new config:');
2017-07-28 05:10:16 +08:00
Logger.info(LOG_TAG, JSON.stringify(Config, null, '\t'));
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
2018-03-31 03:30:30 +08:00
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-28 05:10:16 +08:00
}
}
2017-07-15 22:31:43 +08:00
2017-07-26 03:09:37 +08:00
public static startIndexing(req: Request, res: Response, next: NextFunction) {
try {
2018-11-24 20:08:34 +08:00
const createThumbnails: boolean = (<IndexingDTO>req.body).createThumbnails || false;
2019-01-14 00:38:39 +08:00
ObjectManagerRepository.getInstance().IndexingTaskManager.startIndexing(createThumbnails);
2018-03-31 03:30:30 +08:00
req.resultPipe = 'ok';
2017-07-26 03:09:37 +08:00
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-26 03:09:37 +08:00
}
}
2018-11-24 20:08:34 +08:00
2017-07-26 03:09:37 +08:00
public static getIndexingProgress(req: Request, res: Response, next: NextFunction) {
try {
2019-01-14 00:38:39 +08:00
req.resultPipe = ObjectManagerRepository.getInstance().IndexingTaskManager.getProgress();
2017-07-26 03:09:37 +08:00
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-26 03:09:37 +08:00
}
}
public static cancelIndexing(req: Request, res: Response, next: NextFunction) {
try {
2019-01-14 00:38:39 +08:00
ObjectManagerRepository.getInstance().IndexingTaskManager.cancelIndexing();
2018-03-31 03:30:30 +08:00
req.resultPipe = 'ok';
2017-07-26 03:09:37 +08:00
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-26 03:09:37 +08:00
}
}
2018-11-29 06:49:33 +08:00
public static async resetIndexes(req: Express.Request, res: Response, next: NextFunction) {
2017-07-26 03:09:37 +08:00
try {
2019-01-14 00:38:39 +08:00
await ObjectManagerRepository.getInstance().IndexingTaskManager.reset();
2018-03-31 03:30:30 +08:00
req.resultPipe = 'ok';
2017-07-26 03:09:37 +08:00
return next();
} catch (err) {
2018-12-02 19:22:05 +08:00
if (err instanceof Error) {
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + err.toString(), err));
}
return next(new ErrorDTO(ErrorCodes.SETTINGS_ERROR, 'Settings error: ' + JSON.stringify(err, null, ' '), err));
2017-07-26 03:09:37 +08:00
}
}
2017-07-08 18:43:42 +08:00
}