Added copy button for URL redirects

Fixes #80
This commit is contained in:
Daniel Szabo 2022-10-27 17:23:39 +03:00
parent d2e7234d96
commit 769901c895
2 changed files with 118 additions and 98 deletions

View file

@ -334,10 +334,14 @@ Changes the maximum width of the UI from 720 pixels to 1080 pixels.
Add the given public path prefix to all urls. Add the given public path prefix to all urls.
The URL copy feature will only copy the entire URL if this is provided. Otherwise only the path (eg. `/url/dog-cat-bat`) will be copied to your clipboard!
This allows you to host MicroBin behind a reverse proxy on a subpath. This allows you to host MicroBin behind a reverse proxy on a subpath.
Note that MicroBin itself still expects all routes to be as without this option, and thus is unsuited Note that MicroBin itself still expects all routes to be as without this option, and thus is unsuited
if you are running MicroBin directly. if you are running MicroBin directly.
Example: `--public-path https://myserver.com` or `--public-path http://localhost:8080`
#### Example Usage (caddy) #### Example Usage (caddy)
An example of running MicroBin behind the reverse proxy `caddy` on the path `/paste` (using systemd) An example of running MicroBin behind the reverse proxy `caddy` on the path `/paste` (using systemd)

View file

@ -11,105 +11,121 @@
<br> <br>
{% if args.pure_html %} {% if args.pure_html %}
<table border="1" style="width: 100%"> <table border="1" style="width: 100%">
{% else %} {% else %}
<table style="width: 100%"> <table style="width: 100%">
{% endif %} {% endif %}
<thead> <thead>
<tr> <tr>
<th colspan="4">Pastas</th> <th colspan="4">Pastas</th>
</tr> </tr>
<tr> <tr>
<th> <th>
Key Key
</th> </th>
<th> <th>
Created Created
</th> </th>
<th> <th>
Expiration Expiration
</th> </th>
<th> <th>
</th> </th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% for pasta in pastas %} {% for pasta in pastas %}
{% if pasta.pasta_type == "text" && !pasta.private %} {% if pasta.pasta_type == "text" && !pasta.private %}
<tr> <tr>
<td> <td>
<a href="{{ args.public_path }}/pasta/{{pasta.id_as_animals()}}">{{pasta.id_as_animals()}}</a> <a href="{{ args.public_path }}/pasta/{{pasta.id_as_animals()}}">{{pasta.id_as_animals()}}</a>
</td> </td>
<td> <td>
{{pasta.created_as_string()}} {{pasta.created_as_string()}}
</td> </td>
<td> <td>
{{pasta.expiration_as_string()}} {{pasta.expiration_as_string()}}
</td> </td>
<td> <td>
<a style="margin-right:1rem" href="{{ args.public_path }}/raw/{{pasta.id_as_animals()}}">Raw</a> <a style="margin-right:1rem" href="{{ args.public_path }}/raw/{{pasta.id_as_animals()}}">Raw</a>
{% if pasta.file.is_some() %} {% if pasta.file.is_some() %}
<a style="margin-right:1rem" href="{{ args.public_path }}/file/{{pasta.id_as_animals()}}/{{pasta.file.as_ref().unwrap().name()}}">File</a> <a style="margin-right:1rem"
href="{{ args.public_path }}/file/{{pasta.id_as_animals()}}/{{pasta.file.as_ref().unwrap().name()}}">File</a>
{%- endif %}
{% if pasta.editable %}
<a style="margin-right:1rem" href="{{ args.public_path }}/edit/{{pasta.id_as_animals()}}">Edit</a>
{%- endif %}
<a href="{{ args.public_path }}/remove/{{pasta.id_as_animals()}}">Remove</a>
</td>
</tr>
{%- endif %} {%- endif %}
{% if pasta.editable %} {% endfor %}
<a style="margin-right:1rem" href="{{ args.public_path }}/edit/{{pasta.id_as_animals()}}">Edit</a> </tbody>
{%- endif %} </table>
<a href="{{ args.public_path }}/remove/{{pasta.id_as_animals()}}">Remove</a> <br>
</td> {% if args.pure_html %}
</tr> <table border="1" style="width: 100%">
{%- endif %} {% else %}
{% endfor %} <table style="width: 100%">
</tbody> {% endif %}
</table> <thead>
<br> <tr>
{% if args.pure_html %} <th colspan="4">URL Redirects</th>
<table border="1" style="width: 100%"> </tr>
{% else %} <tr>
<table style="width: 100%"> <th>
{% endif %} Key
<thead> </th>
<tr> <th>
<th colspan="4">URL Redirects</th> Created
</tr> </th>
<tr> <th>
<th> Expiration
Key </th>
</th> <th>
<th>
Created
</th>
<th>
Expiration
</th>
<th>
</th> </th>
</tr> </tr>
</thead> </thead>
{% for pasta in pastas %} {% for pasta in pastas %}
{% if pasta.pasta_type == "url" && !pasta.private %} {% if pasta.pasta_type == "url" && !pasta.private %}
<tr> <tr>
<td> <td>
<a href="{{ args.public_path }}/url/{{pasta.id_as_animals()}}">{{pasta.id_as_animals()}}</a> <a href="{{ args.public_path }}/url/{{pasta.id_as_animals()}}">{{pasta.id_as_animals()}}</a>
</td> </td>
<td> <td>
{{pasta.created_as_string()}} {{pasta.created_as_string()}}
</td> </td>
<td> <td>
{{pasta.expiration_as_string()}} {{pasta.expiration_as_string()}}
</td> </td>
<td> <td>
<a style="margin-right:1rem" href="{{ args.public_path }}raw/{{pasta.id_as_animals()}}">Raw</a> <a style="margin-right:1rem" id="copy-button"
{% if pasta.editable %} data-url="{{ args.public_path }}/url/{{pasta.id_as_animals()}}">Copy</a>
<a style="margin-right:1rem" href="{{ args.public_path }}/edit/{{pasta.id_as_animals()}}">Edit</a> {% if pasta.editable %}
<a style="margin-right:1rem" href="{{ args.public_path }}/edit/{{pasta.id_as_animals()}}">Edit</a>
{%- endif %}
<a href="{{ args.public_path }}/remove/{{pasta.id_as_animals()}}">Remove</a>
</td>
</tr>
{%- endif %} {%- endif %}
<a href="{{ args.public_path }}/remove/{{pasta.id_as_animals()}}">Remove</a> {% endfor %}
</td> </tbody>
</tr> </table>
{%- endif %} <br>
{% endfor %} {%- endif %}
</tbody>
</table> <script>
<br> // const btn = document.getElementById("copy-button")
{%- endif %} const btn = document.querySelector("#copy-button");
{% include "footer.html" %} btn.addEventListener("click", () => {
navigator.clipboard.writeText(btn.dataset.url)
btn.innerHTML = "Copied"
setTimeout(() => {
btn.innerHTML = "Copy"
}, 1000)
})
</script>
{% include "footer.html" %}