Avoid cloning generated id when submitting paste
This commit is contained in:
parent
26b21d7b39
commit
c2219e15f4
1 changed files with 8 additions and 5 deletions
13
src/main.rs
13
src/main.rs
|
@ -55,8 +55,9 @@ struct IndexForm {
|
||||||
#[post("/", data = "<input>")]
|
#[post("/", data = "<input>")]
|
||||||
fn submit(input: Form<IndexForm>) -> Redirect {
|
fn submit(input: Form<IndexForm>) -> Redirect {
|
||||||
let id = generate_id();
|
let id = generate_id();
|
||||||
store_paste(id.clone(), input.into_inner().val);
|
let uri = uri!(show_paste: &id);
|
||||||
Redirect::to(uri!(show_paste: id))
|
store_paste(id, input.into_inner().val);
|
||||||
|
Redirect::to(uri)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[put("/", data = "<input>")]
|
#[put("/", data = "<input>")]
|
||||||
|
@ -65,11 +66,13 @@ fn submit_raw(input: Data, host: HostHeader) -> std::io::Result<String> {
|
||||||
input.open().take(1024 * 1000).read_to_string(&mut data)?;
|
input.open().take(1024 * 1000).read_to_string(&mut data)?;
|
||||||
|
|
||||||
let id = generate_id();
|
let id = generate_id();
|
||||||
store_paste(id.clone(), data);
|
let uri = uri!(show_paste: &id);
|
||||||
|
|
||||||
|
store_paste(id, data);
|
||||||
|
|
||||||
match *host {
|
match *host {
|
||||||
Some(host) => Ok(format!("https://{}{}", host, uri!(show_paste: id))),
|
Some(host) => Ok(format!("https://{}{}", host, uri)),
|
||||||
None => Ok(id),
|
None => Ok(format!("{}", uri)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue