added file sizes, download/delete icons, different package scripts and more

This commit is contained in:
eclipse 2023-10-06 23:27:23 +02:00
parent 1c85658ccd
commit c9425a130a
3 changed files with 41 additions and 15 deletions

View File

@ -1,12 +1,13 @@
{
"name": "updown",
"version": "0.1.0",
"version": "0.2.0",
"description": "a simple file uploader/downloader",
"main": "updown.js",
"scripts": {
"start": "npx parcel serve updown.js --public-url / --dist-dir dist",
"start": "NODE_ENV=dev node updown.js",
"clean": "rm -rf dist/ && rm -rf .parcel-cache/",
"build": "npx parcel build --no-optimize --public-url ./ --dist-dir dist"
"build": "parcel build --no-optimize --dist-dir dist updown.js",
"watch": "parcel watch"
},
"author": "eclipse729",
"license": "GPL-3.0",

View File

@ -1,18 +1,36 @@
const express = require('express')
const app = express()
const port = 3000
const express = require('express');
const app = express();
const port = 3000;
const fs = require('fs');
const staticPath = "public/";
app.set("view engine", "pug");
function getFilesAndSizes(path) {
var filenames = fs.readdirSync(path);
var files = [];
filenames.forEach(filename => {
files.push({ name: filename, size: fs.statSync(path + filename, (e, s) => s).size });
})
console.log(files);
return files;
}
app.get('/', (req, res) => {
console.log(req.query);
res.render("updown", {
message: "hello world",
files: fs.readdirSync("public/")
message: "method: get",
files: getFilesAndSizes(staticPath)
})
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
app.post("/", (req, res) => {
res.render("updown", {
message: "method: post",
files: getFilesAndSizes(staticPath)
});
})
app.listen(port, () => {
console.log(`updown listening on port ${port}`)
})

View File

@ -3,15 +3,22 @@ html
head(lang="en")
title Updown
body
table
form(method='post', action='')
div(align='center')
p= message
table(align='center')
form(method='get', action='')
tr
th
a(href='?sort=name') Uploaded File(s)
th
a(href='?sort=size') Size
th
input(type='checkbox' onclick='toggleAll(this)')
th
each file in files
tr
td= file
td= file.name
td= file.size
td
a(href='?download='+file.name alt="download") 🠳
td
a(href='?delete='+file.name alt="delete") 🞬