Compare commits

..

3 Commits

Author SHA1 Message Date
neri 48005123de increase margin-top of buttons 2021-12-20 01:06:45 +01:00
neri 2fb3b257c2 add shortlink to uploaded page 2021-12-20 01:06:28 +01:00
neri c320f87961 make copying more generic and hide when unsupported 2021-12-20 01:05:38 +01:00
7 changed files with 67 additions and 29 deletions

View File

@ -16,6 +16,7 @@ use rand::prelude::SliceRandom;
use sqlx::postgres::PgPool; use sqlx::postgres::PgPool;
const UPLOAD_HTML: &str = include_str!("../template/upload.html"); const UPLOAD_HTML: &str = include_str!("../template/upload.html");
const UPLOAD_SHORT_HTML: &str = include_str!("../template/upload-short.html");
const ID_CHARS: &[char] = &[ const ID_CHARS: &[char] = &[
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'q', 'r', 's', 't', 'u', 'v',
@ -151,8 +152,13 @@ fn get_file_url(req: &web::HttpRequest, id: &str, name: Option<&str>) -> String
pub async fn uploaded(req: web::HttpRequest) -> Result<HttpResponse, Error> { pub async fn uploaded(req: web::HttpRequest) -> Result<HttpResponse, Error> {
let id = req.match_info().query("id"); let id = req.match_info().query("id");
let name = req.match_info().get("name"); let name = req.match_info().get("name");
let url = get_file_url(&req, id, name); let upload_html = if name.is_some() {
let upload_html = UPLOAD_HTML.replace("{url}", url.as_str()); UPLOAD_SHORT_HTML
.replace("{link}", &get_file_url(&req, id, name))
.replace("{shortlink}", &get_file_url(&req, id, None))
} else {
UPLOAD_HTML.replace("{link}", &get_file_url(&req, id, name))
};
Ok(HttpResponse::Ok() Ok(HttpResponse::Ok()
.content_type("text/html") .content_type("text/html")
.body(upload_html)) .body(upload_html))

View File

@ -1,17 +1,13 @@
const button = document.getElementById("copy"); if (navigator.clipboard) {
button.classList.remove("hidden"); const buttons = document.querySelectorAll("button[data-copy], a[data-copy]");
button.onclick = () => { for (const button of buttons) {
if (!navigator.clipboard) { button.classList.remove("hidden");
button.innerText = "nicht unterstützt"; button.onclick = () => {
return; const target = document.querySelector(button.getAttribute("data-copy"));
} navigator.clipboard.writeText(target.textContent).then(
const content = document.getElementsByClassName("copy-content")[0]; (_) => (button.innerText = "kopiert!"),
navigator.clipboard.writeText(content.textContent).then( (_) => (button.innerText = "nicht unterstützt")
(_) => {
button.innerText = "kopiert!";
},
(_) => {
button.innerText = "nicht unterstützt";
}
); );
}; };
}
}

View File

@ -101,6 +101,7 @@ input[type="checkbox"] {
font-weight: normal; font-weight: normal;
font-size: 1rem; font-size: 1rem;
margin-right: 0.5rem; margin-right: 0.5rem;
margin-top: 1rem;
user-select: none; user-select: none;
} }

View File

@ -9,12 +9,12 @@
<body> <body>
<main> <main>
<h1><a href="/">datatrash</a></h1> <h1><a href="/">datatrash</a></h1>
<textarea id="text" rows="20" cols="120" class="copy-content" readonly> <textarea id="text" rows="20" cols="120" readonly>{text}</textarea>
{text}</textarea
>
<br /> <br />
<a class="main button" href="?dl">herunterladen</a> <a class="main button" href="?dl">herunterladen</a>
<button id="copy" class="button hidden">text kopieren</button> <button id="copy" data-copy="#text" class="button hidden">
text kopieren
</button>
</main> </main>
<footer> <footer>
<a <a

View File

@ -0,0 +1,33 @@
<!DOCTYPE html>
<html lang="de-DE">
<head>
<title>datatrash</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="/static/index.css" rel="stylesheet" />
</head>
<body>
<main>
<h1><a href="/">datatrash</a></h1>
<p>link: <a id="link" href="{link}">{link}</a></p>
<p>shortlink: <a id="shortlink" href="{shortlink}">{shortlink}</a></p>
<button id="copy" data-copy="#link" class="main button hidden">
link kopieren
</button>
<button id="copy-short" data-copy="#shortlink" class="button hidden">
shortlink kopieren
</button>
</main>
<footer>
<a
class="repo"
href="https://repos.ctdo.de/neri/datatrash"
target="_blank"
rel="noopener noreferrer"
>
repo
</a>
</footer>
<script src="/static/copy.js" lang="javascript"></script>
</body>
</html>

View File

@ -9,11 +9,10 @@
<body> <body>
<main> <main>
<h1><a href="/">datatrash</a></h1> <h1><a href="/">datatrash</a></h1>
<p> <p>link: <a id="link" href="{link}">{link}</a></p>
datei-link: <button id="copy" data-copy="#link" class="main button hidden">
<a id="link" class="copy-content" href="{url}">{url}</a> link kopieren
</p> </button>
<button id="copy" class="main button hidden">link kopieren</button>
</main> </main>
<footer> <footer>
<a <a

View File

@ -10,7 +10,8 @@
<main> <main>
<h1><a href="/">datatrash</a></h1> <h1><a href="/">datatrash</a></h1>
<a <a
class="large-link copy-content" id="link"
class="large-link"
href="{link_attribute}" href="{link_attribute}"
rel="noopener noreferrer" rel="noopener noreferrer"
>{link_content}</a >{link_content}</a
@ -19,7 +20,9 @@
<a class="main button" href="{link_attribute}" rel="noopener noreferrer"> <a class="main button" href="{link_attribute}" rel="noopener noreferrer">
link öffnen link öffnen
</a> </a>
<button id="copy" class="button hidden">link kopieren</button> <button id="copy" data-copy="#link" class="button hidden">
link kopieren
</button>
<a class="button" href="?dl">als text herunterladen</a> <a class="button" href="?dl">als text herunterladen</a>
</main> </main>
<footer> <footer>