Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
Fix redirect URLs clashing with each other (#163)
Browse files Browse the repository at this point in the history
  • Loading branch information
kuylar authored Aug 15, 2024
1 parent 3e36eea commit 51c5ecc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
24 changes: 18 additions & 6 deletions LightTube/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System.Text;
using InnerTube;
using InnerTube.Protobuf.Responses;
using LightTube.Contexts;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Net.Http.Headers;
using Endpoint = InnerTube.Protobuf.Endpoint;

namespace LightTube.Controllers;

public class HomeController(ILogger<HomeController> logger) : Controller
public class HomeController(SimpleInnerTubeClient innerTube) : Controller
{
private readonly ILogger<HomeController> _logger = logger;

public IActionResult Index() => View(new HomepageContext(HttpContext));

[Route("/rss")]
Expand Down Expand Up @@ -53,9 +54,20 @@ public IActionResult DismissAlert(string redirectUrl)
return Redirect(redirectUrl);
}

[Route("/{videoId:regex([[a-zA-Z0-9-_]]{{11}})}")]
public IActionResult VideoRedirect(string videoId)
[Route("/{str}")]
public async Task<IActionResult> AutoRedirect(string str)
{
return Redirect($"/watch?v={videoId}");
if (str.StartsWith('@'))
{
ResolveUrlResponse endpoint = await innerTube.ResolveUrl("https://youtube.com/" + str);
return Redirect(endpoint.Endpoint.EndpointTypeCase == Endpoint.EndpointTypeOneofCase.BrowseEndpoint
? $"/channel/{endpoint.Endpoint.BrowseEndpoint.BrowseId}"
: "/");
}

if (str.Length == 11)
return Redirect($"/watch?v={str}");

return Redirect("/");
}
}
9 changes: 0 additions & 9 deletions LightTube/Controllers/YoutubeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,6 @@ public async Task<IActionResult> ChannelFromVanity(string vanity)
: "/");
}

[Route("/@{handle}")]
public async Task<IActionResult> ChannelFromHandle(string handle)
{
ResolveUrlResponse endpoint = await innerTube.ResolveUrl("https://youtube.com/@" + handle);
return Redirect(endpoint.Endpoint.EndpointTypeCase == Endpoint.EndpointTypeOneofCase.BrowseEndpoint
? $"/channel/{endpoint.Endpoint.BrowseEndpoint.BrowseId}"
: "/");
}

[Route("/channel/{id}")]
public async Task<IActionResult> Channel(string id, string? continuation = null) =>
await Channel(id, ChannelTabs.Featured, continuation);
Expand Down

0 comments on commit 51c5ecc

Please sign in to comment.