client: write a simple client for the pastebin
Signed-off-by: Gunwant Jain <mail@wantguns.dev>
This commit is contained in:
parent
cb8e210acb
commit
04c992e8b3
|
@ -6,6 +6,7 @@ RUN cargo install --path .
|
||||||
RUN cargo clean
|
RUN cargo clean
|
||||||
|
|
||||||
RUN mkdir -p upload
|
RUN mkdir -p upload
|
||||||
|
COPY ./client upload/client
|
||||||
COPY ./templates templates
|
COPY ./templates templates
|
||||||
COPY ./static static
|
COPY ./static static
|
||||||
|
|
||||||
|
|
10
client
Executable file
10
client
Executable 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)
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
use rocket::data::{Data, ToByteUnit};
|
use rocket::data::{Data, ToByteUnit};
|
||||||
use rocket::response::Redirect;
|
|
||||||
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use crate::models::paste_id::PasteId;
|
use crate::models::paste_id::PasteId;
|
||||||
|
|
||||||
#[post("/", data = "<paste>")]
|
#[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 id = PasteId::new(6);
|
||||||
|
|
||||||
let filename = format!("upload/{id}", id = id);
|
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),
|
false => format!("/{id}", id = id),
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(Redirect::to(url))
|
Ok(url)
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ button[type="submit"] {
|
||||||
border: none;
|
border: none;
|
||||||
padding: 0 1em 0 0;
|
padding: 0 1em 0 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
width: 70%;
|
width: 50%;
|
||||||
font-family: inherit;
|
font-family: inherit;
|
||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
line-height: inherit;
|
line-height: inherit;
|
||||||
|
@ -206,7 +206,9 @@ AUTHOR
|
||||||
},
|
},
|
||||||
body: data
|
body: data
|
||||||
});
|
});
|
||||||
return response;
|
|
||||||
|
const text = await response.text();
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
// drag and drop files
|
// drag and drop files
|
||||||
|
@ -221,7 +223,7 @@ AUTHOR
|
||||||
|
|
||||||
postData(url, blob)
|
postData(url, blob)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
window.location.href = data.url + "." + ext;
|
window.location.href = data + "." + ext;
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
console.info(err + " url: " + url);
|
console.info(err + " url: " + url);
|
||||||
|
@ -243,7 +245,7 @@ AUTHOR
|
||||||
|
|
||||||
postData(url, blob)
|
postData(url, blob)
|
||||||
.then(data => {
|
.then(data => {
|
||||||
window.location.href = data.url;
|
window.location.href = data;
|
||||||
})
|
})
|
||||||
.catch(function (err) {
|
.catch(function (err) {
|
||||||
console.info(err + " url: " + url);
|
console.info(err + " url: " + url);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user