dl / server.js
scnario's picture
Update server.js
8616b46 verified
Raw History Blame Contribute Delete
3.7 kB
const express = require('express');
const axios = require('express');
const app = express();
//app.use(express.static('public'));
app.get('/', (req, res) => {
res.send(`
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Fast Downloader</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: Arial, sans-serif;
background: #000;
color: #fff;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
background: #111;
padding: 2rem;
border-radius: 10px;
text-align: center;
animation: fadeIn 1s ease-in-out;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(-20px); }
to { opacity: 1; transform: translateY(0); }
}
h1 { margin-bottom: 1rem; font-size: 2rem; color: #fff; }
input {
width: 100%;
padding: 0.75rem;
margin-bottom: 1rem;
border: none;
border-radius: 5px;
background: #222;
color: #fff;
font-size: 1rem;
}
input::placeholder { color: #888; }
button {
width: 100%;
padding: 0.75rem;
border: none;
border-radius: 5px;
background: #fff;
color: #000;
font-size: 1rem;
font-weight: bold;
cursor: pointer;
transition: background 0.3s ease;
}
button:hover { background: #ddd; }
</style>
</head>
<body>
<div class="container">
<h1>Fast Downloader</h1>
<input type="text" id="url" placeholder="Masukkan URL file">
<input type="text" id="filename" placeholder="Masukkan nama file">
<button onclick="downloadFile()">Download</button>
</div>
<script>
function downloadFile() {
const url = document.getElementById('url').value;
const filename = document.getElementById('filename').value;
if (url && filename) {
window.location.href = \`/dl?url=\${encodeURIComponent(url)}&filename=\${encodeURIComponent(filename)}\`;
} else {
alert('Harap isi URL dan nama file!');
}
}
</script>
</body>
</html>
`);
});
app.get('/dl', async (req, res) => {
const { url, filename } = req.query;
if (!url || !filename) return res.status(400).send('Missing url or filename');
try {
const response = await axios({ url, responseType: 'stream' });
res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
response.data.pipe(res);
} catch (error) {
res.status(500).send('Error downloading file');
}
});
app.listen(7860, () => console.log('Server running on port 7860'));