2017-07-14 05:39:09 +08:00
|
|
|
import {Config} from "../../common/config/private/Config";
|
|
|
|
import {
|
|
|
|
DataBaseConfig,
|
|
|
|
DatabaseType,
|
|
|
|
ThumbnailConfig,
|
|
|
|
ThumbnailProcessingLib
|
|
|
|
} from "../../common/config/private/IPrivateConfig";
|
|
|
|
import {Logger} from "../Logger";
|
|
|
|
import {NotificationManager} from "./NotifocationManager";
|
|
|
|
import {ProjectPath} from "../ProjectPath";
|
|
|
|
import {MySQLConnection} from "./mysql/MySQLConnection";
|
|
|
|
import * as fs from "fs";
|
2017-07-15 18:47:11 +08:00
|
|
|
import {ClientConfig} from "../../common/config/public/ConfigClass";
|
2017-07-14 05:39:09 +08:00
|
|
|
|
|
|
|
const LOG_TAG = "[ConfigDiagnostics]";
|
|
|
|
export class ConfigDiagnostics {
|
|
|
|
|
|
|
|
static async testDatabase(databaseConfig: DataBaseConfig) {
|
|
|
|
if (databaseConfig.type == DatabaseType.mysql) {
|
|
|
|
await MySQLConnection.tryConnection(databaseConfig);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static async testThumbnailLib(processingLibrary: ThumbnailProcessingLib) {
|
|
|
|
switch (processingLibrary) {
|
|
|
|
case ThumbnailProcessingLib.sharp:
|
|
|
|
const sharp = require("sharp");
|
|
|
|
sharp();
|
|
|
|
break;
|
|
|
|
case ThumbnailProcessingLib.gm:
|
|
|
|
const gm = require("gm");
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
gm(ProjectPath.FrontendFolder + "/assets/icon.png").size((err, value) => {
|
2017-07-15 18:47:11 +08:00
|
|
|
if (err) {
|
|
|
|
return reject(err.toString());
|
2017-07-14 05:39:09 +08:00
|
|
|
}
|
2017-07-15 18:47:11 +08:00
|
|
|
return resolve();
|
2017-07-14 05:39:09 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static async testThumbnailFolder(folder: string) {
|
|
|
|
await new Promise((resolve, reject) => {
|
2017-07-14 15:28:52 +08:00
|
|
|
fs.access(folder, fs.constants.W_OK, (err) => {
|
2017-07-14 05:39:09 +08:00
|
|
|
if (err) {
|
2017-07-15 18:47:11 +08:00
|
|
|
reject({message: "ErrorDTO during getting write access to temp folder", error: err.toString()});
|
2017-07-14 05:39:09 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
static async testImageFolder(folder: string) {
|
|
|
|
await new Promise((resolve, reject) => {
|
|
|
|
if (!fs.existsSync(folder)) {
|
2017-07-14 15:28:52 +08:00
|
|
|
reject("Images folder not exists: '" + folder + "'");
|
2017-07-14 05:39:09 +08:00
|
|
|
}
|
2017-07-14 15:28:52 +08:00
|
|
|
fs.access(folder, fs.constants.R_OK, (err) => {
|
2017-07-14 05:39:09 +08:00
|
|
|
if (err) {
|
2017-07-15 18:47:11 +08:00
|
|
|
reject({message: "ErrorDTO during getting read access to images folder", error: err.toString()});
|
2017-07-14 05:39:09 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
resolve();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-15 18:47:11 +08:00
|
|
|
static async testServerThumbnailConfig(thumbnailConfig: ThumbnailConfig) {
|
2017-07-14 05:39:09 +08:00
|
|
|
await ConfigDiagnostics.testThumbnailLib(thumbnailConfig.processingLibrary);
|
|
|
|
await ConfigDiagnostics.testThumbnailFolder(thumbnailConfig.folder);
|
|
|
|
}
|
|
|
|
|
2017-07-15 18:47:11 +08:00
|
|
|
static async testClientThumbnailConfig(thumbnailConfig: ClientConfig.ThumbnailConfig) {
|
|
|
|
if (isNaN(thumbnailConfig.iconSize) || thumbnailConfig.iconSize <= 0) {
|
|
|
|
throw "IconSize has to be >= 0 integer, got: " + thumbnailConfig.iconSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!thumbnailConfig.thumbnailSizes.length) {
|
|
|
|
throw "At least one thumbnail size is needed";
|
|
|
|
}
|
|
|
|
for (let i = 0; i < thumbnailConfig.thumbnailSizes.length; i++) {
|
|
|
|
if (isNaN(thumbnailConfig.thumbnailSizes[i]) || thumbnailConfig.thumbnailSizes[i] <= 0) {
|
|
|
|
throw "Thumbnail size has to be >= 0 integer, got: " + thumbnailConfig.thumbnailSizes[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-14 05:39:09 +08:00
|
|
|
|
2017-07-15 18:47:11 +08:00
|
|
|
static async testSearchConfig(search: ClientConfig.SearchConfig) {
|
2017-07-14 05:39:09 +08:00
|
|
|
if (search.enabled == true && Config.Server.database.type == DatabaseType.memory) {
|
|
|
|
throw "Memory Database do not support searching";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-15 18:47:11 +08:00
|
|
|
static async testSharingConfig(sharing: ClientConfig.SharingConfig) {
|
2017-07-14 05:39:09 +08:00
|
|
|
if (sharing.enabled == true && Config.Server.database.type == DatabaseType.memory) {
|
|
|
|
throw "Memory Database do not support sharing";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-15 18:47:11 +08:00
|
|
|
static async testMapConfig(map: ClientConfig.MapConfig) {
|
2017-07-14 05:39:09 +08:00
|
|
|
if (map.enabled == true && (!map.googleApiKey || map.googleApiKey.length == 0)) {
|
|
|
|
throw "Maps need a valid google api key";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static async runDiagnostics() {
|
|
|
|
|
|
|
|
if (Config.Server.database.type == DatabaseType.mysql) {
|
|
|
|
try {
|
|
|
|
await ConfigDiagnostics.testDatabase(Config.Server.database);
|
|
|
|
} catch (err) {
|
|
|
|
Logger.warn(LOG_TAG, "[MYSQL error]", err);
|
2017-07-15 18:47:11 +08:00
|
|
|
Logger.warn(LOG_TAG, "ErrorDTO during initializing mysql falling back temporally to memory DB");
|
|
|
|
NotificationManager.warning("ErrorDTO during initializing mysql falling back temporally to memory DB", err);
|
2017-07-14 05:39:09 +08:00
|
|
|
Config.setDatabaseType(DatabaseType.memory);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Config.Server.thumbnail.processingLibrary != ThumbnailProcessingLib.Jimp) {
|
|
|
|
try {
|
|
|
|
await ConfigDiagnostics.testThumbnailLib(Config.Server.thumbnail.processingLibrary);
|
|
|
|
} catch (err) {
|
|
|
|
NotificationManager.warning("Thumbnail hardware acceleration is not possible." +
|
|
|
|
" '" + ThumbnailProcessingLib[Config.Server.thumbnail.processingLibrary] + "' node module is not found." +
|
2017-07-14 15:28:52 +08:00
|
|
|
" Falling back temporally to JS based thumbnail generation", err);
|
2017-07-14 05:39:09 +08:00
|
|
|
Logger.warn(LOG_TAG, "[Thumbnail hardware acceleration] module error: ", err);
|
|
|
|
Logger.warn(LOG_TAG, "Thumbnail hardware acceleration is not possible." +
|
|
|
|
" '" + ThumbnailProcessingLib[Config.Server.thumbnail.processingLibrary] + "' node module is not found." +
|
2017-07-14 15:28:52 +08:00
|
|
|
" Falling back temporally to JS based thumbnail generation");
|
2017-07-14 05:39:09 +08:00
|
|
|
Config.Server.thumbnail.processingLibrary = ThumbnailProcessingLib.Jimp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await ConfigDiagnostics.testThumbnailFolder(Config.Server.thumbnail.folder)
|
|
|
|
} catch (err) {
|
|
|
|
NotificationManager.error("Thumbnail folder error", err);
|
|
|
|
Logger.error(LOG_TAG, "Thumbnail folder error", err);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
await ConfigDiagnostics.testImageFolder(Config.Server.imagesFolder)
|
|
|
|
} catch (err) {
|
|
|
|
NotificationManager.error("Images folder error", err);
|
|
|
|
Logger.error(LOG_TAG, "Images folder error", err);
|
|
|
|
}
|
2017-07-15 18:47:11 +08:00
|
|
|
try {
|
|
|
|
await ConfigDiagnostics.testClientThumbnailConfig(Config.Client.Thumbnail)
|
|
|
|
} catch (err) {
|
|
|
|
NotificationManager.error("Thumbnail settings error", err);
|
|
|
|
Logger.error(LOG_TAG, "Thumbnail settings error", err);
|
|
|
|
}
|
2017-07-14 05:39:09 +08:00
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
await ConfigDiagnostics.testSearchConfig(Config.Client.Search);
|
|
|
|
} catch (err) {
|
2017-07-14 15:28:52 +08:00
|
|
|
NotificationManager.warning("Search is not supported with these settings. Disabling temporally. Please adjust the config properly.", err);
|
2017-07-14 05:39:09 +08:00
|
|
|
Logger.warn(LOG_TAG, "Search is not supported with these settings, switching off..", err);
|
|
|
|
Config.Client.Search.enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await ConfigDiagnostics.testSharingConfig(Config.Client.Sharing);
|
|
|
|
} catch (err) {
|
2017-07-14 15:28:52 +08:00
|
|
|
NotificationManager.warning("Sharing is not supported with these settings. Disabling temporally. Please adjust the config properly.", err);
|
2017-07-14 05:39:09 +08:00
|
|
|
Logger.warn(LOG_TAG, "Sharing is not supported with these settings, switching off..", err);
|
|
|
|
Config.Client.Sharing.enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
await ConfigDiagnostics.testMapConfig(Config.Client.Map);
|
|
|
|
} catch (err) {
|
2017-07-14 15:28:52 +08:00
|
|
|
NotificationManager.warning("Maps is not supported with these settings. Disabling temporally. Please adjust the config properly.", err);
|
|
|
|
Logger.warn(LOG_TAG, "Maps is not supported with these settings. Disabling temporally. Please adjust the config properly.", err);
|
2017-07-14 05:39:09 +08:00
|
|
|
Config.Client.Map.enabled = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|