Skip to content

Commit

Permalink
Merge pull request #32 from CoR-Forum/res-db
Browse files Browse the repository at this point in the history
add API path to fetch all resources from the DB
  • Loading branch information
Joshua2504 authored Aug 27, 2024
2 parents ccc952b + 92685b0 commit a7ae1bc
Showing 1 changed file with 47 additions and 40 deletions.
87 changes: 47 additions & 40 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,46 +267,42 @@ db.query(`CREATE TABLE IF NOT EXISTS regnum_res (
// import regnum online resource server index from json file
// it contains the filename and needs to be converted
// 12345-Filename-goes-here.png -> ID 12345, Name Filename goes here, Filename 12345-Filename-goes-here.png
// const regnumRes = require('../public/data/texturesparadise/files.json');
// if (Array.isArray(regnumRes.textures)) {
// for (const res of regnumRes.textures) {
// const res_id = parseInt(res.filename.split('-')[0]);
// const filename = res.filename;
// const type = 'texture';
// const name = res.filename.split('-').slice(1).join(' ').split('.')[0];
// const url = "https://cor-forum.de/regnum/datengrab/res/" + type.toUpperCase + "/" + res.filename;
// db.query('INSERT INTO regnum_res (res_id, filename, name, type, url) VALUES (?, ?, ?, ?, ?)', [res_id, filename, name, type, url], (err) => {
// if (err) {
// logger.error('Error inserting regnum_res into database:', err);
// throw err;
// }
// });
// }
// } else {
// logger.error('regnumRes.textures is not an array');
// }
//
// if (Array.isArray(regnumRes.sounds)) {
// for (const res of regnumRes.sounds) {
// const res_id = parseInt(res.filename.split('-')[0]);
// const filename = res.filename;
// const type = 'sound';
// const name = res.filename.split('-').slice(1).join(' ').split('.')[0];
// const url = "https://cor-forum.de/regnum/datengrab/res/" + type.toUpperCase + "/" + res.filename;
// db.query('INSERT INTO regnum_res (res_id, filename, name, type, url) VALUES (?, ?, ?, ?, ?)', [res_id, filename, name, type, url], (err) => {
// if (err) {
// logger.error('Error inserting regnum_res into database:', err);
// throw err;
// }
// });
// }
// } else {
// logger.error('regnumRes.sounds is not an array');
// }




//const regnumRes = require('../public/data/texturesparadise/files.json');
//if (Array.isArray(regnumRes.textures)) {
// for (const res of regnumRes.textures) {
// const res_id = parseInt(res.filename.split('-')[0]);
// const filename = res.filename;
// const type = 'texture';
// const name = res.filename.split('-').slice(1).join(' ').split('.')[0];
// const url = "https://cor-forum.de/regnum/datengrab/res/" + type.toUpperCase + "/" + res.filename;
// db.query('INSERT INTO regnum_res (res_id, filename, name, type, url) VALUES (?, ?, ?, ?, ?)', [res_id, filename, name, type, url], (err) => {
// if (err) {
// logger.error('Error inserting regnum_res into database:', err);
// throw err;
// }
// });
// }
//} else {
// logger.error('regnumRes.textures is not an array');
//}
//
//if (Array.isArray(regnumRes.sounds)) {
// for (const res of regnumRes.sounds) {
// const res_id = parseInt(res.filename.split('-')[0]);
// const filename = res.filename;
// const type = 'sound';
// const name = res.filename.split('-').slice(1).join(' ').split('.')[0];
// const url = "https://cor-forum.de/regnum/datengrab/res/" + type.toUpperCase + "/" + res.filename;
// db.query('INSERT INTO regnum_res (res_id, filename, name, type, url) VALUES (?, ?, ?, ?, ?)', [res_id, filename, name, type, url], (err) => {
// if (err) {
// logger.error('Error inserting regnum_res into database:', err);
// throw err;
// }
// });
// }
//} else {
// logger.error('regnumRes.sounds is not an array');
//}

// E-Mails

Expand Down Expand Up @@ -1053,6 +1049,17 @@ app.put(API_PATH + '/trainer/mysetups/:id/name', checkAuth, (req, res) => {
});
});

// get all regnum resources
app.get(API_PATH + '/regnum/resources', (req, res) => {
db.query('SELECT * FROM regnum_res', (err, result) => {
if (err) {
logger.error('Error querying database: ' + err);
return res.status(500).send('Internal Server Error');
}
res.send(result);
});
});

if (process.env.NODE_ENV === 'production') {
// run "python3 warstatus/warstatus.py" every minute and once on startup
function runWarstatus() {
Expand Down

0 comments on commit a7ae1bc

Please sign in to comment.