🏡 index : ~doyle/bin.git

author Jordan Johnson-Doyle <jordan@doyle.la> 2019-02-21 11:51:36.0 +00:00:00
committer Jordan Johnson-Doyle <jordan@doyle.la> 2019-02-21 11:51:36.0 +00:00:00
commit
c2219e15f403eab61c730ca03462c79c27f22234 [patch]
tree
8a607dadf12b577d448495920404386db2844987
parent
26b21d7b396689209d1aed8a68f276ae81d658b3
download
c2219e15f403eab61c730ca03462c79c27f22234.tar.gz

Avoid cloning generated id when submitting paste



Diff

 src/main.rs | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/src/main.rs b/src/main.rs
index d280a05..47e33d8 100644
--- a/src/main.rs
+++ a/src/main.rs
@@ -55,8 +55,9 @@
#[post("/", data = "<input>")]
fn submit(input: Form<IndexForm>) -> Redirect {
    let id = generate_id();
    store_paste(id.clone(), input.into_inner().val);
    Redirect::to(uri!(show_paste: id))
    let uri = uri!(show_paste: &id);
    store_paste(id, input.into_inner().val);
    Redirect::to(uri)
}

#[put("/", data = "<input>")]
@@ -65,11 +66,13 @@
    input.open().take(1024 * 1000).read_to_string(&mut data)?;

    let id = generate_id();
    store_paste(id.clone(), data);
    let uri = uri!(show_paste: &id);

    store_paste(id, data);

    match *host {
        Some(host) => Ok(format!("https://{}{}", host, uri!(show_paste: id))),
        None => Ok(id),
        Some(host) => Ok(format!("https://{}{}", host, uri)),
        None => Ok(format!("{}", uri)),
    }
}