add asciitrash copy and download button

This commit is contained in:
neri 2020-07-14 13:21:57 +02:00
parent 8436ae4f4d
commit 07db070107
4 changed files with 39 additions and 5 deletions

View File

@ -110,7 +110,7 @@ async fn download(
let mut path = config.files_dir.clone(); let mut path = config.files_dir.clone();
path.push(&file_id); path.push(&file_id);
if kind == FileKind::TEXT.to_string() { if kind == FileKind::TEXT.to_string() && !req.query_string().contains("raw") {
let content = fs::read_to_string(path).await.map_err(|_| { let content = fs::read_to_string(path).await.map_err(|_| {
error::ErrorInternalServerError("this file should be here but could not be found") error::ErrorInternalServerError("this file should be here but could not be found")
})?; })?;

View File

@ -30,7 +30,9 @@ label {
input, input,
select, select,
textarea { textarea,
.button,
.button:visited {
background-color: #222222; background-color: #222222;
color: #dddddd; color: #dddddd;
padding: 0.5rem; padding: 0.5rem;
@ -40,6 +42,19 @@ textarea {
max-width: calc(100vw - 3rem - 4px); max-width: calc(100vw - 3rem - 4px);
} }
input[type="submit"] { .button {
cursor: pointer;
text-decoration: none;
}
.button:hover {
background-color: #444444;
}
.button.main {
background-color: green; background-color: green;
} }
.button.main:hover {
background-color: forestgreen;
}

View File

@ -29,7 +29,7 @@
<option value="2678400">1 monat</option> <option value="2678400">1 monat</option>
</select> </select>
<br /> <br />
<input type="submit" value="Hochladen" /> <input class="main button" type="submit" value="Hochladen" />
</form> </form>
</main> </main>
</body> </body>

View File

@ -9,7 +9,26 @@
<body> <body>
<main> <main>
<h1><a href="/">datatrash</a></h1> <h1><a href="/">datatrash</a></h1>
<textarea rows="20" cols="120" readonly>{text}</textarea> <textarea id="text" rows="20" cols="120" readonly>{text}</textarea>
<br />
<a class="main button" href="?raw">Herunterladen</a>
<button id="copy" class="button" onclick="copyToClipboard()">
Text kopieren
</button>
</main> </main>
<script lang="javascript">
function copyToClipboard() {
const button = document.getElementById("copy");
if (!navigator.clipboard) {
button.innerText = "Nicht unterstützt";
return;
}
const textarea = document.getElementById("text");
navigator.clipboard.writeText(textarea.value).then(
_ => { button.innerText = "Kopiert!"; },
_ => { button.innerText = "Nicht unterstützt"; },
);
}
</script>
</body> </body>
</html> </html>