Skip to content

Commit

Permalink
Display error on invalid Youtube URL
Browse files Browse the repository at this point in the history
  • Loading branch information
Xwilarg committed Dec 30, 2024
1 parent 78cd596 commit 60c18bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions web/src/main/upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ export async function upload_initAsync() {
popup.classList.remove("is-active");
});

document.getElementById("upload-url").addEventListener("change", (_) => {
const upload = document.getElementById("upload-url");
const content = upload.value;
if (content === "") {
document.getElementById("upload-url-error").classList.add("is-hidden");
upload.classList.remove("is-danger");
} else {
const r = /youtu\.?be(\.com)?\/(watch\?v=)?([^?]+)/g.exec(upload.value);
if (r === null) {
document.getElementById("upload-url-error").classList.remove("is-hidden");
upload.classList.add("is-danger");
} else {
document.getElementById("upload-url-error").classList.add("is-hidden");
upload.classList.remove("is-danger");
}
}
});

document.getElementById("upload-form").addEventListener("submit", (e) => {
e.preventDefault();
const data = new FormData(e.target);
Expand All @@ -28,6 +46,7 @@ export async function upload_initAsync() {
form.elements[i].disabled = false;
}
form.reset();
document.getElementById("upload-yt-player").src = "";
}, () => {
for (var i = 0, len = form.elements.length; i < len; ++i) {
form.elements[i].disabled = false;
Expand Down
1 change: 1 addition & 0 deletions web/templates/upload.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<div class="control">
<input class="input" type="url" name="Youtube" placeholder="Youtube URL to the song" id="upload-url"/>
</div>
<p class="help is-danger is-hidden" id="upload-url-error">This doesn't look like a valid YouTube link</p>
</div>
<div class="field">
<label class="label">Album name</label>
Expand Down

0 comments on commit 60c18bb

Please sign in to comment.