client: write a simple client for the pastebin

Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
Gunwant Jain 2021-07-13 21:20:54 +05:30
parent cb8e210acb
commit 04c992e8b3
4 changed files with 19 additions and 7 deletions

View File

@ -6,6 +6,7 @@ RUN cargo install --path .
RUN cargo clean
RUN mkdir -p upload
COPY ./client upload/client
COPY ./templates templates
COPY ./static static

10
client Executable file
View File

@ -0,0 +1,10 @@
#!/bin/sh
url="http://127.0.0.1:8000"
filepath="$1"
filename=$(basename -- "$filepath")
extension="${filename##*.}"
response=$(curl --data-binary @${filepath:-/dev/stdin} --url $url)
echo "$url$response"".""$extension" | tee >(xclip -selection clipboard)

View File

@ -1,12 +1,11 @@
use rocket::data::{Data, ToByteUnit};
use rocket::response::Redirect;
use std::path::Path;
use crate::models::paste_id::PasteId;
#[post("/", data = "<paste>")]
pub async fn upload(paste: Data<'_>) -> Result<Redirect, std::io::Error> {
pub async fn upload(paste: Data<'_>) -> Result<String, std::io::Error> {
let id = PasteId::new(6);
let filename = format!("upload/{id}", id = id);
@ -23,5 +22,5 @@ pub async fn upload(paste: Data<'_>) -> Result<Redirect, std::io::Error> {
false => format!("/{id}", id = id),
};
Ok(Redirect::to(url))
Ok(url)
}

View File

@ -54,7 +54,7 @@ button[type="submit"] {
border: none;
padding: 0 1em 0 0;
margin: 0;
width: 70%;
width: 50%;
font-family: inherit;
font-size: inherit;
line-height: inherit;
@ -206,7 +206,9 @@ AUTHOR
},
body: data
});
return response;
const text = await response.text();
return text;
}
// drag and drop files
@ -221,7 +223,7 @@ AUTHOR
postData(url, blob)
.then(data => {
window.location.href = data.url + "." + ext;
window.location.href = data + "." + ext;
})
.catch(function (err) {
console.info(err + " url: " + url);
@ -243,7 +245,7 @@ AUTHOR
postData(url, blob)
.then(data => {
window.location.href = data.url;
window.location.href = data;
})
.catch(function (err) {
console.info(err + " url: " + url);