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

Don't save current mainurl to Library #1486

Closed
2 tasks done
Luna712 opened this issue Jan 11, 2025 · 2 comments
Closed
2 tasks done

Don't save current mainurl to Library #1486

Luna712 opened this issue Jan 11, 2025 · 2 comments
Labels
enhancement New feature or request

Comments

@Luna712
Copy link
Contributor

Luna712 commented Jan 11, 2025

Describe your suggested feature

Instead it should only save provider and the URL suffix (not the main domain) and lookup the current url's main domain based on provider URL to let the provider handle it. As if mainUrl is changed it breaks existing entries.

We could handle backward compatibility too to make it work for existing entries by just parsing the URL parts and ignore the domain part and replace it with saved providers URL. As least in theory, I have not made any attempts at this yet.

Another theory I suppose could work is keep using mainurl but add something to UI like "Update cache" to recache the URL so it updates or some sort of expiry on it so it updates sometimes. Not exactly sure how to handle this as looking for the mainUrl in all providers could also have a negative performance impact.

I don't know if there is really a perfect solution to this either...

Other details

I will probably look at this later this is mostly just as a reminder for me.

Acknowledgements

  • My suggestion is NOT about adding a new provider
  • I have searched the existing issues and this is a new ticket, NOT a duplicate or related to another open issue.
@Luna712 Luna712 added the enhancement New feature or request label Jan 11, 2025
@fire-light42
Copy link
Collaborator

This should be up to the extension developer, as the url specified can and is often in other forms like json, or for other sites then the one specified by mainUrl. Because of this we can not reliably automate any sort of mechanism, however we can add a function like this to the api if needed.

/**
 * For APIs using the mainUrl in the prefix for `MainAPI::load`,
 * this function replaces the `scheme`, `host` and `port` from an old link to the new mainUrl. 
 *
 * https://en.wikipedia.org/wiki/Uniform_Resource_Identifier
 * ```text
 *           userinfo       host      port
 *           ┌──┴───┐ ┌──────┴──────┐ ┌┴─┐
 *   https://[email protected]:1234/forum/questions/?tag=networking&order=newest#:~:text=whatever
 *   └─┬─┘   └─────────────┬─────────────┘└───────┬───────┘ └────────────┬────────────┘ └───────┬───────┘
 *   scheme            authority                path                   query                 fragment
 * ```
 */
fun MainAPI.updateUrl(url: String): String {
    try {
        val original = URI(url)
        val updated = URI(mainUrl)

        // URI(String scheme, String userInfo, String host, int port, String path, String query, String fragment)
        return URI(
            updated.scheme,
            original.userInfo,
            updated.host,
            updated.port,
            original.path,
            original.query,
            original.fragment
        ).toString()
    } catch (t: Throwable) {
        logError(t)
        return url
    }
}

@Luna712
Copy link
Contributor Author

Luna712 commented Jan 21, 2025

That is actually probably the best solution for this indeed.

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

2 participants