Update DockerCompose.template, Dockerfile, Upload.js, and upload.ejs files
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2024-04-14 15:57:58 +02:00
parent 4e2e085a63
commit 1006dcb1f5
5 changed files with 65 additions and 32 deletions

View File

@@ -1,13 +0,0 @@
version: '3'
services:
app:
image: swiftlogiclabs/cdn-app-insider:latest
ports:
- "5053:5053"
volumes:
- app-data:/app/cdn-app-insider/cdn-files
- app-data:/app/cdn-app-insider/report
- app-data:/app/cdn-app-insider/data
volumes:
app-data:

View File

@@ -1,6 +1,6 @@
FROM node:14
WORKDIR /app/cdn-app-insider
WORKDIR /home/cdn-app
COPY package*.json ./

19
docker-compose.yml Normal file
View File

@@ -0,0 +1,19 @@
version: '3.8'
services:
cdn-app-insider:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
container_name: cdn-app-container
ports:
- "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
volumes:
cdn-files:
report:
data:

View File

@@ -84,7 +84,7 @@ router.post('/', authMiddleware, async (req, res) => {
await fs.promises.writeFile(path.join(__dirname, '../../../data', 'file_info.json'), JSON.stringify(data, null, 2));
}
res.redirect('/dpanel/dashboard');
res.status(200).send({ message: 'Votre fichier a été téléchargé avec succès.' });
});
} catch (error) {
console.error(error);

View File

@@ -9,6 +9,7 @@
<link rel="stylesheet" href="/public/css/styles.css">
<title>Upload</title>
<link rel="icon" href="/public/assets/homelab_logo.png" />
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@10"></script>
</head>
<body class="light-mode">
@@ -65,19 +66,32 @@
});
uploadForm.addEventListener('submit', (event) => {
event.preventDefault();
event.preventDefault();
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
const expiryDate = document.getElementById('expiryDate').value;
const password = document.getElementById('password').value;
const formData = new FormData();
formData.append('file', file);
formData.append('expiryDate', expiryDate);
formData.append('password', password);
const fileInput = document.getElementById('fileInput');
const file = fileInput.files[0];
const xhr = new XMLHttpRequest();
xhr.open('POST', '/api/dpanel/upload', true);
if (!file) {
Swal.fire({
position: 'top',
icon: 'error',
title: 'Veuillez sélectionner \nun fichier avant de soumettre.',
showConfirmButton: false,
timer: 1800,
toast: true,
});
return;
}
const expiryDate = document.getElementById('expiryDate').value;
const password = document.getElementById('password').value;
const formData = new FormData();
formData.append('file', file);
formData.append('expiryDate', expiryDate);
formData.append('password', password);
const xhr = new XMLHttpRequest();
xhr.open('POST', '/api/dpanel/upload', true);
xhr.upload.onprogress = (event) => {
if (event.lengthComputable) {
@@ -88,11 +102,24 @@
};
xhr.onload = () => {
if (xhr.status === 200) {
const response = JSON.parse(xhr.responseText);
const fileLink = response.fileLink;
window.location.href = '/dpanel/upload-success';
Swal.fire({
position: 'top',
icon: 'success',
title: 'Votre fichier a été téléchargé avec succès.',
showConfirmButton: false,
timer: 1800,
toast: true,
});
} else {
console.error('Erreur lors du téléchargement du fichier.', xhr.status);
Swal.fire({
position: 'top',
icon: 'error',
title: 'Erreur lors du téléchargement du fichier.',
showConfirmButton: false,
timer: 1800,
toast: true,
});
console.error('Erreur lors du téléchargement du fichier.', xhr.status, xhr.responseText);
}
};