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

feat: support Invidious image proxy endpoints #257

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hikiko4ern
Copy link

@hikiko4ern hikiko4ern commented Nov 11, 2024

So, this is an attempt to add support for Invidious-specific image endpoints.
I marked PR as a draft because I have some questions about expected behavior.

closes #111

@@ -183,6 +133,13 @@ async fn index(req: HttpRequest) -> Result<HttpResponse, Box<dyn Error>> {
return Ok(response.finish());
}

#[cfg(feature = "invidious")]
if matches!(req.path().get(0..4), Some("/vi/") | Some("/sb/")) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should Invidious endpoints be backwards compatible with Piped? For example, both Invidious and Piped can download video previews via /vi/, but Piped requests them with query (/vi/MYSQe4uuSOA/hq720.jpg?host=i.ytimg.com&qhash=...&rs=...&sqp=...) while Invidious requests them without query (/vi/MYSQe4uuSOA/mqdefault.jpg).

With the current approach they are not backwards compatible, so if a Piped client sends a request to a proxy with invidious feature enabled, qhash and other parameters will not be used and validated. This allows avoiding unnecessary checks for instances running only Piped or only Invidious, but will cause problems for instances running both.

If they need to be backwards compatible, a check that the query is empty could be added here, for example.

};

#[cfg(feature = "avif")]
if content_type == "image/webp" || content_type == "image/jpeg" && avif {
Copy link
Author

@hikiko4ern hikiko4ern Nov 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this check supposed to be like that?

Suggested change
if content_type == "image/webp" || content_type == "image/jpeg" && avif {
if (content_type == "image/webp" || content_type == "image/jpeg") && avif {

Now image/webp is always transcoded regardless of the presence of avif in the query, because this check is computed as

if content_type == "image/webp" || (content_type == "image/jpeg" && avif) {

image_response: Response,
http_response: &mut HttpResponseBuilder,
#[cfg(feature = "avif")] avif: bool,
) -> Result<Either<HttpResponse, Response>, Box<dyn std::error::Error>> {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What behavior is expected in case of transcoding errors? Should the server return 500 Internal Server Error (as it is now) or the original image?

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

Successfully merging this pull request may close these issues.

Support Invidious endpoints
1 participant