Skip to content

Commit

Permalink
fix(Tweet): prevent empty tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
paulleflon committed Sep 19, 2024
1 parent c4cab99 commit f5aa1fe
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "retweet",
"version": "1.1.2",
"version": "1.1.3",
"description": "Twitter comme à l'époque",
"main": "src/app.js",
"repository": "https://github.com/paulleflon/retweet.git",
Expand Down
2 changes: 1 addition & 1 deletion public/js/TweetForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ for (const form of document.querySelectorAll('form.tweet-form')) {
// Vérification de la longueur du tweet.
form.addEventListener('submit', e => {
e.preventDefault();
const content = form.querySelector('input[name=\'content\']').value;
const content = form.querySelector('input[name=\'content\']').value.trim();
if (content.length > 0 && content.length <= 280)
form.submit();
else
Expand Down
5 changes: 4 additions & 1 deletion src/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ const router = Router();
* Envoie un tweet.
*/
router.post('/tweets/add', upload.single('image'), async (req, res) => {
const {content, repliesTo} = req.body;
let {content, repliesTo} = req.body;
content = content.trim();
let parentTweet;
let repliesToUsername;
if (content.length < 1)
return res.status(400).send({message: 'Contenu trop court.'});
if (content.length > 280)
return res.status(400).send({message: 'Contenu trop long.'});
if (repliesTo) {
Expand Down

0 comments on commit f5aa1fe

Please sign in to comment.