1
0
mirror of https://dev.s-ul.net/Galexion/MaiMaiDXNet.git synced 2024-11-24 07:50:11 +01:00
MaiMaiDXNet/index.js

113 lines
3.3 KiB
JavaScript
Raw Normal View History

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");
if (config.serverType === 0) { // Only run the image Importer with aqua or when given Artemis Settings for it)
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){
const watcher = chokidar.watch(config.ArtImageDirectory, {
2023-02-17 00:50:32 +01:00
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 {
console.log("Image Export Disabled. Check readme.md for details.")
}
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);
}
// readFileSync function must use __dirname get current directory
2023-02-17 00:50:32 +01:00
// require use ./ refer to current directory.
const options = {};
2023-02-17 00:50:32 +01:00
var app = express()
// 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 }));
// define routes
2023-02-17 00:50:32 +01:00
app.use('/', indexRouter);
app.use('/api/', apiRouter);
// catch 404 and forward to error handler
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
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');
});
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;