mirror of
https://github.com/benbusby/farside.git
synced 2025-05-04 17:40:02 +00:00
Auto select frontend for links to "parent" service
Farside now supports redirecting based on a provided link to a "parent" service, if such a parent service is supported. For example, a link such as: farside.link/https://www.youtube.com/watch?v=dQw4w9WgXcQ will now redirect to any of the available YouTube related frontends. This works by matching against a mapping of "parent" service domains ("youtube.com", "reddit.com", etc) to a list of their respective frontend alternatives (["invidious", "piped"], ["libreddit", "teddit"], etc). A random element is chosen from this list, and the remainder of Farside's routing logic proceeds as if the user had chosen the service directly to begin with. Closes #37
This commit is contained in:
parent
ff8d220e90
commit
5006b97dfa
4 changed files with 88 additions and 3 deletions
|
@ -39,12 +39,27 @@ defmodule Farside.Router do
|
|||
end
|
||||
|
||||
get "/:service/*glob" do
|
||||
path = Enum.join(glob, "/")
|
||||
service_name = cond do
|
||||
service =~ "http" ->
|
||||
List.first(glob)
|
||||
true ->
|
||||
service
|
||||
end
|
||||
|
||||
path = cond do
|
||||
service_name != service ->
|
||||
Enum.join(Enum.slice(glob, 1..-1), "/")
|
||||
true ->
|
||||
Enum.join(glob, "/")
|
||||
end
|
||||
|
||||
instance = cond do
|
||||
conn.assigns[:throttle] != nil ->
|
||||
Farside.last_instance(service)
|
||||
Farside.get_service(service_name)
|
||||
|> Farside.last_instance
|
||||
true ->
|
||||
Farside.pick_instance(service)
|
||||
Farside.get_service(service_name)
|
||||
|> Farside.pick_instance
|
||||
end
|
||||
|
||||
params =
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue