diff --git a/Tesses.YouTubeDownloader.Server/res/service_worker.js b/Tesses.YouTubeDownloader.Server/res/service_worker.js
index 1d32a87..3c69cd7 100644
--- a/Tesses.YouTubeDownloader.Server/res/service_worker.js
+++ b/Tesses.YouTubeDownloader.Server/res/service_worker.js
@@ -2,6 +2,13 @@ const assets = ["<@ASSETS@>"];
const staticCacheName = "tytd-static-<@BUILD_TIME@>";
+async function ThrowOnBadGateway(req)
+{
+ const resp = await fetch(req);
+ if(resp.status === 502) throw new Error("Bad Gateway");
+ return resp;
+}
+
self.addEventListener('install',evt => {
evt.waitUntil(
caches.open(staticCacheName).then(cache =>{
@@ -19,24 +26,29 @@ self.addEventListener('activate',(evt)=>{
});
self.addEventListener('fetch', evt => {
- const uri = new URL(evt.request.url);
evt.respondWith(
-
+
caches.match(evt.request).then(cacheRes=>{
- return cacheRes || fetch(evt.request);
- }).catch(()=>{
- if(uri.pathname === '/queue-size')
+ console.warn('SW cacheRes:', cacheRes);
+ return cacheRes || ThrowOnBadGateway(evt.request);
+ }).catch((err)=>{
+ console.warn('SW Fallback:', err.message);
+ if(evt.request.headers.has('HX-Request'))
{
- return new Response('
?',{
- headers: { 'Content-Type': 'text/html' }
- });
+
+ return new Response("",{
+ status: 200,
+ headers: {
+ 'HX-Redirect': "/offline.html"
+ }
+ });
}
- if(uri.pathname === "/progress")
+ else
{
- return caches.match("/offline-progress.html");
+ return caches.match('/offline.html');
+
}
- return caches.match('/offline.html');
})
);
-});
\ No newline at end of file
+});
diff --git a/Tesses.YouTubeDownloader.Server/src/components/discover_entry.tcross b/Tesses.YouTubeDownloader.Server/src/components/discover_entry.tcross
deleted file mode 100644
index 59d2893..0000000
--- a/Tesses.YouTubeDownloader.Server/src/components/discover_entry.tcross
+++ /dev/null
@@ -1,62 +0,0 @@
-func Components.DiscoverEntry(item)
-{
- switch(item.type)
- {
- case "video":
- return
-
-
-
}"})
-
-
-
-
-
- {item.views} • {item.uploaded}
-
-
-
-
-
-
;
- break;
- case "channel":
- return
-
-
-
}"})
-
-
-
;
- break;
- }
-
- return "";
-}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/components/music-album-entry.tcross b/Tesses.YouTubeDownloader.Server/src/components/music-album-entry.tcross
deleted file mode 100644
index 58c779c..0000000
--- a/Tesses.YouTubeDownloader.Server/src/components/music-album-entry.tcross
+++ /dev/null
@@ -1,11 +0,0 @@
-func Components.MusicAlbum(item)
-{
- return
-
-
}"})
-
-
-
;
-}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/components/music-artist.tcross b/Tesses.YouTubeDownloader.Server/src/components/music-artist.tcross
deleted file mode 100644
index d62e640..0000000
--- a/Tesses.YouTubeDownloader.Server/src/components/music-artist.tcross
+++ /dev/null
@@ -1,4 +0,0 @@
-func Components.MusicArtist(item)
-{
- return
{item.name};
-}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/components/queuesz.tcross b/Tesses.YouTubeDownloader.Server/src/components/queuesz.tcross
index d093777..0755061 100644
--- a/Tesses.YouTubeDownloader.Server/src/components/queuesz.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/components/queuesz.tcross
@@ -5,7 +5,7 @@ func Components.QueueSZ(tytd)
tytd.Mutex.Lock();
- var html =
{tytd.VideoQueueCount};
+ var html =
{tytd.VideoQueueCount};
tytd.Mutex.Unlock();
return html;
diff --git a/Tesses.YouTubeDownloader.Server/src/components/shell.tcross b/Tesses.YouTubeDownloader.Server/src/components/shell.tcross
index 0bee664..d86ed39 100644
--- a/Tesses.YouTubeDownloader.Server/src/components/shell.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/components/shell.tcross
@@ -21,34 +21,48 @@ func Components.Shell(title, html, page, $mypage)
text="Home",
icon="home",
href=index,
- classStr=""
+ classStr="",
+ badge = ""
+ },
+ {
+ text="Queue",
+ icon="downloading",
+ href=(/"queue").MakeRelative(mypage).ToString(),,
+ classStr="",
+ badge=
+ ?
+
},
{
text = "Downloads",
icon = "download",
href=(/"downloads").MakeRelative(mypage).ToString(),
- classStr=""
+ classStr="",
+ badge=""
},
{
text = "Plugins",
icon = "extension",
href= (/"plugins").MakeRelative(mypage).ToString(),
- classStr=""
+ classStr="",
+ badge=""
},
{
text = "Settings",
icon = "settings",
href= (/"settings").MakeRelative(mypage).ToString(),
- classStr=""
+ classStr="",
+ badge=""
},
{
text = "Api",
icon = "api",
href = (/"api").MakeRelative(mypage).ToString(),
- classStr=""
+ classStr="",
+ badge=""
}
];
- pages[page].classStr = "active";
+ pages[page].classStr = " primary-container";
return
@@ -65,8 +79,43 @@ func Components.Shell(title, html, page, $mypage)
-
-
*/
diff --git a/Tesses.YouTubeDownloader.Server/src/main.tcross b/Tesses.YouTubeDownloader.Server/src/main.tcross
index a5984ff..caff570 100644
--- a/Tesses.YouTubeDownloader.Server/src/main.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/main.tcross
@@ -58,6 +58,11 @@ class TYTDApp {
}
public Handle(ctx)
{
+ if(ctx.Path == "/api/v1/resolutions.json")
+ {
+ ctx.SendJson(Resolution.Resolutions);
+ return true;
+ }
if(ctx.Path == "/service_worker.js" || fileNames.Contains(ctx.Path))
{
const inm=ctx.RequestHeaders.TryGetFirst("If-None-Match");
@@ -176,6 +181,10 @@ class TYTDApp {
);
return true;
}
+ if(ctx.Path == "/queue-size")
+ {
+ return false;
+ }
if(ctx.Path == "/sso")
{
const app = ctx.QueryParams.TryGetFirst("app") ?? "";
@@ -570,6 +579,21 @@ class TYTDApp {
ctx.WithMimeType("application/json").SendJson(this.TYTD.GetChannelContents(id,page-1,count));
return true;
}
+ else if(ctx.Path == "/api/v1/queue.json")
+ {
+ if(ctx.Method == "GET")
+ {
+ var page = ctx.QueryParams.TryGetFirstInt("page");
+ var count = ctx.QueryParams.TryGetFirstInt("count");
+ if(TypeOf(page)!="Long") page = 1;
+ if(TypeOf(count)!="Long") count = 20;
+
+
+ var result = { entries = TYTD.GetQueueItems(page-1,count)};
+ ctx.WithMimeType("application/json").SendJson(result);
+ return true;
+ }
+ }
else if(ctx.Path == "/api/v1/downloads.json")
{
var q = ctx.QueryParams.TryGetFirst("q");
@@ -605,7 +629,7 @@ class TYTDApp {
if(!this.TYTD.SendDatabase(ctx))
{
- ctx.WithMimeType("text/html").SendText(Components.Shell("Unauthorized","You are not authorized to download the database
",3,/"api/v1/database.db"));
+ ctx.WithMimeType("text/html").SendText(Components.Shell("Unauthorized","You are not authorized to download the database
",4,/"api/v1/database.db"));
}
return true;
}
@@ -773,6 +797,24 @@ class TYTDApp {
return true;
}
}
+ else if(ctx.Path == "/queue")
+ {
+
+ if(ctx.Method == "DELETE")
+ {
+ const id = ctx.QueryParams.TryGetFirstInt("id");
+ if(TypeIsLong(id))
+ {
+ this.TYTD.QueueRemoveItem(id);
+ }
+ else
+ {
+ this.TYTD.QueueClear();
+ }
+ }
+ ctx.WithMimeType("text/html").SendText(Pages.Queue(this.TYTD,ctx));
+ return true;
+ }
else if(ctx.Path == "/downloads")
{
ctx.WithMimeType("text/html").SendText(Pages.Downloads(this.TYTD,ctx));
@@ -793,7 +835,7 @@ class TYTDApp {
{
if(!UserFlags.IsAdmin(this.TYTD.IsLoggedIn(ctx)))
{
- ctx.WithMimeType("text/html").SendText(Components.Shell("Unauthorized",You can{"'"}t modify admin settings as you are not an admin
,3));
+ ctx.WithMimeType("text/html").SendText(Components.Shell("Unauthorized",You can{"'"}t modify admin settings as you are not an admin
,4));
return true;
}
const user = ctx.QueryParams.TryGetFirst("user");
@@ -871,7 +913,7 @@ class TYTDApp {
{
if(!UserFlags.IsAdmin(this.TYTD.IsLoggedIn(ctx)))
{
- ctx.WithMimeType("text/html").SendText(Components.Shell("Unauthorized",You can{"'"}t modify admin settings as you are not an admin
,3));
+ ctx.WithMimeType("text/html").SendText(Components.Shell("Unauthorized",You can{"'"}t modify admin settings as you are not an admin
,4));
return true;
}
if(ctx.Method == "POST")
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/admin.tcross b/Tesses.YouTubeDownloader.Server/src/pages/admin.tcross
index ab69271..d5694d8 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/admin.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/admin.tcross
@@ -72,5 +72,5 @@ func Pages.Admin(tytd,ctx)
;
- return Components.Shell("Admin Settings",html ,3);
+ return Components.Shell("Admin Settings",html ,4);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/api.tcross b/Tesses.YouTubeDownloader.Server/src/pages/api.tcross
index 8cdbe40..9607355 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/api.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/api.tcross
@@ -8,5 +8,5 @@ func Pages.Api()
;
- return Components.Shell("Api",html,4);
+ return Components.Shell("Api",html,5);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/api/api-v1.tcross b/Tesses.YouTubeDownloader.Server/src/pages/api/api-v1.tcross
index 80b147a..1375cfd 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/api/api-v1.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/api/api-v1.tcross
@@ -21,7 +21,7 @@ func Pages.ApiV1()
;
- return Components.Shell("Api V1",html,4);
+ return Components.Shell("Api V1",html,5);
}
var apiv1_routes = Json.Decode(embed("apiv1_routes.json").ToString());
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/changepassword.tcross b/Tesses.YouTubeDownloader.Server/src/pages/changepassword.tcross
index 5daf7d9..bb95c0e 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/changepassword.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/changepassword.tcross
@@ -45,5 +45,5 @@ const html =
;
- return Components.Shell("Change your password",html,3);
+ return Components.Shell("Change your password",html,4);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/channel/info.tcross b/Tesses.YouTubeDownloader.Server/src/pages/channel/info.tcross
index 12ec196..4049c44 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/channel/info.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/channel/info.tcross
@@ -35,5 +35,5 @@ func Pages.ChannelInfo(tytd,ctx)
title = res.authorName;
}
- return Components.Shell($"Channel {title}",html,1);
+ return Components.Shell($"Channel {title}",html,2);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/discover.tcross b/Tesses.YouTubeDownloader.Server/src/pages/discover.tcross
deleted file mode 100644
index c05faf2..0000000
--- a/Tesses.YouTubeDownloader.Server/src/pages/discover.tcross
+++ /dev/null
@@ -1,34 +0,0 @@
-func Pages.Discover(tytd,ctx)
-{
-
- var q = ctx.QueryParams.TryGetFirst("q");
- var res = null;
- var q2 = "";
- if(TypeOf(q) == "String")
- {
- q2 = q;
- res = tytd.Discover(q);
-
- }
-
- var html =
-
-
-
-
-
- ;
-
-
- return Components.Shell($"Discover {q2}",html,1);
-}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/downloads.tcross b/Tesses.YouTubeDownloader.Server/src/pages/downloads.tcross
index 15cd72c..83e6892 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/downloads.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/downloads.tcross
@@ -289,5 +289,5 @@ func Pages.Downloads(tytd,ctx)
- return Components.Shell($"Downloads {q}",html,1);
+ return Components.Shell($"Downloads {q}",html,2);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/edituser.tcross b/Tesses.YouTubeDownloader.Server/src/pages/edituser.tcross
index d0df2ad..03f3d5e 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/edituser.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/edituser.tcross
@@ -38,7 +38,7 @@ func Pages.EditUserList(tytd, ctx)
;
- return Components.Shell("Edit users",html, 3);
+ return Components.Shell("Edit users",html, 4);
}
func Pages.EditUser(user)
@@ -141,5 +141,5 @@ func Pages.EditUser(user)
;
- return Components.Shell("Edit user",html, 3);
+ return Components.Shell("Edit user",html, 4);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/list.tcross b/Tesses.YouTubeDownloader.Server/src/pages/list.tcross
index bb2659b..1c0d578 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/list.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/list.tcross
@@ -35,5 +35,5 @@ func Pages.List(tytd,ctx)
;
- return Components.Shell($"Personal List {name}",html,1);
+ return Components.Shell($"Personal List {name}",html,2);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/music/artist.tcross b/Tesses.YouTubeDownloader.Server/src/pages/music/artist.tcross
deleted file mode 100644
index 2107ed6..0000000
--- a/Tesses.YouTubeDownloader.Server/src/pages/music/artist.tcross
+++ /dev/null
@@ -1,25 +0,0 @@
-func Pages.Artist(music,ctx)
-{
-
- var id = ctx.QueryParams.TryGetFirst("id");
- var res = music.GetArtistsAlbums(id);
-
- if(TypeOf(id) != "String")
- {
- return Components.Shell("Error",Artist id not specified
,pages);
- }
-
-
- var html =
- {res.name}
-
- ;
-
-
- return Components.Shell($"Artist {res.name}",html,2);
-
-}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/music/artists.tcross b/Tesses.YouTubeDownloader.Server/src/pages/music/artists.tcross
deleted file mode 100644
index 100fadf..0000000
--- a/Tesses.YouTubeDownloader.Server/src/pages/music/artists.tcross
+++ /dev/null
@@ -1,33 +0,0 @@
-func Pages.Artists(music,ctx)
-{
-
- var q = ctx.QueryParams.TryGetFirst("q");
- var res = null;
- var q2 = "";
- if(TypeOf(q) == "String")
- {
- q2 = q;
- res = music.GetArtists(q);
-
- }
-
- var html =
-
-
-
-
- ;
-
-
- return Components.Shell($"Search Artists {q2}",html,2);
-}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/music/music.tcross b/Tesses.YouTubeDownloader.Server/src/pages/music/music.tcross
deleted file mode 100644
index 4da2516..0000000
--- a/Tesses.YouTubeDownloader.Server/src/pages/music/music.tcross
+++ /dev/null
@@ -1,8 +0,0 @@
-func Pages.Music(ctx)
-{
- var html = ;
- return Components.Shell("Music",html,2);
-}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/newaccount.tcross b/Tesses.YouTubeDownloader.Server/src/pages/newaccount.tcross
index 37aba13..9da9521 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/newaccount.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/newaccount.tcross
@@ -81,5 +81,5 @@ func Pages.NewUser(error)
;
- return Components.Shell("New User",html ,3);
+ return Components.Shell("New User",html ,4);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/personal-from-yt-temp.tcross b/Tesses.YouTubeDownloader.Server/src/pages/personal-from-yt-temp.tcross
index 710421c..33ad237 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/personal-from-yt-temp.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/personal-from-yt-temp.tcross
@@ -22,5 +22,5 @@ func Pages.YouTubeAnonyPlaylist(video_ids)
;
- return Components.Shell("Create playlist",html ,1);
+ return Components.Shell("Create playlist",html ,2);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/playlist/info.tcross b/Tesses.YouTubeDownloader.Server/src/pages/playlist/info.tcross
index 61b8408..b7c73c6 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/playlist/info.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/playlist/info.tcross
@@ -35,5 +35,5 @@ func Pages.PlaylistInfo(tytd,ctx)
title = res.authorName;
}
- return Components.Shell($"Playlist {title}",html,1);
+ return Components.Shell($"Playlist {title}",html,2);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/plugins-dl.tcross b/Tesses.YouTubeDownloader.Server/src/pages/plugins-dl.tcross
index 5c03a2f..73ddcb9 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/plugins-dl.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/plugins-dl.tcross
@@ -75,5 +75,5 @@ func Pages.DownloadPlugins(tytd,ctx)
;
- return Components.Shell("Download plugins",html ,2);
+ return Components.Shell("Download plugins",html ,3);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/plugins.tcross b/Tesses.YouTubeDownloader.Server/src/pages/plugins.tcross
index 7ff683c..b3eef41 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/plugins.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/plugins.tcross
@@ -20,5 +20,5 @@ func Pages.Plugins(tytd,ctx)
;
- return Components.Shell("Installed plugins", UserFlags.CanUsePlugins(userFlags) ? html :
You can{"'"}t use plugins
,2);
+ return Components.Shell("Installed plugins", UserFlags.CanUsePlugins(userFlags) ? html :
You can{"'"}t use plugins
,3);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/queue.tcross b/Tesses.YouTubeDownloader.Server/src/pages/queue.tcross
new file mode 100644
index 0000000..0a18ca6
--- /dev/null
+++ b/Tesses.YouTubeDownloader.Server/src/pages/queue.tcross
@@ -0,0 +1,71 @@
+
+func Pages.Queue(tytd,ctx)
+{
+ var page = ctx.QueryParams.TryGetFirstInt("page");
+ if(TypeOf(page) != "Long") page = 1;
+ page--;
+
+
+ enumerable func getitems()
+ {
+ each(var item : tytd.GetQueueItems(page,10))
+ {
+ tytd.PutVideoInfoIfNotExists(item.videoId);
+ const info = tytd.GetVideo(item.videoId);
+
+ yield {
+ Title = $"{info.title}-{item.videoId}-{item.resolution}",
+ VideoId = item.videoId,
+ Id = item.id,
+ ChannelId = info.channelId,
+ Channel = info.author
+ };
+ }
+ }
+
+
+ const html =
+
+
+
+
+
+
+
}"})
+
+
+
+
+ {item.Title}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ;
+ return Components.Shell("Queue",html,1);
+}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/settings.tcross b/Tesses.YouTubeDownloader.Server/src/pages/settings.tcross
index aa9d7a6..e34589a 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/settings.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/settings.tcross
@@ -15,5 +15,5 @@ func Pages.Settings(tytd,ctx)
;
- return Components.Shell("Settings",html ,3);
+ return Components.Shell("Settings",html ,4);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/video/info.tcross b/Tesses.YouTubeDownloader.Server/src/pages/video/info.tcross
index 0561be0..1412a17 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/video/info.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/video/info.tcross
@@ -27,5 +27,5 @@ func Pages.VideoInfo(tytd,ctx)
;
}
- return Components.Shell(vi != null ? vi.title : "Could not find video", html, 1);
+ return Components.Shell(vi != null ? vi.title : "Could not find video", html, 2);
}
\ No newline at end of file
diff --git a/Tesses.YouTubeDownloader.Server/src/pages/whoami.tcross b/Tesses.YouTubeDownloader.Server/src/pages/whoami.tcross
index b0102e2..6e2dc55 100644
--- a/Tesses.YouTubeDownloader.Server/src/pages/whoami.tcross
+++ b/Tesses.YouTubeDownloader.Server/src/pages/whoami.tcross
@@ -11,5 +11,5 @@ func Pages.WhoAmI(row)