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);
|
||||
}
|
||||
|
||||
#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 {
|
||||
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;
|
||||
display: inline-flex;
|
||||
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;
|
||||
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;
|
||||
box-shadow: 0 2px 5px rgba(0,0,0,0.25);
|
||||
border: 2px solid #007BFF;
|
||||
}
|
||||
|
||||
.custom-btn:hover {
|
||||
transform: scale(1.15);
|
||||
background-color: #007BFF;
|
||||
color: #fff;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.btn-icon {
|
||||
@@ -171,30 +149,48 @@ body.dark-theme .navbar-toggler-icon {
|
||||
|
||||
.custom-dropdown,
|
||||
.animated-button {
|
||||
position: relative;
|
||||
background: #1d2429;
|
||||
display: inline-flex;
|
||||
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;
|
||||
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;
|
||||
padding: 10px 20px;
|
||||
font-size: 1em;
|
||||
color: #17a2b8;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
body.white-theme .custom-dropdown,
|
||||
body.white-theme .animated-button {
|
||||
color: #6c757d;
|
||||
background: #e9ecef;
|
||||
body .custom-dropdown:focus,
|
||||
body .animated-button:focus {
|
||||
color: #ffffff !important; /* Change the text color to white */
|
||||
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,
|
||||
.animated-button:hover {
|
||||
background: #343a40;
|
||||
color: #fff;
|
||||
body.white-theme .custom-dropdown:focus,
|
||||
body.white-theme .animated-button:focus {
|
||||
color: #ffffff !important; /* Change the text color to white */
|
||||
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,
|
||||
body.white-theme .animated-button:hover {
|
||||
background: #343a40;
|
||||
color: #fff;
|
||||
@keyframes rainbowBorder {
|
||||
0% { box-shadow: 0 0 0 3px rgba(255, 0, 0, 0.7); }
|
||||
14% { box-shadow: 0 0 0 3px rgba(255, 127, 0, 0.7); }
|
||||
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,
|
||||
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) {
|
||||
if (req.session.user) {
|
||||
req.user = req.session.user;
|
||||
req.userData = req.session.user;
|
||||
return next();
|
||||
}
|
||||
|
||||
let token = null;
|
||||
const authHeader = req.headers['authorization'];
|
||||
|
||||
@@ -125,6 +131,8 @@ function authenticateToken(req, res, next) {
|
||||
return res.status(401).json({ message: 'Unauthorized: Invalid token' });
|
||||
}
|
||||
|
||||
// Enregistrer l'utilisateur dans la session
|
||||
req.session.user = user;
|
||||
req.user = user;
|
||||
req.userData = user;
|
||||
next();
|
||||
|
||||
@@ -129,9 +129,9 @@ function authenticateToken(req, res, next) {
|
||||
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) {
|
||||
console.error('Error reading user.json:', err);
|
||||
console.error('Error reading user.jso,:', err);
|
||||
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) => {
|
||||
if (err) {
|
||||
console.error('Error reading user.json:', err);
|
||||
console.error('Error reading user.js:', err);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
@@ -145,61 +145,62 @@ router.post('/', authenticateToken, async (req, res) => {
|
||||
const folderName = req.body.folderName;
|
||||
|
||||
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')
|
||||
const users = JSON.parse(data);
|
||||
const user = users.find(user => user.id === req.user.id);
|
||||
|
||||
if (!user) {
|
||||
console.error('User not found in user.json');
|
||||
return res.status(500).send('Error moving the file.');
|
||||
}
|
||||
|
||||
const userId = user.name;
|
||||
|
||||
if (!fileName || !userId) {
|
||||
console.error('fileName or userId is undefined');
|
||||
return res.status(500).send('Error moving the file.');
|
||||
}
|
||||
|
||||
const sourcePath = path.join('cdn-files', userId, fileName);
|
||||
|
||||
let destinationDir;
|
||||
if (folderName && folderName.trim() !== '') {
|
||||
destinationDir = path.join('cdn-files', userId, folderName);
|
||||
} else {
|
||||
destinationDir = path.join('cdn-files', userId);
|
||||
}
|
||||
|
||||
const destinationPath = path.join(destinationDir, fileName);
|
||||
|
||||
try {
|
||||
const data = await fs.promises.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf-8');
|
||||
const users = JSON.parse(data);
|
||||
const user = users.find(user => user.id === req.user.id);
|
||||
|
||||
if (!user) {
|
||||
console.error('User not found in user.json');
|
||||
return res.status(500).json({ error: 'Error moving the file.' });
|
||||
}
|
||||
|
||||
const userId = user.name;
|
||||
|
||||
if (!fileName || !userId) {
|
||||
console.error('fileName or userId is undefined');
|
||||
return res.status(500).json({ error: 'Error moving the file.' });
|
||||
}
|
||||
|
||||
const sourcePath = path.join('cdn-files', userId, fileName);
|
||||
|
||||
let destinationDir;
|
||||
if (folderName && folderName.trim() !== '') {
|
||||
destinationDir = path.join('cdn-files', userId, folderName);
|
||||
} else {
|
||||
destinationDir = path.join('cdn-files', userId);
|
||||
}
|
||||
|
||||
const destinationPath = path.join(destinationDir, fileName);
|
||||
|
||||
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);
|
||||
console.log('Full Source Path:', normalizedSourcePath);
|
||||
|
||||
|
||||
if (fs.existsSync(normalizedSourcePath)) {
|
||||
await fs.promises.access(destinationDir);
|
||||
|
||||
await ncpAsync(normalizedSourcePath, destinationPath);
|
||||
|
||||
await fs.promises.unlink(normalizedSourcePath);
|
||||
} else {
|
||||
console.log('File does not exist');
|
||||
return res.status(404).json({ error: 'File not found.' });
|
||||
}
|
||||
|
||||
res.status(200).json({ message: 'File moved successfully' });
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
return res.status(500).send('Error moving the file.');
|
||||
return res.status(500).json({ error: 'Error moving the file.' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/:folderName', authenticateToken, async (req, res) => {
|
||||
const fileName = req.body.fileName;
|
||||
let newFolderName = req.body.newFolderName;
|
||||
const oldFolderName = req.params.folderName;
|
||||
const oldFolderName = req.params.folderName;
|
||||
const userName = req.body.userName;
|
||||
|
||||
if (newFolderName === 'root') {
|
||||
@@ -208,7 +209,11 @@ router.post('/:folderName', authenticateToken, async (req, res) => {
|
||||
|
||||
if (fileName === undefined || userName === undefined || oldFolderName === undefined || newFolderName === 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);
|
||||
@@ -218,25 +223,23 @@ router.post('/:folderName', authenticateToken, async (req, res) => {
|
||||
|
||||
if (!sourcePath.startsWith(userDir) || !destinationPath.startsWith(userDir)) {
|
||||
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 {
|
||||
const normalizedSourcePath = path.normalize(sourcePath);
|
||||
console.log('Full Source Path:', normalizedSourcePath);
|
||||
|
||||
|
||||
if (fs.existsSync(normalizedSourcePath)) {
|
||||
await fs.promises.access(destinationDir, fs.constants.W_OK);
|
||||
|
||||
await fs.promises.rename(normalizedSourcePath, destinationPath);
|
||||
} 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) {
|
||||
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' });
|
||||
}
|
||||
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.json'), 'utf8', (err, data) => {
|
||||
fs.readFile(path.join(__dirname, '../../../data', 'user.jso,'), 'utf8', (err, data) => {
|
||||
if (err) {
|
||||
console.error('Error reading user.json:', err);
|
||||
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) {
|
||||
console.error('Error reading user.json:', err);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
|
||||
@@ -40,7 +40,7 @@ router.post('/', authMiddleware, async (req, res) => {
|
||||
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');
|
||||
} 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) {
|
||||
console.error('Error reading user.json:', err);
|
||||
console.error('Error reading user.jso,:', err);
|
||||
return res.status(401).json({ message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ const express = require('express');
|
||||
const router = express.Router();
|
||||
const path = require('path');
|
||||
const fs = require('fs').promises;
|
||||
const fsStandard = require('fs');
|
||||
const mime = require('mime-types');
|
||||
const { logger, ErrorLogger } = require('../config/logs');
|
||||
const bcrypt = require('bcrypt');
|
||||
@@ -27,7 +28,12 @@ async function findFileInUserDir(userId, 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) {
|
||||
const filePath = path.join(dir, file.name);
|
||||
@@ -65,15 +71,16 @@ router.get('/:userId/:filename', async (req, res) => {
|
||||
fileInfoArray = JSON.parse(data);
|
||||
} catch (error) {
|
||||
console.error('Error parsing file_info.json:', error);
|
||||
return res.status(500).send('Error reading file info.');
|
||||
}
|
||||
|
||||
if (!Array.isArray(fileInfoArray)) {
|
||||
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);
|
||||
|
||||
|
||||
if (fileInfo) {
|
||||
const expiryDate = new Date(fileInfo.expiryDate);
|
||||
const now = new Date();
|
||||
@@ -88,26 +95,11 @@ router.get('/:userId/:filename', async (req, res) => {
|
||||
}
|
||||
}
|
||||
|
||||
const fileContent = await fs.readFile(filePath);
|
||||
let mimeType = mime.lookup(filePath);
|
||||
const readStream = fsStandard.createReadStream(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);
|
||||
}
|
||||
|
||||
if (mimeType === 'text/plain') {
|
||||
res.end(fileContent);
|
||||
} else {
|
||||
res.send(fileContent);
|
||||
}
|
||||
res.setHeader('Content-Type', mimeType);
|
||||
readStream.pipe(res);
|
||||
|
||||
if (fileInfo) {
|
||||
req.session.passwordVerified = false;
|
||||
@@ -129,11 +121,12 @@ router.post('/:userId/:filename', async (req, res) => {
|
||||
fileInfoArray = JSON.parse(data);
|
||||
} catch (error) {
|
||||
console.error('Error parsing file_info.json:', error);
|
||||
return res.status(500).send('Error reading file info.');
|
||||
}
|
||||
|
||||
if (!Array.isArray(fileInfoArray)) {
|
||||
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);
|
||||
@@ -142,21 +135,21 @@ router.post('/:userId/:filename', async (req, res) => {
|
||||
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;
|
||||
const filePath = await findFileInUserDir(userId, filename);
|
||||
const fileContent = await fs.readFile(filePath);
|
||||
let mimeType = mime.lookup(filePath);
|
||||
const readStream = fsStandard.createReadStream(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';
|
||||
}
|
||||
}
|
||||
let fileContent = '';
|
||||
readStream.on('data', chunk => {
|
||||
fileContent += chunk.toString('base64');
|
||||
});
|
||||
|
||||
res.json({ success: true, fileContent: fileContent.toString('base64'), mimeType });
|
||||
readStream.on('end', () => {
|
||||
res.json({ success: true, fileContent, mimeType });
|
||||
});
|
||||
} else {
|
||||
res.json({ success: false, message: 'Incorrect password' });
|
||||
}
|
||||
@@ -167,24 +160,31 @@ router.post('/:userId/:filename', async (req, res) => {
|
||||
});
|
||||
|
||||
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;
|
||||
try {
|
||||
fileInfoArray = JSON.parse(data);
|
||||
} catch (error) {
|
||||
console.error('Error parsing file_info.json:', error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Array.isArray(fileInfoArray)) {
|
||||
console.error('fileInfoArray is not an array');
|
||||
fileInfoArray = [];
|
||||
return;
|
||||
}
|
||||
|
||||
const now = new Date();
|
||||
let newFileInfoArray = [];
|
||||
|
||||
for (let i = 0; i < fileInfoArray.length; i++) {
|
||||
const fileInfo = fileInfoArray[i];
|
||||
for (const fileInfo of fileInfoArray) {
|
||||
let expiryDate;
|
||||
if (fileInfo.expiryDate && fileInfo.expiryDate.trim() !== '') {
|
||||
expiryDate = new Date(fileInfo.expiryDate);
|
||||
@@ -193,10 +193,10 @@ async function deleteExpiredFiles() {
|
||||
}
|
||||
|
||||
if (expiryDate < now) {
|
||||
const samaccountname = await getSamAccountNameFromUserId(fileInfo.userId);
|
||||
const userDir = path.join(baseDir, samaccountname);
|
||||
const filePath = path.join(userDir, fileInfo.fileName);
|
||||
try {
|
||||
const samaccountname = await getSamAccountNameFromUserId(fileInfo.userId);
|
||||
const userDir = path.join(baseDir, samaccountname);
|
||||
const filePath = path.join(userDir, fileInfo.fileName);
|
||||
await fs.unlink(filePath);
|
||||
} catch (err) {
|
||||
ErrorLogger.error('Error deleting file:', err);
|
||||
@@ -207,7 +207,7 @@ async function deleteExpiredFiles() {
|
||||
}
|
||||
|
||||
try {
|
||||
await fs.writeFile(path.join(__dirname, '../data', 'file_info.json'), JSON.stringify(newFileInfoArray, null, 2), 'utf8');
|
||||
await fs.writeFile(path.join(__dirname, '../data', 'file_info.json'), JSON.stringify(newFileInfoArray, null, 2), 'utf8');
|
||||
} catch (err) {
|
||||
ErrorLogger.error('Error writing to file_info.json:', err);
|
||||
}
|
||||
@@ -215,4 +215,4 @@ async function deleteExpiredFiles() {
|
||||
|
||||
setInterval(deleteExpiredFiles, 24 * 60 * 60 * 1000);
|
||||
|
||||
module.exports = router;
|
||||
module.exports = router;
|
||||
|
||||
@@ -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/delete',discordWebhookSuspisiousAlertMiddleware, logApiRequest, DeleteFileRoute);
|
||||
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-setup',discordWebhookSuspisiousAlertMiddleware, logApiRequest, UpdateSetupAdminRoute);
|
||||
router.use('/api/dpanel/dashboard/deletefolder',discordWebhookSuspisiousAlertMiddleware, logApiRequest, DeleteFolderRoute);
|
||||
|
||||
@@ -48,28 +48,28 @@
|
||||
color: #000;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.custom-btn {
|
||||
transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
|
||||
color: #007BFF;
|
||||
background-color: transparent;
|
||||
padding: 5px 10px;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
.custom-btn {
|
||||
display: inline-flex;
|
||||
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;
|
||||
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;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.custom-btn:hover {
|
||||
transform: scale(1.15);
|
||||
background-color: #007BFF;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -11,26 +11,26 @@
|
||||
<link rel="icon" href="/public/assets/homelab_logo.png" />
|
||||
|
||||
<style>
|
||||
.custom-btn {
|
||||
transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
|
||||
color: #007BFF;
|
||||
background-color: transparent;
|
||||
padding: 5px 10px;
|
||||
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;
|
||||
}
|
||||
.custom-btn {
|
||||
display: inline-flex;
|
||||
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;
|
||||
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;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.custom-btn:hover {
|
||||
transform: scale(1.15);
|
||||
background-color: #007BFF;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
input[type="text"] {
|
||||
width: 100%;
|
||||
|
||||
@@ -48,28 +48,28 @@
|
||||
color: #000;
|
||||
text-decoration: none;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.custom-btn {
|
||||
transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
|
||||
color: #007BFF;
|
||||
background-color: transparent;
|
||||
padding: 5px 10px;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
.custom-btn {
|
||||
display: inline-flex;
|
||||
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;
|
||||
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;
|
||||
transition: all 0.3s ease;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.custom-btn:hover {
|
||||
transform: scale(1.15);
|
||||
background-color: #007BFF;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
</style>
|
||||
</head>
|
||||
|
||||
@@ -83,6 +83,8 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const originalFileName = file.name;
|
||||
|
||||
const expiryDate = document.getElementById('expiryDate').value;
|
||||
const password = document.getElementById('password').value;
|
||||
const formData = new FormData();
|
||||
@@ -105,7 +107,7 @@
|
||||
Swal.fire({
|
||||
position: 'top',
|
||||
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,
|
||||
timer: 1800,
|
||||
toast: true,
|
||||
|
||||
Reference in New Issue
Block a user