add shortlink to uploaded page
This commit is contained in:
parent
c320f87961
commit
2fb3b257c2
|
@ -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))
|
||||
|
|
|
@ -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,7 +9,7 @@
|
|||
<body>
|
||||
<main>
|
||||
<h1><a href="/">datatrash</a></h1>
|
||||
<p>link: <a id="link" href="{url}">{url}</a></p>
|
||||
<p>link: <a id="link" href="{link}">{link}</a></p>
|
||||
<button id="copy" data-copy="#link" class="main button hidden">
|
||||
link kopieren
|
||||
</button>
|
||||
|
|
Loading…
Reference in New Issue