From 850e9b47cce60b745a2f3b07895a25962fc5f1ac Mon Sep 17 00:00:00 2001 From: bouzuya Date: Mon, 26 Dec 2022 07:27:23 +0900 Subject: [PATCH] twiq-light: Add simple length check --- twiq-light/src/enqueue.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/twiq-light/src/enqueue.rs b/twiq-light/src/enqueue.rs index d77bf122..6ab4470f 100644 --- a/twiq-light/src/enqueue.rs +++ b/twiq-light/src/enqueue.rs @@ -1,9 +1,13 @@ +use anyhow::bail; use tracing::instrument; use crate::{domain::ScheduledTweet, store::TweetQueueStore}; #[instrument(skip_all)] pub async fn run(store: TweetQueueStore, tweet: String) -> anyhow::Result<()> { + if tweet.chars().count() > 140 { + bail!("The length of the tweet exceeded 140 characters"); + } let mut queue = store.read_all().await?; queue.push_back(ScheduledTweet { text: tweet }); store.write_all(&queue).await?;