-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add ability to view logs from web UI
- Loading branch information
Showing
2 changed files
with
190 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,13 +32,6 @@ | |
crossorigin="anonymous" | ||
/> | ||
|
||
<!-- <link | ||
rel="stylesheet" | ||
href="https://cdn.jsdelivr.net/npm/@sweetalert2/[email protected]/dark/dark.min.css" | ||
integrity="sha384-2+Epqnzu2PLK58QMjMin01tqgpiF1f1xYqbSioBCXAiAGv23Gn6FgEtMeJ3S3Z0s" | ||
crossorigin="anonymous" | ||
/> --> | ||
|
||
<link | ||
rel="apple-touch-icon" | ||
sizes="180x180" | ||
|
@@ -78,6 +71,44 @@ | |
div.input-group > select.form-select { | ||
flex: 0.1 1 100px; | ||
} | ||
|
||
#btn-logs { | ||
margin: 24px auto 12px auto; | ||
} | ||
|
||
#box { | ||
margin: 12px auto 12px auto; | ||
resize: vertical; | ||
overflow-y: auto; | ||
min-height: 95px; | ||
width: 85%; | ||
border: 1px solid #333333; | ||
border-radius: 10px; | ||
background-color: #181a1b; | ||
padding: 10px; | ||
text-align: left; | ||
color: #dedad6; | ||
font-family: monospace; | ||
font-size: 12px; | ||
line-height: 16px; | ||
scrollbar-color: #454a4d #202324; | ||
} | ||
|
||
textarea { | ||
transition: border linear .2s, box-shadow linear .2s; | ||
outline: none; | ||
} | ||
|
||
textarea:focus { | ||
border: 1px solid rgba(11, 94, 215, 1); | ||
box-shadow: 0 0 5px rgba(11, 94, 215, 1); | ||
} | ||
|
||
footer > p { | ||
margin: 8px auto 24px auto; | ||
font-size: 16px; | ||
line-height: 24px; | ||
} | ||
</style> | ||
|
||
<title>gallery-dl</title> | ||
|
@@ -129,11 +160,17 @@ <h1 class="display-4">gallery-dl</h1> | |
</button> | ||
</div> | ||
</form> | ||
|
||
<div> | ||
<a href="/gallery-dl/logs" id="btn-logs" class="btn btn-outline-light" onclick="toggleLogs()">Show Logs</a> | ||
</div> | ||
|
||
<div> | ||
<textarea id="box" name="Logs" placeholder="Logs output" readonly style="display: none"></textarea> | ||
</div> | ||
</main> | ||
|
||
<footer class="mt-auto text-white-50"> | ||
<!-- <div id="liveAlertPlaceholder"></div> --> | ||
|
||
<p> | ||
Web frontend for | ||
<a class="text-white" href="https://github.com/mikf/gallery-dl">gallery-dl</a> | ||
|
@@ -145,22 +182,9 @@ <h1 class="display-4">gallery-dl</h1> | |
</div> | ||
|
||
<script> | ||
// var alertPlaceholder = document.getElementById('liveAlertPlaceholder'); | ||
|
||
const urlParams = new URLSearchParams(window.location.search); | ||
const added = urlParams.get('added'); | ||
|
||
// function alert(message, type) { | ||
// var wrapper = document.createElement('div'); | ||
// wrapper.innerHTML = | ||
// '<div class="alert alert-' + | ||
// type + | ||
// ' alert-dismissible" role="alert">' + | ||
// message + | ||
// '<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button></div>'; | ||
// alertPlaceholder.append(wrapper); | ||
// } | ||
|
||
const Success = Swal.mixin({ | ||
animation: true, | ||
position: "top-end", | ||
|
@@ -187,18 +211,40 @@ <h1 class="display-4">gallery-dl</h1> | |
}); | ||
|
||
if (added) { | ||
// alert( | ||
// 'Successfully added <a href=' + | ||
// added + | ||
// '>one item</a> to the download queue.', | ||
// 'success', | ||
// ); | ||
|
||
Success.fire({ | ||
title: "Success!", | ||
html: "Added <a href=" + added + ">one item</a> to the download queue.", | ||
}); | ||
|
||
addLog("Added one item to the download queue: " + added); | ||
} | ||
|
||
function toggleLogs() { | ||
if (document.getElementById("btn-logs").innerText == "Show Logs") { | ||
document.getElementById("box").style.display = "inline"; | ||
document.getElementById("btn-logs").innerText = "Hide Logs"; | ||
} | ||
else { | ||
document.getElementById("box").style.display = "none"; | ||
document.getElementById("btn-logs").innerText = "Show Logs"; | ||
} | ||
} | ||
|
||
function addLog(message) { | ||
const box = document.getElementById("box"); | ||
box.innerText += message + "\n"; | ||
box.scrollTop = box.scrollHeight; | ||
} | ||
|
||
async function fetchLogs() { | ||
const response = await fetch("gallery-dl/logs"); | ||
const logs = await response.text(); | ||
document.getElementById("box").innerText = logs; | ||
} | ||
|
||
fetchLogs(); | ||
|
||
setInterval(fetchLogs, 1000); | ||
</script> | ||
</body> | ||
</html> |