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: Add fallback to Bunny URLs if main URLs are not accessible #781

Merged
merged 10 commits into from
Jun 14, 2024

Conversation

TanmayDhobale
Copy link
Contributor

PR Fixes: #776

This PR adds a new feature to the ContentRenderer component that checks if the main video URLs from the database are accessible or not. If any of the main URLs are not accessible, it falls back to using the Bunny URLs instead.

Changes:

  1. Added a new helper function isUrlAccessible that makes a HEAD request to a given URL and returns a boolean indicating whether the URL is accessible or not.

  2. Modified the getMetadata function:

    • If the user.bunnyProxyEnabled flag is true, it returns the Bunny URLs directly.
    • If bunnyProxyEnabled is false, it creates an object mainUrls containing the main URLs from the database.
    • It then uses Promise.all and the isUrlAccessible function to check if all the main URLs are accessible.
    • If all main URLs are accessible, it returns mainUrls.
    • If any of the main URLs is not accessible, it returns the Bunny URLs instead.

This change ensures that if the main video URLs are not accessible for any reason, the application falls back to using the Bunny URLs, providing a more reliable experience for users.

Checklist before requesting a review

  • I have performed a self-review of my code
  • I assure there is no similar/duplicate pull request regarding same issue

@TanmayDhobale
Copy link
Contributor Author

@hkirat This approach is right ? like rn it makes HEAD requests to all the main URLs, which could potentially cause performance issues if there are many URLs to check Instead of checking the accessibility of all main URLs (1080p, 720p, and 360p) by making individual HEAD requests for each URL we can only checks the accessibility of the highest quality video URL (1080p).

@siinghd
Copy link
Collaborator

siinghd commented Jun 13, 2024

@hkirat This approach is right ? like rn it makes HEAD requests to all the main URLs, which could potentially cause performance issues if there are many URLs to check Instead of checking the accessibility of all main URLs (1080p, 720p, and 360p) by making individual HEAD requests for each URL we can only checks the accessibility of the highest quality video URL (1080p).

This should work fine, but can you implement a fallback mechanism that attempts to check other urls only if necessary?

what i mean is:

1- check the highest quality url first, if available return mainurls if not
2- check for 720 and 360, if 720 available return mainurls, if not check for 360, if 360 available return mainurls else return bunnyurls

@TanmayDhobale
Copy link
Contributor Author

@hkirat This approach is right ? like rn it makes HEAD requests to all the main URLs, which could potentially cause performance issues if there are many URLs to check Instead of checking the accessibility of all main URLs (1080p, 720p, and 360p) by making individual HEAD requests for each URL we can only checks the accessibility of the highest quality video URL (1080p).

This should work fine, but can you implement a fallback mechanism that attempts to check other urls only if necessary?

what i mean is:

1- check the highest quality url first, if available return mainurls if not
2- check for 720 and 360, if 720 available return mainurls, if not check for 360, if 360 available return mainurls else return bunnyurls

Yeah sure, let me do that. ( We got a new maintainer before GTA 6)

@TanmayDhobale
Copy link
Contributor Author

@siinghd done

@siinghd
Copy link
Collaborator

siinghd commented Jun 13, 2024

@TanmayDhobale

still the same thing

here:

if (user.bunnyProxyEnabled) {
    return {
      1080: bunnyUrl(metadata[`video_1080p_mp4_${userId}`]),
      720: bunnyUrl(metadata[`video_720p_mp4_${userId}`]),
      360: bunnyUrl(metadata[`video_360p_mp4_${userId}`]),
      subtitles: metadata['subtitles'],
      slides: metadata['slides'],
      segments: metadata['segments'],
      thumbnails: metadata['thumbnail_mosiac_url'],
    };
  }
  
  this is duplicate

{
1080: bunnyUrl(metadata[video_1080p_mp4_${userId}]),
720: bunnyUrl(metadata[video_720p_mp4_${userId}]),
360: bunnyUrl(metadata[video_360p_mp4_${userId}]),
subtitles: metadata['subtitles'],
slides: metadata['slides'],
segments: metadata['segments'],
thumbnails: metadata['thumbnail_mosiac_url'],
};


@siinghd
Copy link
Collaborator

siinghd commented Jun 13, 2024

Move const bunnyUrls = {

above


if (user.bunnyProxyEnabled) {
    return {
      1080: bunnyUrl(metadata[`video_1080p_mp4_${userId}`]),
      720: bunnyUrl(metadata[`video_720p_mp4_${userId}`]),
      360: bunnyUrl(metadata[`video_360p_mp4_${userId}`]),
      subtitles: metadata['subtitles'],
      slides: metadata['slides'],
      segments: metadata['segments'],
      thumbnails: metadata['thumbnail_mosiac_url'],
    };
  }
  
  and do 
  
  if (user.bunnyProxyEnabled) {
    return bunnyUrls
  }

@TanmayDhobale
Copy link
Contributor Author

@siinghd

@siinghd
Copy link
Collaborator

siinghd commented Jun 14, 2024

Merging Thank you, will submit this pr, if it will satisfy bounty requirements, you will get it

@siinghd siinghd merged commit a198c79 into code100x:main Jun 14, 2024
1 check failed
@TanmayDhobale
Copy link
Contributor Author

Merging Thank you, will submit this pr, if it will satisfy bounty requirements, you will get it

sure 👍

@hkirat
Copy link
Contributor

hkirat commented Jul 31, 2024

/bounty $30

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.

feature: Fallback to bunny URL if main url doesnt work for a user
3 participants