From 4857119778d7c69ae62daf35f715b156c12e05ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E9=91=AB?= <7176466@qq.com> Date: Fri, 26 Aug 2022 13:50:57 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BB=BA=E6=A0=B7=E5=BC=8F=E8=A1=A8?= =?UTF-8?q?=E3=80=81=E5=AE=A2=E6=88=B7=E7=AB=AF=E8=84=9A=E6=9C=AC=E3=80=81?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E8=A1=A8=E5=8D=95=E5=8F=8Aupload=E8=B7=AF?= =?UTF-8?q?=E7=94=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/client.js | 1 + public/style.css | 27 +++++++++++++++++++++++++++ server.js | 16 +++++++++++++--- views/index.pug | 21 ++++++++++++++++----- 4 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 public/client.js create mode 100644 public/style.css diff --git a/public/client.js b/public/client.js new file mode 100644 index 0000000..dd839a1 --- /dev/null +++ b/public/client.js @@ -0,0 +1 @@ +file_input.value = null diff --git a/public/style.css b/public/style.css new file mode 100644 index 0000000..6ca03af --- /dev/null +++ b/public/style.css @@ -0,0 +1,27 @@ +* { + margin: 0px; + padding: 0px; + box-sizing: border-box; +} + +body { + user-select: none; + max-width: 360px; + margin: 0 auto; +} + +h1, +form { + margin: 1rem auto; +} + +form { + display: grid; + grid-template-columns: auto 1fr; + gap: 1rem; +} + +form button { + grid-column: span 2; + cursor: pointer; +} diff --git a/server.js b/server.js index 8a4e483..d55b639 100644 --- a/server.js +++ b/server.js @@ -9,11 +9,21 @@ mongoose.connect(MONGODB_URL, (error) => { } }) const app = express() -app.use(express.static('public')) app.set('view engine', 'pug') -app.get('/', async (req, res) => { - res.render('index', { title: '文件分享服务器' }) +app.use(express.static('public')) +app.use(express.urlencoded({ extended: true })) +app.use(express.json()) +app.get('/', (req, res) => { + res.render('index') +}) +app.post('/upload', (req, res) => { + res.sendStatus(201) }) const server = app.listen(SERVER_PORT, SERVER_HOST, () => { console.info(`server is running at http://${SERVER_HOST}:${SERVER_PORT}`) }) +/** + * "bcrypt": "^5.0.1", + "md5-file": "^5.0.0", + "multer": "^1.4.5-lts.1", + */ diff --git a/views/index.pug b/views/index.pug index 8ed79c9..713c703 100644 --- a/views/index.pug +++ b/views/index.pug @@ -1,9 +1,20 @@ doctype html html(lang='zh') head - meta(charset="UTF-8") - meta(http-equiv="X-UA-Compatible" content="IE=edge") - meta(name="viewport" content="width=device-width, initial-scale=1.0") - title #{title} + meta(charset='UTF-8') + meta(http-equiv='X-UA-Compatible' content='IE=edge') + meta(name='viewport' content='width=device-width, initial-scale=1.0') + link(rel='icon' href='/favicon.ico' type='image/x-icon') + link(rel='stylesheet' href='/style.css') + title 文件分享服务器 body - h1 #{title} + h1 文件分享服务器 + if uploaded + p= uploaded + form(method='POST' action='/upload' enctype='multipart/form-data') + label(for='file_input') 文件 + input(id='file_input' name='file' type='file' required) + label(for='password_input') 密码 + input(id='password_input' name='password' type='password' autocomplete='off') + button(id='share_button' type='submit') 分享 + script(src='/client.js')