From 04c992e8b3ae86d490b1b99abcd6b289e15003f5 Mon Sep 17 00:00:00 2001 From: Gunwant Jain Date: Tue, 13 Jul 2021 21:20:54 +0530 Subject: [PATCH] client: write a simple client for the pastebin Signed-off-by: Gunwant Jain --- Dockerfile | 1 + client | 10 ++++++++++ src/routes/upload.rs | 5 ++--- templates/index.html.tera | 10 ++++++---- 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100755 client diff --git a/Dockerfile b/Dockerfile index d78c3cb..eba6e56 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/client b/client new file mode 100755 index 0000000..416ef4c --- /dev/null +++ b/client @@ -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) + diff --git a/src/routes/upload.rs b/src/routes/upload.rs index 0d10c71..0346347 100644 --- a/src/routes/upload.rs +++ b/src/routes/upload.rs @@ -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 = "")] -pub async fn upload(paste: Data<'_>) -> Result { +pub async fn upload(paste: Data<'_>) -> Result { let id = PasteId::new(6); let filename = format!("upload/{id}", id = id); @@ -23,5 +22,5 @@ pub async fn upload(paste: Data<'_>) -> Result { false => format!("/{id}", id = id), }; - Ok(Redirect::to(url)) + Ok(url) } diff --git a/templates/index.html.tera b/templates/index.html.tera index f9d4649..7e26d80 100644 --- a/templates/index.html.tera +++ b/templates/index.html.tera @@ -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);