2023-02-17 00:50:32 +01:00
|
|
|
const chokidar = require('chokidar');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
var createError = require('http-errors');
|
|
|
|
var express = require('express');
|
|
|
|
var cookieParser = require('cookie-parser');
|
|
|
|
var logger = require('morgan');
|
|
|
|
var indexRouter = require('./routes/index');
|
|
|
|
var apiRouter = require('./routes/api');
|
|
|
|
var config = require("./config.json");
|
|
|
|
|
2023-07-19 19:13:39 +02:00
|
|
|
if (config.serverType === 0) { // Only run the image Importer with aqua or when given Artemis Settings for it)
|
2023-07-17 08:16:54 +02:00
|
|
|
const watcher = chokidar.watch(config.aquaSrvDir, {
|
|
|
|
persistent: true
|
|
|
|
});
|
|
|
|
|
|
|
|
watcher
|
|
|
|
.on('add', (filePath) => {
|
|
|
|
const isImage = /\.(jpe?g|png|gif)$/i.test(filePath);
|
|
|
|
if (isImage) {
|
|
|
|
const fileName = path.basename(filePath);
|
|
|
|
const destPath = path.join(config.imageFolder, fileName);
|
|
|
|
fs.access(destPath, (err) => {
|
|
|
|
if (err) {
|
|
|
|
fs.copyFile(filePath, destPath, (err) => {
|
|
|
|
if (err) throw err;
|
|
|
|
console.log(`${fileName} Imported.`);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('error', (error) => {
|
|
|
|
console.error(`Watcher error: ${error}`);
|
|
|
|
});
|
2023-07-17 08:17:09 +02:00
|
|
|
} else if (config.ArtImageDirectory && config.ArtImageImport === true){
|
2023-07-17 08:16:54 +02:00
|
|
|
const watcher = chokidar.watch(config.ArtImageDirectory, {
|
2023-02-17 00:50:32 +01:00
|
|
|
persistent: true
|
|
|
|
});
|
|
|
|
|
2023-07-16 10:06:49 +02:00
|
|
|
watcher
|
|
|
|
.on('add', (filePath) => {
|
|
|
|
const isImage = /\.(jpe?g|png|gif)$/i.test(filePath);
|
|
|
|
if (isImage) {
|
|
|
|
const fileName = path.basename(filePath);
|
|
|
|
const destPath = path.join(config.imageFolder, fileName);
|
|
|
|
fs.access(destPath, (err) => {
|
|
|
|
if (err) {
|
|
|
|
fs.copyFile(filePath, destPath, (err) => {
|
|
|
|
if (err) throw err;
|
|
|
|
console.log(`${fileName} Imported.`);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.on('error', (error) => {
|
|
|
|
console.error(`Watcher error: ${error}`);
|
|
|
|
});
|
2023-07-17 08:17:09 +02:00
|
|
|
} else {
|
|
|
|
console.log("Image Export Disabled. Check readme.md for details.")
|
2023-07-16 10:06:49 +02:00
|
|
|
}
|
2023-07-19 19:13:39 +02:00
|
|
|
if(config.serverType === 1 && !config.ArtConnSettings.connectionLimit) {
|
|
|
|
console.error("You are Missing the `ConnectionLimit` setting. Please add and set it in config.json.");
|
|
|
|
process.exit(1);
|
|
|
|
}
|
2023-07-16 10:06:49 +02:00
|
|
|
|
|
|
|
// readFileSync function must use __dirname get current directory
|
2023-02-17 00:50:32 +01:00
|
|
|
// require use ./ refer to current directory.
|
|
|
|
|
2023-07-16 10:06:49 +02:00
|
|
|
const options = {};
|
2023-02-17 00:50:32 +01:00
|
|
|
var app = express()
|
|
|
|
|
2023-07-16 10:06:49 +02:00
|
|
|
// Create HTTPs server.
|
2023-02-17 00:50:32 +01:00
|
|
|
|
|
|
|
//var httpsServer = https.createServer(options, app);
|
|
|
|
|
|
|
|
// view engine setup
|
|
|
|
app.set('views', path.join(__dirname, 'views'));
|
|
|
|
app.set('view engine', 'ejs');
|
|
|
|
app.use(express.static(__dirname + '/public'));
|
|
|
|
app.use(logger('dev'));
|
|
|
|
app.use(express.urlencoded({ extended: false }));
|
|
|
|
app.use(cookieParser());
|
|
|
|
app.use(express.json({ extended: false }));
|
|
|
|
|
2023-07-16 10:06:49 +02:00
|
|
|
// define routes
|
2023-02-17 00:50:32 +01:00
|
|
|
app.use('/', indexRouter);
|
|
|
|
app.use('/api/', apiRouter);
|
|
|
|
|
|
|
|
// catch 404 and forward to error handler
|
2023-07-16 10:06:49 +02:00
|
|
|
app.use(function (req, res, next) {
|
2023-02-17 00:50:32 +01:00
|
|
|
next(createError(404));
|
|
|
|
});
|
|
|
|
|
2023-07-17 08:17:09 +02:00
|
|
|
var PORT = config.hostPort || 8000
|
2023-02-17 00:50:32 +01:00
|
|
|
|
|
|
|
// error handler
|
2023-07-16 10:06:49 +02:00
|
|
|
app.use(function (err, req, res, next) {
|
2023-02-17 00:50:32 +01:00
|
|
|
// set locals, only providing error in development
|
|
|
|
res.locals.message = err.message;
|
|
|
|
res.locals.error = req.app.get('env') === 'development' ? err : {};
|
|
|
|
|
|
|
|
// render the error page
|
|
|
|
res.status(err.status || 500);
|
|
|
|
res.render('error');
|
|
|
|
});
|
|
|
|
|
2023-07-16 10:06:49 +02:00
|
|
|
app.listen(PORT, () => console.log(`Server is running in port ${PORT}, Server type ${config.serverType}`));
|
2023-02-17 00:50:32 +01:00
|
|
|
|
|
|
|
module.exports = app;
|