From 025a78d8243c90103719bc03a73378127cc5f3eb Mon Sep 17 00:00:00 2001 From: Galexion Date: Mon, 17 Jul 2023 02:16:54 -0400 Subject: [PATCH] made it so artemis memorial photos are accessible, and made it so you can change the port within the config file. --- dbhandler.js | 4 ++-- index.js | 27 ++++++++++++++++++++++++++- public/javascript/login.js | 2 +- public/javascript/user.js | 6 +++++- readme.md | 22 +++++++++++++++++----- routes/api.js | 8 +++++--- routes/index.js | 2 +- views/user.ejs | 10 ++++++++++ 8 files changed, 67 insertions(+), 14 deletions(-) diff --git a/dbhandler.js b/dbhandler.js index 62609f0..2d6643a 100644 --- a/dbhandler.js +++ b/dbhandler.js @@ -1,8 +1,8 @@ -const { serverType, ArtConnSettings, DXMemorialImageDirectory } = require('./config.json'); +const { serverType, ArtConnSettings, aquaSrvDir } = require('./config.json'); const sqlite3 = require('sqlite3').verbose(); var db = undefined; if (serverType === 0) { - db = new sqlite3.Database(DXMemorialImageDirectory + '\\db.sqlite'); + db = new sqlite3.Database(aquaSrvDir + '\\db.sqlite'); } const mysql = require('mysql'); var con = mysql.createConnection(ArtConnSettings) diff --git a/index.js b/index.js index c870a6b..59b8d5f 100644 --- a/index.js +++ b/index.js @@ -10,7 +10,32 @@ var apiRouter = require('./routes/api'); var config = require("./config.json"); if (config.serverType === 0) { // Only run the image Importer when Aqua is active - const watcher = chokidar.watch(config.DXMemorialImageDirectory, { + 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}`); + }); +} else if (config.ArtImageDirectory){ + const watcher = chokidar.watch(config.ArtImageDirectory, { persistent: true }); diff --git a/public/javascript/login.js b/public/javascript/login.js index 597a16b..56ef55a 100644 --- a/public/javascript/login.js +++ b/public/javascript/login.js @@ -51,7 +51,7 @@ form.addEventListener("submit", function (event) { let releventData = { luid: data.data.luid || data.data.access_code, - ext_id: data.data.ext_id + ext_id: data.data.ext_id || data.data.user } console.log(releventData) // Set the cookie expiration to 7 days from now diff --git a/public/javascript/user.js b/public/javascript/user.js index a4c6eef..75fd9e2 100644 --- a/public/javascript/user.js +++ b/public/javascript/user.js @@ -371,7 +371,11 @@ async function userImageFormatter(div) { memorialImage.addEventListener("error", function () { this.src = "assets/icon/UI_Icon_000000.png"; }); - memorialImage.src = "images/" + imageName + '.jpg'; + if(window.serverType === 0) { + memorialImage.src = "images/" + imageName + '.jpg'; + } else { + memorialImage.src = "images/" + imageName + '.jpeg'; + } imageInfoDiv.append(memorialImage) } } diff --git a/readme.md b/readme.md index f48bd07..5a6b2a1 100644 --- a/readme.md +++ b/readme.md @@ -47,7 +47,8 @@ Create a `config.json` file and paste this in, with paths to your instance. "user":"MaiDXNet", "password":"aSecurePassword" }, - "imageFolder": "N:\\MaiMaiDXNet\\public\\images" + "imageFolder": "N:\\MaiMaiDXNet\\public\\images", + "hostPort": "8000" } ``` @@ -59,20 +60,20 @@ Note: `imageFolder` leads to the `/public/images` folder of the directory. ## Artemis -### WARNING: Artemis currently does not have support for Memorial Photos, and none will be imported when attempting to use Artemis. - Create a `config.json` file and paste this in, with paths to your instance. ```json { "serverType": 1, - "aquaSrvDir": "A:\\path\\to\\aqua\\data", + "ArtImageImport": true, + "ArtImageDirectory":"S:\\Artemis\\Server\\Image\\Directory", "ArtConnSettings": { "host":"192.168.smt.hng", "user":"MaiDXNet", "pass":"aSecurePassword" }, - "imageFolder": "N:\\MaiMaiDXNet\\public\\images" + "imageFolder": "N:\\MaiMaiDXNet\\public\\images", + "hostPort": "8000" } ``` @@ -87,6 +88,17 @@ CREATE USER 'MaiDXNet'@'%' IDENTIFIED BY 'aSecurePassword'; GRANT Alter,Create,Delete,Drop,Index,Insert,References,Select,Update ON aime.* TO 'MaiDXNet'@'%'; ``` +Note: you'll need to configure `mai2.yaml` to enable Photo Sending to Artemis. Ensure that you have a image directory ready. + +```yaml + photos: True + photos_dir: "S:\\Artemis\\Server\\Image\\Directory" + movies: false + movies_dir: "S:\\Artemis\\Server\\Movie\\Directory" +``` + +If you can't update Artemis to a version that supports Photo Exporting, or simply don't want to use Memorial Photo's, please set `"ArtImageImport": false`. + # Project Progress Goal for Milestone 1: diff --git a/routes/api.js b/routes/api.js index 12e1c9f..d9a2718 100644 --- a/routes/api.js +++ b/routes/api.js @@ -78,11 +78,13 @@ var {getExtId,getUserArea,getUserScores,getUserUnbanned,getUserBanned, getUserDa }); router.get('/getmemorialimagelist/', function (req,res,next) { - let ext = ".jpg"; + let ext = ".jpg"; + let ext2 = ".jpeg"; // Use fs.readdirSync() to get the file names synchronously - const files = fs.readdirSync(config.DXMemorialImageDirectory); + const files = fs.readdirSync(config.imageFolder); // Filter the files by extension and create an array of names - const imageNames = files.filter(file => file.endsWith(ext)).map(file => file.slice(0, -ext.length)); + const imageNames = files.filter(file => file.endsWith('.jpg') || file.endsWith('.jpeg')).map(file => file.endsWith('.jpeg') ? file.slice(0, -5) : file.slice(0, -4)); + // Create and return a JSON object with the image names res.send(imageNames); }); diff --git a/routes/index.js b/routes/index.js index beafb43..34f045b 100644 --- a/routes/index.js +++ b/routes/index.js @@ -30,7 +30,7 @@ router.get('/user', async function (req, res, next) { if (cookies.aime_card_id === undefined) { return res.redirect("/") } - res.render('user', { title: title, userdata: await getUserData(req) }); + res.render('user', { title: title, userdata: await getUserData(req), params:{serverType: config.serverType}}); } catch (err) { res.render('error', { error: err }); } diff --git a/views/user.ejs b/views/user.ejs index 70c3ebc..7489988 100644 --- a/views/user.ejs +++ b/views/user.ejs @@ -1,4 +1,5 @@ <% var rootPath='../' ; %> + <%- include(rootPath + 'templates/header.ejs' ); %> <% function normalizeText(text) { return text .normalize('NFD') .replace(/[\u0300-\u036f]/g, '' ).replace(/[\uFF01-\uFF5E]/g, function(ch) { return String.fromCharCode(ch.charCodeAt(0) - 0xFEE0); }); } %> @@ -20,6 +21,15 @@ if(userdata.user_name !== undefined) { } } %> +<% if (params.serverType===0) { %> + + <% } else { %> + + <% } %>

Yo! Welcome Back <%= normalizeText(user.user_name) %>!