Urgent correction of version v1.0.0-beta.14 due to crash issues when acting on the CDN.
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-07-12 18:13:03 +02:00
parent aaff0ed4ea
commit 44631acfc6
27 changed files with 704 additions and 534 deletions

View File

@@ -12,7 +12,17 @@ async function getUserData() {
throw err;
}
}
let userData = getUserData();
let userData;
(async () => {
try {
userData = await getUserData();
} catch (err) {
console.error(`Failed to initialize userData: ${err}`);
process.exit(1);
}
})();
async function checkUserExistsDiscord(req, res, next) {
if (!req.user || (!req.user.username && !req.user.id)) {
@@ -20,19 +30,18 @@ async function checkUserExistsDiscord(req, res, next) {
}
try {
let users = userData;
let userData = await getUserData();
let existingUser;
if (req.user.username) {
existingUser = users.find(u => u.name === req.user.username);
existingUser = userData.find(u => u.name === req.user.username);
} else if (req.user.id) {
existingUser = users.find(u => u.id === req.user.id);
existingUser = userData.find(u => u.id === req.user.id);
}
if (existingUser) {
req.user.id = existingUser.id;
res.redirect('/dpanel/dashboard');
return;
return res.redirect('/dpanel/dashboard');
}
const newUser = {
@@ -40,9 +49,10 @@ async function checkUserExistsDiscord(req, res, next) {
name: req.user.username,
role: "user"
};
users.push(newUser);
await fs.writeFile(filePath, JSON.stringify(users, null, 2), 'utf8');
userData.push(newUser);
await fs.writeFile(filePath, JSON.stringify(userData, null, 2), 'utf8');
req.user.id = newUser.id;
@@ -52,4 +62,5 @@ async function checkUserExistsDiscord(req, res, next) {
}
}
module.exports = { checkUserExistsDiscord };
module.exports = { checkUserExistsDiscord };