Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect to random healthy instance #6

Open
craftyguy opened this issue Feb 23, 2021 · 2 comments
Open

Redirect to random healthy instance #6

craftyguy opened this issue Feb 23, 2021 · 2 comments
Labels
enhancement New feature or request

Comments

@craftyguy
Copy link

I've noticed a few instances going offline or slowing down substantially over the last few weeks, and I suspect it might be because users are picking the top healthy instance on the current redirect page. This surge may resource/load issues on that one instance.

What if this redirected to a random healthy instance that would have normally been shown towards the top of the list on the page today? This could be something similar, in theory, to how other load balancers work.

If you still wanted to show a list so users could manually override this behavior, show the current list with a timed redirect to a random instance after some number of seconds. (this particular part might not work without JS though..?)

@Kreyren
Copy link

Kreyren commented Jun 29, 2021

Created proof-of-concept redirect in rustlang that doesn't depend on javascript

use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer, Responder};

async fn redirect() -> impl Responder {
	HttpResponse::MovedPermanently()
		.set_header(
			actix_web::http::header::LOCATION,
			"https://snopyta.org",
		)
		.finish()
}

#[actix_web::main]
async fn main() -> std::io::Result<()> {
	HttpServer::new(|| {
		App::new()
			.route("/", web::get().to(redirect))
	})
	.bind(("127.0.0.1", 8080))?
	.run()
	.await
}

@sethidden
Copy link

sethidden commented May 13, 2024

Doable with Tampermonkey script for now:

// ==UserScript==
// @name         Redirect Invidious Feeling Lucky
// @description  Redirect to random Invidious instance that has 100% uptime when visiting redirect.invidious.io
// @namespace    http://tampermonkey.net/
// @version      2024-05-13
// @author       sethidden
// @match        https://redirect.invidious.io/*
// @grant        none
// ==/UserScript==

const interval = setInterval(() => {
    const table = [...document.querySelector('tbody').children];
    if(table[0].className === 'loading') return;

    clearInterval(interval);

    const buttonsWith100Uptime = table
        .reduce(
            (acc, { children: [,,health,buttonContainer] }) =>
                health.textContent === "100"
                  ? [...acc, buttonContainer.children[0]]
                  : acc,
            []
        )

    const randomIndex = Math.floor(Math.random()*1000 % buttonsWith100Uptime.length);

    buttonsWith100Uptime[randomIndex].click();
}, 200)

then go to e.g.: https://redirect.invidious.io/search?q=chocolate+rain

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants