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);
if (!isValid) {
res.status(400).send('Invalid input.');
res.status(400).send('invalid input.');
return;
}
fs.access(filePath, fs.F_OK, (err) => {
if (err) {
res.status(404).send('File not found or is invalid.');
res.status(404).send('file not found or is invalid.');
return;
}
@ -114,44 +114,44 @@ app.post('/api/upload', [ cors(corsOptions) ], (req, res) => {
const chosenFileName = req.body.filename;
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) {
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;
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);
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) => {
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') {
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 } });
});
} 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) {
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, () => {
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>
<p>i think</p>
<form action='/api/upload' method="POST" enctype="multipart/form-data">
Password: <input type="password" name="password"> </br>
File name: <input type="text" name="filename"> </br>
password: <input type="password" name="password"> </br>
file name: <input type="text" name="filename"> </br>
<input type="file" name="file"/> </br>
<input type='submit' value='Upload!'/>
</form>

View file

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

View file

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