added file sizes, download/delete icons, different package scripts and more
This commit is contained in:
parent
1c85658ccd
commit
c9425a130a
@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "updown",
|
"name": "updown",
|
||||||
"version": "0.1.0",
|
"version": "0.2.0",
|
||||||
"description": "a simple file uploader/downloader",
|
"description": "a simple file uploader/downloader",
|
||||||
"main": "updown.js",
|
"main": "updown.js",
|
||||||
"scripts": {
|
"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/",
|
"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",
|
"author": "eclipse729",
|
||||||
"license": "GPL-3.0",
|
"license": "GPL-3.0",
|
||||||
|
|||||||
34
updown.js
34
updown.js
@ -1,18 +1,36 @@
|
|||||||
const express = require('express')
|
const express = require('express');
|
||||||
const app = express()
|
const app = express();
|
||||||
const port = 3000
|
const port = 3000;
|
||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
|
const staticPath = "public/";
|
||||||
|
|
||||||
app.set("view engine", "pug");
|
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) => {
|
app.get('/', (req, res) => {
|
||||||
|
console.log(req.query);
|
||||||
res.render("updown", {
|
res.render("updown", {
|
||||||
message: "hello world",
|
message: "method: get",
|
||||||
files: fs.readdirSync("public/")
|
files: getFilesAndSizes(staticPath)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
app.listen(port, () => {
|
app.post("/", (req, res) => {
|
||||||
console.log(`Example app listening on port ${port}`)
|
res.render("updown", {
|
||||||
|
message: "method: post",
|
||||||
|
files: getFilesAndSizes(staticPath)
|
||||||
|
});
|
||||||
|
})
|
||||||
|
|
||||||
|
app.listen(port, () => {
|
||||||
|
console.log(`updown listening on port ${port}`)
|
||||||
})
|
})
|
||||||
|
|||||||
@ -3,15 +3,22 @@ html
|
|||||||
head(lang="en")
|
head(lang="en")
|
||||||
title Updown
|
title Updown
|
||||||
body
|
body
|
||||||
table
|
div(align='center')
|
||||||
form(method='post', action='')
|
p= message
|
||||||
|
table(align='center')
|
||||||
|
form(method='get', action='')
|
||||||
tr
|
tr
|
||||||
th
|
th
|
||||||
a(href='?sort=name') Uploaded File(s)
|
a(href='?sort=name') Uploaded File(s)
|
||||||
th
|
th
|
||||||
a(href='?sort=size') Size
|
a(href='?sort=size') Size
|
||||||
th
|
th
|
||||||
input(type='checkbox' onclick='toggleAll(this)')
|
th
|
||||||
each file in files
|
each file in files
|
||||||
tr
|
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") 🞬
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user