Add new dependencies and update file paths
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-04-17 01:42:24 +02:00
parent 9a5b4c20cb
commit 7a02f2682c
10 changed files with 190 additions and 127 deletions

View File

@@ -5,15 +5,4 @@ services:
restart: unless-stopped restart: unless-stopped
container_name: cdn-app-container container_name: cdn-app-container
ports: ports:
- "5053:5053" - "5053:5053"
volumes:
- /home/cdn-app:/home/cdn-app
- cdn-files:/home/cdn-app/cdn-files
- report:/home/cdn-app/report
- data:/home/cdn-app/data
command: sh -c "if [ ! -f /home/cdn-app/moved_files ]; then mv /app/cdn-app-insider/* /home/cdn-app && touch /home/cdn-app/moved_files; fi && node server.js"
volumes:
cdn-files:
report:
data:

View File

@@ -3,7 +3,7 @@ const path = require('path');
const { logger, ErrorLogger, logRequestInfo } = require('../config/logs'); const { logger, ErrorLogger, logRequestInfo } = require('../config/logs');
const dataFolderPath = path.join(__dirname, '../data'); const dataFolderPath = path.join(__dirname, '../data');
const filesToCreate = ['setup.json', 'user.json', 'file_info.json']; const filesToCreate = ['setup.json', 'user.json', 'file_info.json', 'banData.json'];
filesToCreate.forEach((fileName) => { filesToCreate.forEach((fileName) => {
const filePath = path.join(dataFolderPath, fileName); const filePath = path.join(dataFolderPath, fileName);

34
package-lock.json generated
View File

@@ -29,6 +29,7 @@
"express-session": "^1.17.3", "express-session": "^1.17.3",
"fs": "^0.0.1-security", "fs": "^0.0.1-security",
"fs-extra": "^11.2.0", "fs-extra": "^11.2.0",
"get-folder-size": "^4.0.0",
"ip": "^2.0.1", "ip": "^2.0.1",
"mime-types": "^2.1.35", "mime-types": "^2.1.35",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",
@@ -1926,6 +1927,12 @@
"url": "https://github.com/sponsors/ljharb" "url": "https://github.com/sponsors/ljharb"
} }
}, },
"node_modules/gar": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/gar/-/gar-1.0.4.tgz",
"integrity": "sha512-w4n9cPWyP7aHxKxYHFQMegj7WIAsL/YX/C4Bs5Rr8s1H9M1rNtRWRsw+ovYMkXDQ5S4ZbYHsHAPmevPjPgw44w==",
"deprecated": "Package no longer supported. Contact Support at https://www.npmjs.com/support for more info."
},
"node_modules/gauge": { "node_modules/gauge": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz",
@@ -1953,6 +1960,20 @@
"is-property": "^1.0.2" "is-property": "^1.0.2"
} }
}, },
"node_modules/get-folder-size": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/get-folder-size/-/get-folder-size-4.0.0.tgz",
"integrity": "sha512-Z6sv92povPRhGTNv1j8pMOzkXCcJOYWFTSrulKzoF9qbIRHXtR2Vfjw964jsWVMrIKnwHzm/0jl8IFONbBbEKw==",
"dependencies": {
"gar": "^1.0.4"
},
"bin": {
"get-folder-size": "bin/get-folder-size.js"
},
"engines": {
"node": ">=14.13.0"
}
},
"node_modules/get-intrinsic": { "node_modules/get-intrinsic": {
"version": "1.2.4", "version": "1.2.4",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz",
@@ -6416,6 +6437,11 @@
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz",
"integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==" "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA=="
}, },
"gar": {
"version": "1.0.4",
"resolved": "https://registry.npmjs.org/gar/-/gar-1.0.4.tgz",
"integrity": "sha512-w4n9cPWyP7aHxKxYHFQMegj7WIAsL/YX/C4Bs5Rr8s1H9M1rNtRWRsw+ovYMkXDQ5S4ZbYHsHAPmevPjPgw44w=="
},
"gauge": { "gauge": {
"version": "3.0.2", "version": "3.0.2",
"resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz",
@@ -6440,6 +6466,14 @@
"is-property": "^1.0.2" "is-property": "^1.0.2"
} }
}, },
"get-folder-size": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/get-folder-size/-/get-folder-size-4.0.0.tgz",
"integrity": "sha512-Z6sv92povPRhGTNv1j8pMOzkXCcJOYWFTSrulKzoF9qbIRHXtR2Vfjw964jsWVMrIKnwHzm/0jl8IFONbBbEKw==",
"requires": {
"gar": "^1.0.4"
}
},
"get-intrinsic": { "get-intrinsic": {
"version": "1.2.4", "version": "1.2.4",
"resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz",

View File

@@ -30,6 +30,7 @@
"express-session": "^1.17.3", "express-session": "^1.17.3",
"fs": "^0.0.1-security", "fs": "^0.0.1-security",
"fs-extra": "^11.2.0", "fs-extra": "^11.2.0",
"get-folder-size": "^4.0.0",
"ip": "^2.0.1", "ip": "^2.0.1",
"mime-types": "^2.1.35", "mime-types": "^2.1.35",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",

View File

@@ -166,4 +166,5 @@ body.dark-theme .navbar-toggler-icon {
.btn-icon { .btn-icon {
border-radius: 50%; border-radius: 50%;
padding: 0.5em; padding: 0.5em;
} }

View File

@@ -470,12 +470,14 @@ async function getUserIdFromFolder(username) {
async function showFileInfo(fileLink) { async function showFileInfo(fileLink) {
let data; let data;
try { try {
let response = await fetch(`/file_info.json`); let response = await fetch('/data/file_info.json');
if (!response.ok) { if (!response.ok) {
throw new Error('Network response was not ok'); throw new Error(`HTTP error! status: ${response.status}`);
} }
data = await response.json(); let fileContent = await response.text();
data = JSON.parse(fileContent);
} catch (error) { } catch (error) {
console.log(error);
Swal.fire({ Swal.fire({
position: 'top', position: 'top',
icon: 'error', icon: 'error',
@@ -487,9 +489,8 @@ async function showFileInfo(fileLink) {
return; return;
} }
let fileName = fileLink.split('/').pop();
let pathParts = fileLink.split('/'); let pathParts = fileLink.split('/');
if (pathParts.length < 2) { if (pathParts.length < 4) {
Swal.fire({ Swal.fire({
position: 'top', position: 'top',
icon: 'error', icon: 'error',
@@ -500,18 +501,16 @@ async function showFileInfo(fileLink) {
}); });
return; return;
} }
let username = pathParts[1].replace('.', ''); let fileName = pathParts.pop();
console.log('Extracted username:', username); let userId = pathParts.pop();
let userId = await getUserIdFromFolder(username);
console.log('Obtained userId:', userId);
let fileInfo = data.find(file => file.fileName === fileName && file.Id === userId); let fileInfo = data.find(file => file.fileName === fileName && file.Id === userId);
console.log('Found fileInfo:', fileInfo);
if (!fileInfo) { if (!fileInfo) {
Swal.fire({ Swal.fire({
position: 'top', position: 'top',
icon: 'error', icon: 'error',
title: `Aucune information trouvée pour le fichier ${fileName} pour l'utilisateur ${username}.`, title: `Aucune information trouvée pour le fichier ${fileName} pour l'utilisateur avec l'ID ${userId}.`,
showConfirmButton: false, showConfirmButton: false,
timer: 1800, timer: 1800,
toast: true, toast: true,
@@ -534,3 +533,32 @@ async function showFileInfo(fileLink) {
confirmButtonText: 'Fermer' confirmButtonText: 'Fermer'
}); });
} }
async function displayMetadata() {
const response = await fetch('/build-metadata');
if (!response.ok) {
console.error('Failed to fetch metadata');
return;
}
const metadata = await response.json();
if (!metadata) {
console.error('No metadata provided');
return;
}
document.getElementById('buildVersion').textContent = metadata.build_version;
document.getElementById('nodeVersion').textContent = metadata.node_version;
document.getElementById('expressVersion').textContent = metadata.express_version;
document.getElementById('buildSha').textContent = metadata.build_sha;
document.getElementById('osType').textContent = metadata.os_type;
document.getElementById('osRelease').textContent = metadata.os_release;
const modal = document.getElementById('metadataModal');
modal.style.display = 'block';
}
function closeModal() {
const modal = document.getElementById('metadataModal');
modal.style.display = 'none';
}

67
routes/BuildMetaData.js Normal file
View File

@@ -0,0 +1,67 @@
const express = require('express');
const router = express.Router();
const os = require('os');
const child_process = require('child_process');
const packageJson = require('../package.json');
const fs = require('fs');
const path = require('path');
function getAllFiles(dirPath, arrayOfFiles) {
const files = fs.readdirSync(dirPath);
arrayOfFiles = arrayOfFiles || [];
files.forEach(function(file) {
if (fs.statSync(dirPath + "/" + file).isDirectory()) {
arrayOfFiles = getAllFiles(dirPath + "/" + file, arrayOfFiles);
} else {
arrayOfFiles.push(path.join(dirPath, "/", file));
}
});
return arrayOfFiles;
}
function bytesToSize(bytes) {
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return '0 Byte';
const i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
}
function calculateBuildSize(files) {
let totalSize = 0;
files.forEach(file => {
const stats = fs.statSync(file);
totalSize += stats.size;
});
return totalSize;
}
router.get('/', async (req, res) => {
try {
const clientIp = req.headers['cf-connecting-ip'] || req.ip;
const version = packageJson.version;
const expressVersion = require('express/package.json').version;
const buildMetadata = {
build_version: version,
node_version: process.version,
express_version: expressVersion,
build_sha: child_process.execSync('git rev-parse HEAD').toString().trim(),
os_type: os.type(),
os_release: os.release(),
};
res.json(buildMetadata);
} catch (error) {
console.error('Error in /build-metadata: ', error);
res.status(500).send('Error in /build-metadata: ' + error.toString());
}
});
module.exports = router;

View File

@@ -1,12 +1,12 @@
const express = require('express'); const express = require('express');
const router = express.Router(); const router = express.Router();
const path = require('path');
const indexRoute = require('./index.js'); const indexRoute = require('./index.js');
const DpanelDashboardRoute = require('./Dpanel/Dashboard/index.js'); const DpanelDashboardRoute = require('./Dpanel/Dashboard/index.js');
const DpanelFolderRoute = require('./Dpanel/Folder/index.js'); const DpanelFolderRoute = require('./Dpanel/Folder/index.js');
const DpanelUploadRoute = require('./Dpanel/Upload.js'); const DpanelUploadRoute = require('./Dpanel/Upload.js');
const AttachmentsRoute = require('./attachments.js'); const AttachmentsRoute = require('./attachments.js');
const buildMetadataRoute = require('./BuildMetaData.js');
const NewFolderRoute = require('./Dpanel/API/NewFolder.js'); const NewFolderRoute = require('./Dpanel/API/NewFolder.js');
const RenameFileRoute = require('./Dpanel/API/RenameFile.js'); const RenameFileRoute = require('./Dpanel/API/RenameFile.js');
@@ -31,6 +31,7 @@ const AdminPrivacySecurityDpanelRoute = require('./Dpanel/Admin/Privacy-Security
router.use('/', indexRoute); router.use('/', indexRoute);
router.use('/attachments', AttachmentsRoute); router.use('/attachments', AttachmentsRoute);
router.use('/build-metadata', buildMetadataRoute);
router.use('/dpanel/dashboard', DpanelDashboardRoute); router.use('/dpanel/dashboard', DpanelDashboardRoute);
router.use('/dpanel/upload', DpanelUploadRoute); router.use('/dpanel/upload', DpanelUploadRoute);
@@ -56,4 +57,6 @@ router.use('/auth/logout', logoutRoute);
router.use('/auth/activedirectory', activeDirectoryRoute); router.use('/auth/activedirectory', activeDirectoryRoute);
router.use('/auth/discord', discordRoute); router.use('/auth/discord', discordRoute);
router.use('/*', indexRoute)
module.exports = router; module.exports = router;

View File

@@ -1,92 +1,14 @@
<!DOCTYPE html> <html>
<html lang="en"> <head>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" href="/public/assets/homelab_logo.png"/> <link rel="icon" href="/public/assets/homelab_logo.png"/>
<title>Temporary Network Error</title> <title>401 Authorization Required</title>
<style>
body {
background-color: #313338;
color: #ffffff;
font-family: Arial, sans-serif;
text-align: center;
margin: 0;
padding: 0;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
height: 100vh;
}
.logo {
width : 150px;
height : 150px;
}
.error-message {
font-size: 24px;
margin-top: 50px;
}
.request-id {
font-size: 18px;
color: #ffffff;
margin-top: 45px;
}
.promotion {
margin-top: 30px;
font-size: 18px;
color: #ffffff;
}
.custom-btn {
transition: transform 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
color: #007BFF;
background-color: transparent;
padding: 10px 20px;
text-decoration: none;
display: inline-block;
font-size: 16px;
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:hover {
transform: scale(1.15);
background-color: #007BFF;
color: #fff;
}
</style>
</head> </head>
<body> <body>
<img class="logo" id="logo" src="../public/assets/homelab_logo.png"> <center><h1>401 Authorization Required</h1></center>
<div class="error-message"> <center id="request-id"></center>
Temporary Network Error<br> <hr>
You do not have permission to access the requested resource, or there is an error. Please try again later. <center>
</div> <a href="https://discord.gg/k6r96Tmtgx" target="_blank">SwiftLogic Labs</a>
<div class="request-id"> </center>
Request ID: <span id="request-id"></span>
</div>
<script>
document.getElementById('request-id').textContent = Math.random().toString(16).slice(2);
</script>
<br><a class="custom-btn" href="#" target="_blank">Check out the Uptime Page</a>
<div class="promotion">
<p>The modern CDN for secure file transfer</p>
<p>Power your project with our self-hosted CDN</p>
<p>Experience exceptional performance and ultra-fast content distribution.</p><br>
<a class="custom-btn" href="https://cdn-app.dinawo.fr" target="_blank">Learn more about our CDN</a><br>
<p>Created by SwiftLogic Labs.</p>
<a class="custom-btn" href="https://discord.gg/k6r96Tmtgx" target="_blank">Join our Discord Server</a>
</div>
</body> </body>
</html> </html>

View File

@@ -90,11 +90,12 @@
<tbody> <tbody>
<% files.forEach(file => { %> <% files.forEach(file => { %>
<tr data-extension="<%= file.extension %>" data-type="<%= file.type %>"> <tr data-extension="<%= file.extension %>" data-type="<%= file.type %>">
<% if (fileInfoNames.includes(file.name)) { %> <% if (fileInfoNames.includes(file.name) || file.name === 'mm4alktpmei71.jpg') { %>
<td><a href="#" onclick="showFileInfo('<%= file.name %>')"><%= file.name %></a></td> <td><a href="#" onclick="showFileInfo('<%= file.name %>')"><%= file.name %></a></td>
<% } else { %> <% } else { %>
<td><%= file.name %></td> <td><%= file.name %></td>
<% } %> <td> <% } %>
<td>
<% if (file.type === 'folder') { %> <% if (file.type === 'folder') { %>
Dossier Dossier
<% } else { %> <% } else { %>
@@ -171,7 +172,7 @@
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div class="patch-note-item pl-3"> <div class="patch-note-item pl-3">
<p><i class="fas fa-tools"></i> Améliorations :</p> <p><i class="fas fa-tools"></i> Améliorations :</p>
<ul> <ul>
@@ -199,10 +200,37 @@
<div class="patch-note-item pl-3"> <div class="patch-note-item pl-3">
<p>Remarque : Nous apprécions vos retours d'expérience et vos rapports de bogues pour continuer à améliorer notre plateforme. Merci pour votre soutien continu !</p> <p>Remarque : Nous apprécions vos retours d'expérience et vos rapports de bogues pour continuer à améliorer notre plateforme. Merci pour votre soutien continu !</p>
</div> </div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fermer</button>
<button type="button" class="btn btn-primary" onclick="displayMetadata()">Afficher les métadonnées</button>
</div>
</div>
</div>
</div>
<div id="metadataModal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Metadata</h5>
<button type="button" class="close" data-dismiss="modal" onclick="closeModal()" aria-label="Fermer">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<p><i class="fas fa-code-branch"></i> Version de Build: <span id="buildVersion"></span></p>
<p><i class="fab fa-node"></i> Version de Node.js: <span id="nodeVersion"></span></p>
<p><i class="fas fa-server"></i> Version de Express.js: <span id="expressVersion"></span></p>
<p><i class="fas fa-hashtag"></i> SHA de Build: <span id="buildSha"></span></p>
<p><i class="fas fa-windows"></i> Type d'OS: <span id="osType"></span></p>
<p><i class="fas fa-laptop-code"></i> Version d'OS: <span id="osRelease"></span></p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-block" data-dismiss="modal" onclick="closeModal()">OK</button>
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="container"> <div class="container">
<footer class="py-3 my-4"> <footer class="py-3 my-4">
@@ -216,16 +244,6 @@
<div class="d-flex justify-content-center align-items-center"> <div class="d-flex justify-content-center align-items-center">
<p class="text-center text-muted mb-0">&copy; 2024 SwiftLogic Labs</p> <p class="text-center text-muted mb-0">&copy; 2024 SwiftLogic Labs</p>
<div class="ml-3"> <div class="ml-3">
<% if (user.role === 'admin') { %>
<button id="checkUpdateButton" class="btn btn-icon btn-info btn-round" title="Vérifier les mises à jour" onclick="checkUpdates()">
<div class="d-flex align-items-center">
<svg xmlns="http://www.w3.org/2000/svg" height="16" width="16" viewBox="0 0 512 512">
<path d="M370.7 133.3C339.5 104 298.9 88 255.8 88c-77.5 .1-144.3 53.2-162.8 126.9-1.3 5.4-6.1 9.2-11.7 9.2H24.1c-7.5 0-13.2-6.8-11.8-14.2C33.9 94.9 134.8 8 256 8c66.4 0 126.8 26.1 171.3 68.7L463 41C478.1 25.9 504 36.6 504 57.9V192c0 13.3-10.7 24-24 24H345.9c-21.4 0-32.1-25.9-17-41l41.8-41.7zM32 296h134.1c21.4 0 32.1 25.9 17 41l-41.8 41.8c31.3 29.3 71.8 45.3 114.9 45.3 77.4-.1 144.3-53.1 162.8-126.8 1.3-5.4 6.1-9.2 11.7-9.2h57.3c7.5 0 13.2 6.8 11.8 14.2C478.1 417.1 377.2 504 256 504c-66.4 0-126.8-26.1-171.3-68.7L49 471C33.9 486.1 8 475.4 8 454.1V320c0-13.3 10.7-24 24-24z"/>
</svg>
<span class="ml-2 d-none">Vérifier les mises à jours</span>
</div>
</button>
<% } %>
</div> </div>
</div> </div>
</footer> </footer>