mirror of
https://git.sr.ht/~coasteen/webui
synced 2025-11-04 11:37:34 +01:00
Merge branch 'main' into main
This commit is contained in:
commit
8e133c31fb
2 changed files with 118 additions and 110 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>File Transfer</title>
|
||||
|
|
@ -39,8 +39,8 @@
|
|||
max-height: 400px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Upload Files</h1>
|
||||
<form id="upload-form" action="/upload" method="post" enctype="multipart/form-data">
|
||||
<input type="file" name="files" multiple required>
|
||||
|
|
@ -53,5 +53,5 @@
|
|||
</div>
|
||||
|
||||
<script src="script.js"></script>
|
||||
</body>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -5,6 +5,7 @@ const fs = require('fs');
|
|||
|
||||
const app = express();
|
||||
|
||||
// configure storage for uploaded files
|
||||
const storage = multer.diskStorage({
|
||||
destination: (req, file, cb) => {
|
||||
cb(null, 'uploads/');
|
||||
|
|
@ -17,8 +18,10 @@ const storage = multer.diskStorage({
|
|||
|
||||
const upload = multer({ storage: storage });
|
||||
|
||||
// serve static files
|
||||
app.use(express.static(__dirname));
|
||||
|
||||
// upload files
|
||||
app.post('/upload', upload.array('files'), (req, res) => {
|
||||
if (!req.files || req.files.length === 0) {
|
||||
return res.status(400).send('No files were uploaded.');
|
||||
|
|
@ -26,6 +29,7 @@ app.post('/upload', upload.array('files'), (req, res) => {
|
|||
res.send(`Successfully uploaded ${req.files.length} file(s)!`);
|
||||
});
|
||||
|
||||
// get list of uploaded files
|
||||
app.get('/files', (req, res) => {
|
||||
const directoryPath = path.join(__dirname, 'uploads');
|
||||
fs.readdir(directoryPath, (err, files) => {
|
||||
|
|
@ -55,6 +59,7 @@ app.get('/files', (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
// serve a specific file
|
||||
app.get('/uploads/:filename', (req, res) => {
|
||||
const filePath = path.join(__dirname, 'uploads', req.params.filename);
|
||||
res.sendFile(filePath, err => {
|
||||
|
|
@ -64,6 +69,7 @@ app.get('/uploads/:filename', (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
// download a specific file
|
||||
app.get('/download/:filename', (req, res) => {
|
||||
const filePath = path.join(__dirname, 'uploads', req.params.filename);
|
||||
res.download(filePath, err => {
|
||||
|
|
@ -73,6 +79,7 @@ app.get('/download/:filename', (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
// delete a specific file
|
||||
app.delete('/delete/:filename', (req, res) => {
|
||||
const filePath = path.join(__dirname, 'uploads', req.params.filename);
|
||||
fs.unlink(filePath, err => {
|
||||
|
|
@ -83,6 +90,7 @@ app.delete('/delete/:filename', (req, res) => {
|
|||
});
|
||||
});
|
||||
|
||||
// start the server
|
||||
app.listen(3000, () => {
|
||||
console.log('Server is running on http://localhost:3000');
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue