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
All checks were successful
continuous-integration/drone/push Build is passing
We would like to apologize for the inconvenience caused and we would like to thank you for the quick report.
This commit is contained in:
@@ -122,46 +122,24 @@ body.dark-theme .navbar-toggler-icon {
|
|||||||
filter: invert(1);
|
filter: invert(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
#logoutLink {
|
|
||||||
transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
|
|
||||||
color: #007BFF;
|
|
||||||
background-color: transparent;
|
|
||||||
padding: 8px 16px;
|
|
||||||
text-decoration: none;
|
|
||||||
display: inline-block;
|
|
||||||
font-size: 14px;
|
|
||||||
margin: 4px 2px;
|
|
||||||
border-radius: 50px;
|
|
||||||
cursor: pointer;
|
|
||||||
box-shadow: 0 2px 5px rgba(0,0,0,0.25);
|
|
||||||
border: 2px solid #007BFF;
|
|
||||||
}
|
|
||||||
|
|
||||||
#logoutLink:hover {
|
|
||||||
transform: scale(1.15);
|
|
||||||
background-color: #007BFF;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
.custom-btn {
|
.custom-btn {
|
||||||
transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
|
display: inline-flex;
|
||||||
color: #007BFF;
|
align-items: center;
|
||||||
background-color: transparent;
|
justify-content: center;
|
||||||
padding: 8px 16px;
|
font-family: inherit;
|
||||||
text-decoration: none;
|
font-weight: 500;
|
||||||
display: inline-block;
|
font-size: 14px; /* réduit la taille de la police */
|
||||||
font-size: 14px;
|
padding: 0.6em 1.2em; /* réduit le padding */
|
||||||
margin: 4px 2px;
|
color: white;
|
||||||
border-radius: 50px;
|
background: linear-gradient(0deg, rgba(77,54,208,1) 0%, rgba(132,116,254,1) 100%);
|
||||||
|
border: none;
|
||||||
|
box-shadow: 0 0.7em 1.5em -0.5em #4d36d0be;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
border-radius: 15em; /* réduit le rayon de la bordure */
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
box-shadow: 0 2px 5px rgba(0,0,0,0.25);
|
transition: all 0.3s ease;
|
||||||
border: 2px solid #007BFF;
|
position: relative;
|
||||||
}
|
overflow: hidden;
|
||||||
|
|
||||||
.custom-btn:hover {
|
|
||||||
transform: scale(1.15);
|
|
||||||
background-color: #007BFF;
|
|
||||||
color: #fff;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.btn-icon {
|
.btn-icon {
|
||||||
@@ -171,30 +149,48 @@ body.dark-theme .navbar-toggler-icon {
|
|||||||
|
|
||||||
.custom-dropdown,
|
.custom-dropdown,
|
||||||
.animated-button {
|
.animated-button {
|
||||||
position: relative;
|
display: inline-flex;
|
||||||
background: #1d2429;
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font-family: inherit;
|
||||||
|
font-weight: 500;
|
||||||
|
font-size: 14px; /* réduit la taille de la police */
|
||||||
|
padding: 0.6em 1.2em; /* réduit le padding */
|
||||||
|
color: white;
|
||||||
|
background: linear-gradient(0deg, rgba(77,54,208,1) 0%, rgba(132,116,254,1) 100%);
|
||||||
border: none;
|
border: none;
|
||||||
|
box-shadow: 0 0.7em 1.5em -0.5em #4d36d0be;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
border-radius: 15em; /* réduit le rayon de la bordure */
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
padding: 10px 20px;
|
|
||||||
font-size: 1em;
|
|
||||||
color: #17a2b8;
|
|
||||||
transition: all 0.3s ease;
|
transition: all 0.3s ease;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
body.white-theme .custom-dropdown,
|
body .custom-dropdown:focus,
|
||||||
body.white-theme .animated-button {
|
body .animated-button:focus {
|
||||||
color: #6c757d;
|
color: #ffffff !important; /* Change the text color to white */
|
||||||
background: #e9ecef;
|
background: linear-gradient(0deg, rgba(77,54,208,1) 0%, rgba(132,116,254,1) 100%) !important; /* Keep the background color as the button color */
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-dropdown:hover,
|
body.white-theme .custom-dropdown:focus,
|
||||||
.animated-button:hover {
|
body.white-theme .animated-button:focus {
|
||||||
background: #343a40;
|
color: #ffffff !important; /* Change the text color to white */
|
||||||
color: #fff;
|
background: linear-gradient(0deg, rgba(77,54,208,1) 0%, rgba(132,116,254,1) 100%) !important; /* Keep the background color as the button color */
|
||||||
}
|
}
|
||||||
|
|
||||||
body.white-theme .custom-dropdown:hover,
|
@keyframes rainbowBorder {
|
||||||
body.white-theme .animated-button:hover {
|
0% { box-shadow: 0 0 0 3px rgba(255, 0, 0, 0.7); }
|
||||||
background: #343a40;
|
14% { box-shadow: 0 0 0 3px rgba(255, 127, 0, 0.7); }
|
||||||
color: #fff;
|
28% { box-shadow: 0 0 0 3px rgba(255, 255, 0, 0.7); }
|
||||||
|
42% { box-shadow: 0 0 0 3px rgba(0, 255, 0, 0.7); }
|
||||||
|
57% { box-shadow: 0 0 0 3px rgba(0, 0, 255, 0.7); }
|
||||||
|
71% { box-shadow: 0 0 0 3px rgba(75, 0, 130, 0.7); }
|
||||||
|
85% { box-shadow: 0 0 0 3px rgba(143, 0, 255, 0.7); }
|
||||||
|
100% { box-shadow: 0 0 0 3px rgba(255, 0, 0, 0.7); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.rainbow-effect {
|
||||||
|
animation: rainbowBorder 2s linear infinite;
|
||||||
}
|
}
|
||||||
@@ -337,4 +337,78 @@ async function showFileInfo(fileName) {
|
|||||||
html: html,
|
html: html,
|
||||||
confirmButtonText: 'Fermer'
|
confirmButtonText: 'Fermer'
|
||||||
});
|
});
|
||||||
}
|
}document.addEventListener('DOMContentLoaded', function () {
|
||||||
|
const moveFileForm = document.getElementById('moveFileForm');
|
||||||
|
|
||||||
|
moveFileForm.addEventListener('submit', function (event) {
|
||||||
|
event.preventDefault(); // Empêche la soumission par défaut du formulaire
|
||||||
|
|
||||||
|
const fileName = this.querySelector('input[name="fileName"]').value;
|
||||||
|
const userName = this.querySelector('input[name="userName"]').value;
|
||||||
|
const oldFolderName = this.querySelector('input[name="oldFolderName"]').value;
|
||||||
|
const newFolderName = this.querySelector('select[name="newFolderName"]').value;
|
||||||
|
|
||||||
|
if (!newFolderName || newFolderName === "Déplacer vers...") {
|
||||||
|
Swal.fire({
|
||||||
|
position: 'top',
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Veuillez sélectionner un dossier de destination',
|
||||||
|
showConfirmButton: false,
|
||||||
|
timer: 1800,
|
||||||
|
toast: true
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Swal.fire({
|
||||||
|
title: 'Confirmer le déplacement du fichier',
|
||||||
|
text: `Voulez-vous déplacer le fichier ${fileName} vers ${newFolderName} ?`,
|
||||||
|
icon: 'warning',
|
||||||
|
showCancelButton: true,
|
||||||
|
confirmButtonText: 'Déplacer',
|
||||||
|
cancelButtonText: 'Annuler',
|
||||||
|
}).then((result) => {
|
||||||
|
if (result.isConfirmed) {
|
||||||
|
fetch(`/api/dpanel/dashboard/movefile/${oldFolderName}`, {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ fileName, userName, newFolderName }),
|
||||||
|
})
|
||||||
|
.then(response => {
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error('Network response was not ok');
|
||||||
|
}
|
||||||
|
return response.json();
|
||||||
|
})
|
||||||
|
.then(data => {
|
||||||
|
if (data.message === "File moved successfully") {
|
||||||
|
Swal.fire({
|
||||||
|
position: 'top',
|
||||||
|
icon: 'success',
|
||||||
|
title: 'Le fichier a été déplacé avec succès.',
|
||||||
|
showConfirmButton: false,
|
||||||
|
timer: 1800,
|
||||||
|
toast: true,
|
||||||
|
}).then(() => {
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
throw new Error(data.error || 'Une erreur est survenue');
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
Swal.fire({
|
||||||
|
position: 'top',
|
||||||
|
icon: 'error',
|
||||||
|
title: 'Erreur lors du déplacement du fichier.',
|
||||||
|
showConfirmButton: false,
|
||||||
|
timer: 1800,
|
||||||
|
toast: true,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -99,6 +99,12 @@ router.use(bodyParser.json());
|
|||||||
|
|
||||||
|
|
||||||
function authenticateToken(req, res, next) {
|
function authenticateToken(req, res, next) {
|
||||||
|
if (req.session.user) {
|
||||||
|
req.user = req.session.user;
|
||||||
|
req.userData = req.session.user;
|
||||||
|
return next();
|
||||||
|
}
|
||||||
|
|
||||||
let token = null;
|
let token = null;
|
||||||
const authHeader = req.headers['authorization'];
|
const authHeader = req.headers['authorization'];
|
||||||
|
|
||||||
@@ -125,6 +131,8 @@ function authenticateToken(req, res, next) {
|
|||||||
return res.status(401).json({ message: 'Unauthorized: Invalid token' });
|
return res.status(401).json({ message: 'Unauthorized: Invalid token' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Enregistrer l'utilisateur dans la session
|
||||||
|
req.session.user = user;
|
||||||
req.user = user;
|
req.user = user;
|
||||||
req.userData = user;
|
req.userData = user;
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -129,9 +129,9 @@ function authenticateToken(req, res, next) {
|
|||||||
return res.status(401).json({ message: 'Unauthorized' });
|
return res.status(401).json({ message: 'Unauthorized' });
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
fs.readFile(path.join(__dirname, '../../../data', 'user.jso,'), 'utf8', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error reading user.json:', err);
|
console.error('Error reading user.jso,:', err);
|
||||||
return res.status(401).json({ message: 'Unauthorized' });
|
return res.status(401).json({ message: 'Unauthorized' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ function authenticateToken(req, res, next) {
|
|||||||
|
|
||||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error reading user.json:', err);
|
console.error('Error reading user.js:', err);
|
||||||
return res.status(401).json({ message: 'Unauthorized' });
|
return res.status(401).json({ message: 'Unauthorized' });
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,23 +145,24 @@ router.post('/', authenticateToken, async (req, res) => {
|
|||||||
const folderName = req.body.folderName;
|
const folderName = req.body.folderName;
|
||||||
|
|
||||||
if (!fileName || fileName.trim() === '') {
|
if (!fileName || fileName.trim() === '') {
|
||||||
return res.status(400).send('No file selected for moving.');
|
return res.status(400).json({ error: 'No file selected for moving.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await fs.readFileSync(path.join(__dirname, '../../../data', 'user.json'), 'utf-8')
|
try {
|
||||||
|
const data = await fs.promises.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf-8');
|
||||||
const users = JSON.parse(data);
|
const users = JSON.parse(data);
|
||||||
const user = users.find(user => user.id === req.user.id);
|
const user = users.find(user => user.id === req.user.id);
|
||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
console.error('User not found in user.json');
|
console.error('User not found in user.json');
|
||||||
return res.status(500).send('Error moving the file.');
|
return res.status(500).json({ error: 'Error moving the file.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const userId = user.name;
|
const userId = user.name;
|
||||||
|
|
||||||
if (!fileName || !userId) {
|
if (!fileName || !userId) {
|
||||||
console.error('fileName or userId is undefined');
|
console.error('fileName or userId is undefined');
|
||||||
return res.status(500).send('Error moving the file.');
|
return res.status(500).json({ error: 'Error moving the file.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const sourcePath = path.join('cdn-files', userId, fileName);
|
const sourcePath = path.join('cdn-files', userId, fileName);
|
||||||
@@ -175,24 +176,24 @@ router.post('/', authenticateToken, async (req, res) => {
|
|||||||
|
|
||||||
const destinationPath = path.join(destinationDir, fileName);
|
const destinationPath = path.join(destinationDir, fileName);
|
||||||
|
|
||||||
try {
|
if (!destinationPath.startsWith(path.join('cdn-files', userId))) {
|
||||||
|
return res.status(403).json({ error: 'Unauthorized: Cannot move file outside of user directory.' });
|
||||||
|
}
|
||||||
|
|
||||||
const normalizedSourcePath = path.normalize(sourcePath);
|
const normalizedSourcePath = path.normalize(sourcePath);
|
||||||
console.log('Full Source Path:', normalizedSourcePath);
|
|
||||||
|
|
||||||
if (fs.existsSync(normalizedSourcePath)) {
|
if (fs.existsSync(normalizedSourcePath)) {
|
||||||
await fs.promises.access(destinationDir);
|
await fs.promises.access(destinationDir);
|
||||||
|
|
||||||
await ncpAsync(normalizedSourcePath, destinationPath);
|
await ncpAsync(normalizedSourcePath, destinationPath);
|
||||||
|
|
||||||
await fs.promises.unlink(normalizedSourcePath);
|
await fs.promises.unlink(normalizedSourcePath);
|
||||||
} else {
|
} else {
|
||||||
console.log('File does not exist');
|
return res.status(404).json({ error: 'File not found.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
res.status(200).json({ message: 'File moved successfully' });
|
res.status(200).json({ message: 'File moved successfully' });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).send('Error moving the file.');
|
return res.status(500).json({ error: 'Error moving the file.' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -208,7 +209,11 @@ router.post('/:folderName', authenticateToken, async (req, res) => {
|
|||||||
|
|
||||||
if (fileName === undefined || userName === undefined || oldFolderName === undefined || newFolderName === undefined) {
|
if (fileName === undefined || userName === undefined || oldFolderName === undefined || newFolderName === undefined) {
|
||||||
console.error('fileName, userName, oldFolderName, or newFolderName is undefined');
|
console.error('fileName, userName, oldFolderName, or newFolderName is undefined');
|
||||||
return res.status(500).send('Error moving the file.');
|
return res.status(500).json({ error: 'Error moving the file.' });
|
||||||
|
}
|
||||||
|
|
||||||
|
if (userName !== req.user.name) {
|
||||||
|
return res.status(403).json({ error: 'Unauthorized: Cannot move files for other users.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const userDir = path.join(process.cwd(), 'cdn-files', userName);
|
const userDir = path.join(process.cwd(), 'cdn-files', userName);
|
||||||
@@ -218,25 +223,23 @@ router.post('/:folderName', authenticateToken, async (req, res) => {
|
|||||||
|
|
||||||
if (!sourcePath.startsWith(userDir) || !destinationPath.startsWith(userDir)) {
|
if (!sourcePath.startsWith(userDir) || !destinationPath.startsWith(userDir)) {
|
||||||
ErrorLogger.error('Unauthorized directory access attempt');
|
ErrorLogger.error('Unauthorized directory access attempt');
|
||||||
return res.status(403).send('Unauthorized directory access attempt');
|
return res.status(403).json({ error: 'Unauthorized directory access attempt' });
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const normalizedSourcePath = path.normalize(sourcePath);
|
const normalizedSourcePath = path.normalize(sourcePath);
|
||||||
console.log('Full Source Path:', normalizedSourcePath);
|
|
||||||
|
|
||||||
if (fs.existsSync(normalizedSourcePath)) {
|
if (fs.existsSync(normalizedSourcePath)) {
|
||||||
await fs.promises.access(destinationDir, fs.constants.W_OK);
|
await fs.promises.access(destinationDir, fs.constants.W_OK);
|
||||||
|
|
||||||
await fs.promises.rename(normalizedSourcePath, destinationPath);
|
await fs.promises.rename(normalizedSourcePath, destinationPath);
|
||||||
} else {
|
} else {
|
||||||
console.log('File does not exist');
|
return res.status(404).json({ error: 'File not found.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
res.redirect('/dpanel/dashboard');
|
res.status(200).json({ message: 'File moved successfully', redirectTo: '/dpanel/dashboard' });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
return res.status(500).send('Error moving the file.');
|
return res.status(500).json({ error: 'Error moving the file.' });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -105,7 +105,7 @@ function authenticateToken(req, res, next) {
|
|||||||
return res.status(401).json({ message: 'Unauthorized' });
|
return res.status(401).json({ message: 'Unauthorized' });
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
fs.readFile(path.join(__dirname, '../../../data', 'user.jso,'), 'utf8', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error reading user.json:', err);
|
console.error('Error reading user.json:', err);
|
||||||
return res.status(401).json({ message: 'Unauthorized' });
|
return res.status(401).json({ message: 'Unauthorized' });
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ function authenticateToken(req, res, next) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
fs.readFile(path.join(__dirname, '../../../data', 'user.jso,'), 'utf8', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error reading user.json:', err);
|
console.error('Error reading user.json:', err);
|
||||||
return res.status(401).json({ message: 'Unauthorized' });
|
return res.status(401).json({ message: 'Unauthorized' });
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ router.post('/', authMiddleware, async (req, res) => {
|
|||||||
user.role = role;
|
user.role = role;
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.writeFileSync(path.join(__dirname, '../../../data/user.json'), JSON.stringify(User, null, 2));
|
fs.writeFileSync(path.join(__dirname, '../../../data/user.js'), JSON.stringify(User, null, 2));
|
||||||
|
|
||||||
res.redirect('/dpanel/dashboard/admin');
|
res.redirect('/dpanel/dashboard/admin');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
@@ -112,9 +112,9 @@ function authenticateToken(req, res, next) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
fs.readFile(path.join(__dirname, '../../../data', 'user.jso,'), 'utf8', (err, data) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.error('Error reading user.json:', err);
|
console.error('Error reading user.jso,:', err);
|
||||||
return res.status(401).json({ message: 'Unauthorized' });
|
return res.status(401).json({ message: 'Unauthorized' });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ const express = require('express');
|
|||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const fs = require('fs').promises;
|
const fs = require('fs').promises;
|
||||||
|
const fsStandard = require('fs');
|
||||||
const mime = require('mime-types');
|
const mime = require('mime-types');
|
||||||
const { logger, ErrorLogger } = require('../config/logs');
|
const { logger, ErrorLogger } = require('../config/logs');
|
||||||
const bcrypt = require('bcrypt');
|
const bcrypt = require('bcrypt');
|
||||||
@@ -27,7 +28,12 @@ async function findFileInUserDir(userId, filename) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function findFileInDir(dir, filename) {
|
async function findFileInDir(dir, filename) {
|
||||||
const files = await fs.readdir(dir, { withFileTypes: true });
|
let files;
|
||||||
|
try {
|
||||||
|
files = await fs.readdir(dir, { withFileTypes: true });
|
||||||
|
} catch (err) {
|
||||||
|
return null; // Directory does not exist
|
||||||
|
}
|
||||||
|
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const filePath = path.join(dir, file.name);
|
const filePath = path.join(dir, file.name);
|
||||||
@@ -65,11 +71,12 @@ router.get('/:userId/:filename', async (req, res) => {
|
|||||||
fileInfoArray = JSON.parse(data);
|
fileInfoArray = JSON.parse(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error parsing file_info.json:', error);
|
console.error('Error parsing file_info.json:', error);
|
||||||
|
return res.status(500).send('Error reading file info.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(fileInfoArray)) {
|
if (!Array.isArray(fileInfoArray)) {
|
||||||
console.error('fileInfoArray is not an array');
|
console.error('fileInfoArray is not an array');
|
||||||
fileInfoArray = [];
|
return res.status(500).send('Invalid file info format.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileInfo = fileInfoArray.find(info => info.fileName === filename && info.Id === userId);
|
const fileInfo = fileInfoArray.find(info => info.fileName === filename && info.Id === userId);
|
||||||
@@ -88,26 +95,11 @@ router.get('/:userId/:filename', async (req, res) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileContent = await fs.readFile(filePath);
|
const readStream = fsStandard.createReadStream(filePath);
|
||||||
let mimeType = mime.lookup(filePath);
|
let mimeType = mime.lookup(filePath) || 'application/octet-stream';
|
||||||
|
|
||||||
if (!mimeType) {
|
|
||||||
if (filePath.endsWith('.txt')) {
|
|
||||||
mimeType = 'text/plain';
|
|
||||||
} else if (filePath.endsWith('.pdf')) {
|
|
||||||
mimeType = 'application/pdf';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mimeType) {
|
|
||||||
res.setHeader('Content-Type', mimeType);
|
res.setHeader('Content-Type', mimeType);
|
||||||
}
|
readStream.pipe(res);
|
||||||
|
|
||||||
if (mimeType === 'text/plain') {
|
|
||||||
res.end(fileContent);
|
|
||||||
} else {
|
|
||||||
res.send(fileContent);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (fileInfo) {
|
if (fileInfo) {
|
||||||
req.session.passwordVerified = false;
|
req.session.passwordVerified = false;
|
||||||
@@ -129,11 +121,12 @@ router.post('/:userId/:filename', async (req, res) => {
|
|||||||
fileInfoArray = JSON.parse(data);
|
fileInfoArray = JSON.parse(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error parsing file_info.json:', error);
|
console.error('Error parsing file_info.json:', error);
|
||||||
|
return res.status(500).send('Error reading file info.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(fileInfoArray)) {
|
if (!Array.isArray(fileInfoArray)) {
|
||||||
console.error('fileInfoArray is not an array');
|
console.error('fileInfoArray is not an array');
|
||||||
fileInfoArray = [];
|
return res.status(500).send('Invalid file info format.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const fileInfo = fileInfoArray.find(info => info.fileName === filename && info.Id === userId);
|
const fileInfo = fileInfoArray.find(info => info.fileName === filename && info.Id === userId);
|
||||||
@@ -142,21 +135,21 @@ router.post('/:userId/:filename', async (req, res) => {
|
|||||||
return res.json({ success: false, message: 'File not found' });
|
return res.json({ success: false, message: 'File not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bcrypt.compareSync(enteredPassword, fileInfo.password)) {
|
const passwordMatch = await bcrypt.compare(enteredPassword, fileInfo.password);
|
||||||
|
if (passwordMatch) {
|
||||||
req.session.passwordVerified = true;
|
req.session.passwordVerified = true;
|
||||||
const filePath = await findFileInUserDir(userId, filename);
|
const filePath = await findFileInUserDir(userId, filename);
|
||||||
const fileContent = await fs.readFile(filePath);
|
const readStream = fsStandard.createReadStream(filePath);
|
||||||
let mimeType = mime.lookup(filePath);
|
let mimeType = mime.lookup(filePath) || 'application/octet-stream';
|
||||||
|
|
||||||
if (!mimeType) {
|
let fileContent = '';
|
||||||
if (filePath.endsWith('.txt')) {
|
readStream.on('data', chunk => {
|
||||||
mimeType = 'text/plain';
|
fileContent += chunk.toString('base64');
|
||||||
} else if (filePath.endsWith('.pdf')) {
|
});
|
||||||
mimeType = 'application/pdf';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res.json({ success: true, fileContent: fileContent.toString('base64'), mimeType });
|
readStream.on('end', () => {
|
||||||
|
res.json({ success: true, fileContent, mimeType });
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
res.json({ success: false, message: 'Incorrect password' });
|
res.json({ success: false, message: 'Incorrect password' });
|
||||||
}
|
}
|
||||||
@@ -167,24 +160,31 @@ router.post('/:userId/:filename', async (req, res) => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function deleteExpiredFiles() {
|
async function deleteExpiredFiles() {
|
||||||
let data = await fs.readFile(path.join(__dirname, '../data', 'file_info.json'), 'utf8');
|
let data;
|
||||||
|
try {
|
||||||
|
data = await fs.readFile(path.join(__dirname, '../data', 'file_info.json'), 'utf8');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error reading file_info.json:', error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let fileInfoArray;
|
let fileInfoArray;
|
||||||
try {
|
try {
|
||||||
fileInfoArray = JSON.parse(data);
|
fileInfoArray = JSON.parse(data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error parsing file_info.json:', error);
|
console.error('Error parsing file_info.json:', error);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Array.isArray(fileInfoArray)) {
|
if (!Array.isArray(fileInfoArray)) {
|
||||||
console.error('fileInfoArray is not an array');
|
console.error('fileInfoArray is not an array');
|
||||||
fileInfoArray = [];
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
let newFileInfoArray = [];
|
let newFileInfoArray = [];
|
||||||
|
|
||||||
for (let i = 0; i < fileInfoArray.length; i++) {
|
for (const fileInfo of fileInfoArray) {
|
||||||
const fileInfo = fileInfoArray[i];
|
|
||||||
let expiryDate;
|
let expiryDate;
|
||||||
if (fileInfo.expiryDate && fileInfo.expiryDate.trim() !== '') {
|
if (fileInfo.expiryDate && fileInfo.expiryDate.trim() !== '') {
|
||||||
expiryDate = new Date(fileInfo.expiryDate);
|
expiryDate = new Date(fileInfo.expiryDate);
|
||||||
@@ -193,10 +193,10 @@ async function deleteExpiredFiles() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (expiryDate < now) {
|
if (expiryDate < now) {
|
||||||
|
try {
|
||||||
const samaccountname = await getSamAccountNameFromUserId(fileInfo.userId);
|
const samaccountname = await getSamAccountNameFromUserId(fileInfo.userId);
|
||||||
const userDir = path.join(baseDir, samaccountname);
|
const userDir = path.join(baseDir, samaccountname);
|
||||||
const filePath = path.join(userDir, fileInfo.fileName);
|
const filePath = path.join(userDir, fileInfo.fileName);
|
||||||
try {
|
|
||||||
await fs.unlink(filePath);
|
await fs.unlink(filePath);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ErrorLogger.error('Error deleting file:', err);
|
ErrorLogger.error('Error deleting file:', err);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ router.use('/api/dpanel/dashboard/newfolder',discordWebhookSuspisiousAlertMiddle
|
|||||||
router.use('/api/dpanel/dashboard/rename',discordWebhookSuspisiousAlertMiddleware, logApiRequest, RenameFileRoute);
|
router.use('/api/dpanel/dashboard/rename',discordWebhookSuspisiousAlertMiddleware, logApiRequest, RenameFileRoute);
|
||||||
router.use('/api/dpanel/dashboard/delete',discordWebhookSuspisiousAlertMiddleware, logApiRequest, DeleteFileRoute);
|
router.use('/api/dpanel/dashboard/delete',discordWebhookSuspisiousAlertMiddleware, logApiRequest, DeleteFileRoute);
|
||||||
router.use('/api/dpanel/dashboard/movefile',discordWebhookSuspisiousAlertMiddleware, logApiRequest, MoveFileRoute);
|
router.use('/api/dpanel/dashboard/movefile',discordWebhookSuspisiousAlertMiddleware, logApiRequest, MoveFileRoute);
|
||||||
router.use('/api/dpanel/upload',discordWebhookSuspisiousAlertMiddleware, logApiRequest, UploadRoute);
|
router.use('/api/dpanel/upload', UploadRoute);
|
||||||
router.use('/api/dpanel/dashboard/admin/update-role',discordWebhookSuspisiousAlertMiddleware, logApiRequest, UpdateRoleAdminRoute);
|
router.use('/api/dpanel/dashboard/admin/update-role',discordWebhookSuspisiousAlertMiddleware, logApiRequest, UpdateRoleAdminRoute);
|
||||||
router.use('/api/dpanel/dashboard/admin/update-setup',discordWebhookSuspisiousAlertMiddleware, logApiRequest, UpdateSetupAdminRoute);
|
router.use('/api/dpanel/dashboard/admin/update-setup',discordWebhookSuspisiousAlertMiddleware, logApiRequest, UpdateSetupAdminRoute);
|
||||||
router.use('/api/dpanel/dashboard/deletefolder',discordWebhookSuspisiousAlertMiddleware, logApiRequest, DeleteFolderRoute);
|
router.use('/api/dpanel/dashboard/deletefolder',discordWebhookSuspisiousAlertMiddleware, logApiRequest, DeleteFolderRoute);
|
||||||
|
|||||||
@@ -51,25 +51,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.custom-btn {
|
.custom-btn {
|
||||||
transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
|
display: inline-flex;
|
||||||
color: #007BFF;
|
align-items: center;
|
||||||
background-color: transparent;
|
justify-content: center;
|
||||||
padding: 5px 10px;
|
font-family: inherit;
|
||||||
text-decoration: none;
|
font-weight: 500;
|
||||||
display: inline-block;
|
font-size: 14px; /* réduit la taille de la police */
|
||||||
font-size: 14px;
|
padding: 0.6em 1.2em; /* réduit le padding */
|
||||||
margin: 4px 2px;
|
color: white;
|
||||||
border-radius: 50px;
|
background: linear-gradient(0deg, rgba(77,54,208,1) 0%, rgba(132,116,254,1) 100%);
|
||||||
|
border: none;
|
||||||
|
box-shadow: 0 0.7em 1.5em -0.5em #4d36d0be;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
border-radius: 15em; /* réduit le rayon de la bordure */
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
box-shadow: 0 2px 5px rgba(0,0,0,0.25);
|
transition: all 0.3s ease;
|
||||||
border: 2px solid #007BFF;
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-btn:hover {
|
|
||||||
transform: scale(1.15);
|
|
||||||
background-color: #007BFF;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -12,25 +12,25 @@
|
|||||||
|
|
||||||
<style>
|
<style>
|
||||||
.custom-btn {
|
.custom-btn {
|
||||||
transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
|
display: inline-flex;
|
||||||
color: #007BFF;
|
align-items: center;
|
||||||
background-color: transparent;
|
justify-content: center;
|
||||||
padding: 5px 10px;
|
font-family: inherit;
|
||||||
text-decoration: none;
|
font-weight: 500;
|
||||||
display: inline-block;
|
font-size: 14px; /* réduit la taille de la police */
|
||||||
font-size: 14px;
|
padding: 0.6em 1.2em; /* réduit le padding */
|
||||||
margin: 4px 2px;
|
color: white;
|
||||||
border-radius: 50px;
|
background: linear-gradient(0deg, rgba(77,54,208,1) 0%, rgba(132,116,254,1) 100%);
|
||||||
|
border: none;
|
||||||
|
box-shadow: 0 0.7em 1.5em -0.5em #4d36d0be;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
border-radius: 15em; /* réduit le rayon de la bordure */
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
box-shadow: 0 2px 5px rgba(0,0,0,0.25);
|
transition: all 0.3s ease;
|
||||||
border: 2px solid #007BFF;
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-btn:hover {
|
|
||||||
transform: scale(1.15);
|
|
||||||
background-color: #007BFF;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
input[type="text"] {
|
input[type="text"] {
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
@@ -51,25 +51,25 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.custom-btn {
|
.custom-btn {
|
||||||
transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
|
display: inline-flex;
|
||||||
color: #007BFF;
|
align-items: center;
|
||||||
background-color: transparent;
|
justify-content: center;
|
||||||
padding: 5px 10px;
|
font-family: inherit;
|
||||||
text-decoration: none;
|
font-weight: 500;
|
||||||
display: inline-block;
|
font-size: 14px; /* réduit la taille de la police */
|
||||||
font-size: 14px;
|
padding: 0.6em 1.2em; /* réduit le padding */
|
||||||
margin: 4px 2px;
|
color: white;
|
||||||
border-radius: 50px;
|
background: linear-gradient(0deg, rgba(77,54,208,1) 0%, rgba(132,116,254,1) 100%);
|
||||||
|
border: none;
|
||||||
|
box-shadow: 0 0.7em 1.5em -0.5em #4d36d0be;
|
||||||
|
letter-spacing: 0.05em;
|
||||||
|
border-radius: 15em; /* réduit le rayon de la bordure */
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
box-shadow: 0 2px 5px rgba(0,0,0,0.25);
|
transition: all 0.3s ease;
|
||||||
border: 2px solid #007BFF;
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.custom-btn:hover {
|
|
||||||
transform: scale(1.15);
|
|
||||||
background-color: #007BFF;
|
|
||||||
color: #fff;
|
|
||||||
}
|
|
||||||
|
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -83,6 +83,8 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const originalFileName = file.name;
|
||||||
|
|
||||||
const expiryDate = document.getElementById('expiryDate').value;
|
const expiryDate = document.getElementById('expiryDate').value;
|
||||||
const password = document.getElementById('password').value;
|
const password = document.getElementById('password').value;
|
||||||
const formData = new FormData();
|
const formData = new FormData();
|
||||||
@@ -105,7 +107,7 @@
|
|||||||
Swal.fire({
|
Swal.fire({
|
||||||
position: 'top',
|
position: 'top',
|
||||||
icon: 'success',
|
icon: 'success',
|
||||||
title: 'Votre fichier a été téléchargé avec succès.',
|
title: `Votre fichier ${originalFileName} a été téléchargé avec succès.`,
|
||||||
showConfirmButton: false,
|
showConfirmButton: false,
|
||||||
timer: 1800,
|
timer: 1800,
|
||||||
toast: true,
|
toast: true,
|
||||||
|
|||||||
Reference in New Issue
Block a user