wip: working out /shorten
This commit is contained in:
parent
d8e19e98c8
commit
9372294297
21
src/main.rs
21
src/main.rs
|
@ -458,10 +458,25 @@ async fn serve() {
|
|||
// GET /
|
||||
let homepage = warp::path::end().and(config.serve_rules.dir.to_filter());
|
||||
|
||||
// GET /shorten/:Base64WithoutPaddingUrl
|
||||
let shorten = warp::path!("shorten" / Base64WithoutPaddingUrl).then({
|
||||
|b64url: Base64WithoutPaddingUrl| insert_slug(b64url, slug_factory, db)
|
||||
// POST /shorten/ with argument link:Base64WithoutPaddingUrl
|
||||
let shorten = warp::post()
|
||||
.and(warp::path("shorten"))
|
||||
.and(warp::body::content_length_limit(1024))
|
||||
.and(warp::body::bytes())
|
||||
.then(|body: warp::hyper::body::Bytes| {
|
||||
let unencoded_str = std::str::from_utf8(&body[..]);
|
||||
if unencoded_str.is_err() {
|
||||
return async { warp::reject::reject() };
|
||||
}
|
||||
let b64url = Base64WithoutPaddingUrl::from_str(unencoded_str.unwrap());
|
||||
if b64url.is_err() {
|
||||
return async { warp::reject::reject() };
|
||||
}
|
||||
insert_slug(b64url.unwrap(), slug_factory, db)
|
||||
});
|
||||
/*warp::path!("shorten" / Base64WithoutPaddingUrl).then({
|
||||
|b64url: Base64WithoutPaddingUrl| insert_slug(b64url, slug_factory, db)
|
||||
})*/
|
||||
|
||||
// GET /l/:Slug
|
||||
let link = warp::path("l")
|
||||
|
|
Loading…
Reference in New Issue