Compare commits
3 Commits
530ae31c77
...
48005123de
Author | SHA1 | Date |
---|---|---|
neri | 48005123de | |
neri | 2fb3b257c2 | |
neri | c320f87961 |
|
@ -16,6 +16,7 @@ use rand::prelude::SliceRandom;
|
|||
use sqlx::postgres::PgPool;
|
||||
|
||||
const UPLOAD_HTML: &str = include_str!("../template/upload.html");
|
||||
const UPLOAD_SHORT_HTML: &str = include_str!("../template/upload-short.html");
|
||||
|
||||
const ID_CHARS: &[char] = &[
|
||||
'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> {
|
||||
let id = req.match_info().query("id");
|
||||
let name = req.match_info().get("name");
|
||||
let url = get_file_url(&req, id, name);
|
||||
let upload_html = UPLOAD_HTML.replace("{url}", url.as_str());
|
||||
let upload_html = if name.is_some() {
|
||||
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()
|
||||
.content_type("text/html")
|
||||
.body(upload_html))
|
||||
|
|
|
@ -1,17 +1,13 @@
|
|||
const button = document.getElementById("copy");
|
||||
button.classList.remove("hidden");
|
||||
button.onclick = () => {
|
||||
if (!navigator.clipboard) {
|
||||
button.innerText = "nicht unterstützt";
|
||||
return;
|
||||
}
|
||||
const content = document.getElementsByClassName("copy-content")[0];
|
||||
navigator.clipboard.writeText(content.textContent).then(
|
||||
(_) => {
|
||||
button.innerText = "kopiert!";
|
||||
},
|
||||
(_) => {
|
||||
button.innerText = "nicht unterstützt";
|
||||
}
|
||||
if (navigator.clipboard) {
|
||||
const buttons = document.querySelectorAll("button[data-copy], a[data-copy]");
|
||||
for (const button of buttons) {
|
||||
button.classList.remove("hidden");
|
||||
button.onclick = () => {
|
||||
const target = document.querySelector(button.getAttribute("data-copy"));
|
||||
navigator.clipboard.writeText(target.textContent).then(
|
||||
(_) => (button.innerText = "kopiert!"),
|
||||
(_) => (button.innerText = "nicht unterstützt")
|
||||
);
|
||||
};
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,6 +101,7 @@ input[type="checkbox"] {
|
|||
font-weight: normal;
|
||||
font-size: 1rem;
|
||||
margin-right: 0.5rem;
|
||||
margin-top: 1rem;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
|
|
|
@ -9,12 +9,12 @@
|
|||
<body>
|
||||
<main>
|
||||
<h1><a href="/">datatrash</a></h1>
|
||||
<textarea id="text" rows="20" cols="120" class="copy-content" readonly>
|
||||
{text}</textarea
|
||||
>
|
||||
<textarea id="text" rows="20" cols="120" readonly>{text}</textarea>
|
||||
<br />
|
||||
<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>
|
||||
<footer>
|
||||
<a
|
||||
|
|
|
@ -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>
|
|
@ -9,11 +9,10 @@
|
|||
<body>
|
||||
<main>
|
||||
<h1><a href="/">datatrash</a></h1>
|
||||
<p>
|
||||
datei-link:
|
||||
<a id="link" class="copy-content" href="{url}">{url}</a>
|
||||
</p>
|
||||
<button id="copy" class="main button hidden">link kopieren</button>
|
||||
<p>link: <a id="link" href="{link}">{link}</a></p>
|
||||
<button id="copy" data-copy="#link" class="main button hidden">
|
||||
link kopieren
|
||||
</button>
|
||||
</main>
|
||||
<footer>
|
||||
<a
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
<main>
|
||||
<h1><a href="/">datatrash</a></h1>
|
||||
<a
|
||||
class="large-link copy-content"
|
||||
id="link"
|
||||
class="large-link"
|
||||
href="{link_attribute}"
|
||||
rel="noopener noreferrer"
|
||||
>{link_content}</a
|
||||
|
@ -19,7 +20,9 @@
|
|||
<a class="main button" href="{link_attribute}" rel="noopener noreferrer">
|
||||
link öffnen
|
||||
</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>
|
||||
</main>
|
||||
<footer>
|
||||
|
|
Loading…
Reference in New Issue