change messages to lowercase to fit my style

This commit is contained in:
hippoz 2020-10-07 18:00:32 +03:00
parent 0bacce5fcd
commit 233e2f3e22
4 changed files with 15 additions and 15 deletions

View file

@ -85,13 +85,13 @@ app.get('/file/:filename', (req, res) => {
const isValid = isPathValid(filename, filePath); const isValid = isPathValid(filename, filePath);
if (!isValid) { if (!isValid) {
res.status(400).send('Invalid input.'); res.status(400).send('invalid input.');
return; return;
} }
fs.access(filePath, fs.F_OK, (err) => { fs.access(filePath, fs.F_OK, (err) => {
if (err) { if (err) {
res.status(404).send('File not found or is invalid.'); res.status(404).send('file not found or is invalid.');
return; return;
} }
@ -114,44 +114,44 @@ app.post('/api/upload', [ cors(corsOptions) ], (req, res) => {
const chosenFileName = req.body.filename; const chosenFileName = req.body.filename;
if (config.passwords.indexOf(password) === -1) { if (config.passwords.indexOf(password) === -1) {
return res.status(401).render('uploadfailed', { message: 'The password you entered is not correct.' }); return res.status(401).render('uploadfailed', { message: 'the password you entered is not correct.' });
} }
if (!req.files || Object.keys(req.files).length === 0) { if (!req.files || Object.keys(req.files).length === 0) {
return res.status(400).render('uploadfailed', { message: 'You forgot to upload a file.' }); return res.status(400).render('uploadfailed', { message: 'you forgot to upload a file.' });
} }
const file = req.files.file; const file = req.files.file;
if (!isFilenameValid(chosenFileName)) { if (!isFilenameValid(chosenFileName)) {
return res.status(400).render('uploadfailed', { message: 'Invalid name.' }); return res.status(400).render('uploadfailed', { message: 'invalid name.' });
} }
const filepath = path.join(config.storagePath, chosenFileName); const filepath = path.join(config.storagePath, chosenFileName);
if (!isFilenameValid(file.name) || !isPathValid(chosenFileName, filepath)) { if (!isFilenameValid(file.name) || !isPathValid(chosenFileName, filepath)) {
return res.status(400).render('uploadfailed', { message: 'Invalid name.' }); return res.status(400).render('uploadfailed', { message: 'invalid name.' });
} }
fs.stat(filepath, (err) => { fs.stat(filepath, (err) => {
if(err == null) { if(err == null) {
return res.status(400).render('uploadfailed', { message: 'A file with that name already exists.' }); return res.status(400).render('uploadfailed', { message: 'a file with that name already exists.' });
} else if(err.code === 'ENOENT') { } else if(err.code === 'ENOENT') {
file.mv(filepath, (err) => { file.mv(filepath, (err) => {
if (err) return res.status(500).render('uploadfailed', { message: 'Something went wrong while uploading the file.' }); if (err) return res.status(500).render('uploadfailed', { message: 'something went wrong while uploading the file.' });
res.render('uploaded', { file: { name: chosenFileName } }); res.render('uploaded', { file: { name: chosenFileName } });
}); });
} else { } else {
return res.status(500).render('uploadfailed', { message: 'Something went wrong.' });; return res.status(500).render('uploadfailed', { message: 'something went wrong.' });;
} }
}); });
}); });
app.use(function (err, req, res, next) { app.use(function (err, req, res, next) {
console.error(err.stack); console.error(err.stack);
res.status(500).send('Internal Server Error: Something went wrong'); res.status(500).send('internal server error: something went wrong');
}); });
app.listen(config.server.port, () => { app.listen(config.server.port, () => {
console.log(`Started server on port ${config.server.port}`); console.log(`started server on port ${config.server.port}`);
}); });

View file

@ -9,8 +9,8 @@
<h1>this is the upload page</h1> <h1>this is the upload page</h1>
<p>i think</p> <p>i think</p>
<form action='/api/upload' method="POST" enctype="multipart/form-data"> <form action='/api/upload' method="POST" enctype="multipart/form-data">
Password: <input type="password" name="password"> </br> password: <input type="password" name="password"> </br>
File name: <input type="text" name="filename"> </br> file name: <input type="text" name="filename"> </br>
<input type="file" name="file"/> </br> <input type="file" name="file"/> </br>
<input type='submit' value='Upload!'/> <input type='submit' value='Upload!'/>
</form> </form>

View file

@ -9,6 +9,6 @@
<h1>the file was uploaded</h1> <h1>the file was uploaded</h1>
<p>i think</p> <p>i think</p>
<br> <br>
<a href="/file/<%= file.name %>">Go to file</a> <a href="/file/<%= file.name %>">go to file</a>
</body> </body>
</html> </html>

View file

@ -10,6 +10,6 @@
<p>i think</p> <p>i think</p>
<p><%= message %></p> <p><%= message %></p>
<br> <br>
<a href="/">Go back</a> <a href="/">go back</a>
</body> </body>
</html> </html>