//This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
-use crate::db_handler::{CheckPairingType, DBHandlerRequest, GetIDSenderType};
+use crate::{
+ constants::BACKEND_PHRASE_MAX_LENGTH,
+ db_handler::{CheckPairingType, DBHandlerRequest, GetIDSenderType},
+};
use std::{
sync::mpsc::{sync_channel, SyncSender},
let (player_tx, player_rx) = sync_channel::<GetIDSenderType>(1);
let mut phrase: Option<String> = None;
if let Some(phrase_text) = root.get("phrase") {
- if let Some(phrase_str) = phrase_text.as_str() {
+ if let Some(mut phrase_str) = phrase_text.as_str() {
if !phrase_str.is_empty() {
+ if phrase_str.len() > BACKEND_PHRASE_MAX_LENGTH {
+ let mut idx = BACKEND_PHRASE_MAX_LENGTH;
+ while idx > 0 && !phrase_str.is_char_boundary(idx) {
+ idx -= 1;
+ }
+ if idx == 0 {
+ phrase_str = "";
+ } else {
+ phrase_str = phrase_str.split_at(idx).0;
+ }
+ }
phrase = Some(phrase_str.to_owned());
}
}
pub const BACKEND_TICK_DURATION_MILLIS: i32 = 500;
pub const BACKEND_CLEANUP_INTERVAL_SECONDS: u64 = 120;
+pub const BACKEND_PHRASE_MAX_LENGTH: usize = 128;
+
// TODO: Change this to "https://asdm.seodisparate.com/api" when backend is installed
#[cfg(debug_assertions)]
pub const BACKEND_URL: &str = "http://testlocalhost/api";