feat: Add copier and curl links
All checks were successful
/ pre-commit (push) Successful in 1m16s

Signed-off-by: Julien Riou <julien@riou.xyz>
This commit is contained in:
Julien Riou 2025-10-02 09:23:40 +02:00
commit b316c6ef67
Signed by: jriou
GPG key ID: 9A099EDA51316854
4 changed files with 77 additions and 3 deletions

View file

@ -6,6 +6,12 @@
<div class="d-flex flex-wrap py-2">
<span class="fs-4 d-flex mb-3 mb-md-0 me-md-auto text-decoration-none">Note {{.Note.ID}}</span>
<ul class="nav nav-pills align-items-center">
<li class="nav-item">
<button type="button" class="btn btn-link" id="copier">copier</button>
</li>
<li class="nav-item">
<button type="button" class="btn btn-link" id="curl">curl</button>
</li>
<li class="nav-item px-2">
<a href="" id="rawURL">raw</a>
<script>document.getElementById("rawURL").href = window.location.href.replace(".html", "");</script>
@ -20,6 +26,65 @@
{{end}}
</ul>
</div>
<script>
var password = "{{ .Password }}";
var encryptionKey = window.location.hash.substr(1);
</script>
<div id="copierContainer" style="display: none;" class="alert alert-info alert-dismissible" role="alert">
<p>Access the note with <strong>copier</strong>:</p>
<pre id="copierCommand" style="border: 1px solid;" class="p-2"></pre>
<button type="button" class="btn-close" data-dismiss="alert" aria-label="Close" id="copierClose">
<span aria-hidden="true"></span>
</button>
</div>
<script>
var copierCommand = "copier";
var copierOpts = "";
if (password != "") {
copierOpts += " -password '" + password + "'";
}
copierCommand += copierOpts + " " + window.location.origin + "/{{ .Note.ID }}";
if (encryptionKey != "") {
copierCommand += "#" + encryptionKey;
}
document.getElementById("copierCommand").innerHTML = copierCommand;
document.getElementById("copier").addEventListener("click", () => {
document.getElementById("copierContainer").style.display = "";
});
document.getElementById("copierClose").addEventListener("click", () => {
document.getElementById("copierContainer").style.display = "none";
});
</script>
<div id="curlContainer" style="display: none;" class="alert alert-info alert-dismissible" role="alert">
<p>Access the note with <strong>curl</strong>:</p>
<pre id="curlCommand" style="border: 1px solid;" class="p-2"></pre>
<button type="button" class="btn-close" data-dismiss="alert" aria-label="Close" id="curlClose">
<span aria-hidden="true"></span>
</button>
</div>
<script>
var curlCommand = "curl";
var curlData = {};
if (encryptionKey != "") {
curlData.encryption_key = encryptionKey;
};
if (password != "") {
curlData.password = window.btoa(password);
}
var payload = JSON.stringify(curlData);
if (payload != "{}") {
curlCommand += " -XPOST -d '" + payload + "'";
}
curlCommand += " " + window.location.origin + "/api/note/{{ .Note.ID }}";
document.getElementById("curlCommand").innerHTML = curlCommand;
document.getElementById("curl").addEventListener("click", () => {
document.getElementById("curlContainer").style.display = "";
});
document.getElementById("curlClose").addEventListener("click", () => {
document.getElementById("curlContainer").style.display = "none";
});
</script>
{{if .DisableEditor}}
<div class="row">
<pre class="border px-3 pt-3" style="min-height: 300px; resize: vertical; overflow: auto;">
@ -28,7 +93,8 @@
</div>
{{else}}
<div class="row">
<div id="editor" name="editor" class="form-control" style="min-height: 300px; resize: vertical; overflow: auto;">
<div id="editor" name="editor" class="form-control"
style="min-height: 300px; resize: vertical; overflow: auto;">
</div>
</div>
<script