mirror of
https://github.com/SinTan1729/chhoto-url
synced 2025-02-05 13:52:33 -06:00
new: Proper reply when invalid data is sent
This commit is contained in:
parent
a9168e3459
commit
38b817fdf8
2 changed files with 10 additions and 6 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -8,4 +8,4 @@ urls.sqlite
|
|||
.vscode/
|
||||
**/.directory
|
||||
.env
|
||||
|
||||
cookie*
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
use std::env;
|
||||
|
||||
use crate::database;
|
||||
use nanoid::nanoid;
|
||||
use rand::seq::SliceRandom;
|
||||
use regex::Regex;
|
||||
use rusqlite::Connection;
|
||||
use serde::Deserialize;
|
||||
use std::env;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
use crate::database;
|
||||
|
||||
#[derive(Deserialize, Default, PartialEq)]
|
||||
struct URLPair {
|
||||
shortlink: String,
|
||||
longlink: String,
|
||||
|
@ -32,7 +32,11 @@ pub fn getall(db: &Connection) -> String {
|
|||
}
|
||||
|
||||
pub fn add_link(req: String, db: &Connection) -> (bool, String) {
|
||||
let mut chunks: URLPair = serde_json::from_str(&req).unwrap();
|
||||
let mut chunks: URLPair = serde_json::from_str(&req).unwrap_or_default();
|
||||
|
||||
if chunks == URLPair::default() {
|
||||
return (false, String::from("Invalid request!"));
|
||||
}
|
||||
|
||||
let style = env::var("slug_style").unwrap_or(String::from("Pair"));
|
||||
let len_str = env::var("slug_length").unwrap_or(String::from("8"));
|
||||
|
|
Loading…
Reference in a new issue