d495a14bd219cd4c87152a5344627f98f136cf0c

Author
TheEdgeOfRage <git@theedgeofrage.com>
Committer
TheEdgeOfRage <git@theedgeofrage.com>
Date

Message

Revert download button behaviour

Diff

This diff is truncated to protect this page.

  1diff --git a/assets/index.js b/assets/index.js
  2index 82810f72a1aa7f9e7b25e7a7184ed32ec70d94b6..14af5720636f5544486bad8b3be5dc7f384c2270 100644
  3--- a/assets/index.js
  4+++ b/assets/index.js
  5@@ -46,12 +46,6 @@ document.addEventListener("DOMContentLoaded", function() {
  6 	}
  7 });
  8 
  9-document.addEventListener('click', function(e) {
 10-	const btn = e.target.closest('button[data-url]');
 11-	if (!btn) return;
 12-	downloadVideo(btn.dataset.url, btn.dataset.filename);
 13-});
 14-
 15 var currentVideoID = '';
 16 
 17 function openResolutionModal(button) {
 18@@ -112,19 +106,4 @@ if ("serviceWorker" in navigator) {
 19 	});
 20 }
 21 
 22-function downloadVideo(url, filename) {
 23-	const xhr = new XMLHttpRequest();
 24-	xhr.open("GET", url, true);
 25-	xhr.responseType = "blob";
 26-	xhr.onload = function () {
 27-		if (this.status === 200) {
 28-			const blob = this.response;
 29-			const link = document.createElement("a");
 30-			link.href = window.URL.createObjectURL(blob);
 31-			link.download = filename;
 32-			link.click();
 33-			window.URL.revokeObjectURL(link.href);
 34-		}
 35-	};
 36-	xhr.send();
 37-}
 38+
 39diff --git a/pages/new_videos.templ b/pages/new_videos.templ
 40index b15bc9194983eb53fd3fef6bf13620f1dae8b15b..817410f5fc131a93a1dbe149dc91e495fe6bd291 100644
 41--- a/pages/new_videos.templ
 42+++ b/pages/new_videos.templ
 43@@ -89,14 +89,12 @@ templ VideoCard(video models.Video) {
 44 					</form>
 45 					<div class="d-flex gap-2">
 46 						if video.IsDownloaded() {
 47-							<button
 48-								type="button"
 49+							<a
 50+								href={ templ.SafeURL(fmt.Sprintf("/videos/%s/file", video.ID)) }
 51 								class="btn btn-success"
 52-								data-url={ templ.SafeURL(fmt.Sprintf("/videos/%s/file", video.ID)) }
 53-								data-filename={ templ.SafeURL(video.Title + ".mp4") }
 54 							>
 55 								<i class="bi bi-download"></i>
 56-							</button>
 57+							</a>
 58 						} else if video.IsDownloading() {
 59 							<button
 60 								class="btn btn-primary"
 61diff --git a/pages/new_videos_templ.go b/pages/new_videos_templ.go
 62index 44c8563dece41368e291f71d6f930aa376a767ed..32b2b7ccf056dc709dc04014c98326d4dbd3ed42 100644
 63--- a/pages/new_videos_templ.go
 64+++ b/pages/new_videos_templ.go
 65@@ -363,144 +363,131 @@ func VideoCard(video models.Video) templ.Component {
 66 			return templ_7745c5c3_Err
 67 		}
 68 		if video.IsDownloaded() {
 69-			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<button type=\"button\" class=\"btn btn-success\" data-url=\"")
 70+			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 28, "<a href=\"")
 71 			if templ_7745c5c3_Err != nil {
 72 				return templ_7745c5c3_Err
 73 			}
 74-			var templ_7745c5c3_Var21 string
 75-			templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinStringErrs(templ.SafeURL(fmt.Sprintf("/videos/%s/file", video.ID)))
 76+			var templ_7745c5c3_Var21 templ.SafeURL
 77+			templ_7745c5c3_Var21, templ_7745c5c3_Err = templ.JoinURLErrs(templ.SafeURL(fmt.Sprintf("/videos/%s/file", video.ID)))
 78 			if templ_7745c5c3_Err != nil {
 79-				return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/new_videos.templ`, Line: 95, Col: 74}
 80+				return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/new_videos.templ`, Line: 93, Col: 70}
 81 			}
 82 			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var21))
 83 			if templ_7745c5c3_Err != nil {
 84 				return templ_7745c5c3_Err
 85 			}
 86-			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "\" data-filename=\"")
 87+			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 29, "\" class=\"btn btn-success\"><i class=\"bi bi-download\"></i></a> ")
 88+			if templ_7745c5c3_Err != nil {
 89+				return templ_7745c5c3_Err
 90+			}
 91+		} else if video.IsDownloading() {
 92+			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "<button class=\"btn btn-primary\" disabled hx-get=\"")
 93 			if templ_7745c5c3_Err != nil {
 94 				return templ_7745c5c3_Err
 95 			}
 96 			var templ_7745c5c3_Var22 string
 97-			templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(templ.SafeURL(video.Title + ".mp4"))
 98+			templ_7745c5c3_Var22, templ_7745c5c3_Err = templ.JoinStringErrs(fmt.Sprintf("/videos/%s/card", video.ID))
 99 			if templ_7745c5c3_Err != nil {
100-				return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/new_videos.templ`, Line: 96, Col: 59}
101+				return templ.Error{Err: templ_7745c5c3_Err, FileName: `pages/new_videos.templ`, Line: 102, Col: 57}
102 			}
103 			_, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var22))
104 			if templ_7745c5c3_Err != nil {
105 				return templ_7745c5c3_Err
106 			}
107-			templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 30, "\"><i class=\"bi bi-download\"></i></button> ")