This may not be a appropriate post for this community, and is not strictly web development. It is browser related, specifically qutebrowser, but i don’t think the behaviour is qutebrowser specific, it may be chromium specific though, but i don’t know how to test on any other browser because i hardly know js. If this is not valid for this community, please do tell.

I was writing a way to redirect other lemmy instance links to my home instance. I am basically trying to write lemmyverse.link (it’s working is explained in the following issue, but essentially we just ask the instance where we want to be redirected, if they have the post, if so, they return json, which will have post_id in that instance, and we can use that.

https://github.com/RikudouSage/lemmyverse.link/issues/14

I think I have implemented that somewhat successfully, and it works for all the instances that i have tried, except lemmy.world (why could it not be some tiny instance which i could ignore). For lemmy.world, browser ui shows as if it is loading. I checked dev tools, and we do get the redirection (see the post_id change below in the attched video, and when i click that, i get redirected to correct page). It shows a red errors, but i can not find how to find errors (none of tabs show any errors).

https://envs.sh/s/NhX_dHEZh52CD1MwcXXLwg/cSI.mkv

(the video show succesful redirection for some instance, and unsucceful redirection for other)

I hope someone who knows how to do this help, I could not find anything wrong, and hence am not able to even search for errors online.

code for anyone wanting to see it


import qutebrowser.api.interceptor
import re
import requests
import sys
def match(patterns, url):
    for pattern in patterns:
        if re.match(pattern, url):
            return True
    return False
with open('/home/sg/data/dev/program-data/lemmings_coookie_jwt', 'r') as f:
    cookie = f.read().strip()
def resolve_lemmings_object(query):
    url = "https://lemmings.world/api/v3/resolve_object"
    params = {"q": query}  # Pass the query as a parameter
    headers = { "Cookie": cookie}
    try:
        response = requests.get(url, params=params, headers=headers)
        response.raise_for_status()  # Raise HTTPError for bad responses (4xx or 5xx)
        return response.json()['post']['post']['id']
    except requests.exceptions.RequestException as e:
        print(f"Error: {e}")
        return None

def per_website_rules(request: qutebrowser.api.interceptor.Request):
	lemmy_patterns = [ r"crazypeople\.online", r"discuss\.online", r"discuss\.tchncs\.de", r"feddit\.nl", r"feddit\.org", r"feddit\.uk", r"jlai\.lu", r"lemm\.ee", r"lemmy\.blahaj\.zone", r"lemmy\.ca", r"lemmy\.cafe", r"lemmy\.dbzer0\.com", r"lemmy\.ml", r"lemmy\.one", r"lemmy\.run", r"lemmy\.selfhostcat\.com", r"lemmy\.wtf", r"lemmy\.zip", r"mander\.xyz", r"ponder\.cat", r"programming\.dev", r"sh\.itjust\.works", r"slrpnk\.net", r"sopuli\.xyz", r"toast\.ooo", r"lemmy\.world", r"spaffel\.social" ]
	post_pattern = [ r"^/post/.*$" ]
	if match(lemmy_patterns, request.request_url.host()) and match(post_pattern, request.request_url.path()):
		url = request.request_url.scheme() + "://" + request.request_url.host() + request.request_url.path()
		# post_id_in_my_prefered_instance = os.popen("lemmy-redirect " + url).read()
		post_id_in_my_prefered_instance = resolve_lemmings_object(url)
		request.request_url.setHost('lemmings.world')
		request.request_url.setPath('/post/' + str(post_id_in_my_prefered_instance))
		try:
			request.redirect(request.request_url)
		except:
			pass

  • sgaOP
    link
    fedilink
    English
    arrow-up
    1
    ·
    5 days ago

    I am not sure how, but somehow it seems to be working now. There is a possibility this is still not 100% working, but seems to be working for now.

    • sgaOP
      link
      fedilink
      English
      arrow-up
      1
      ·
      3 days ago

      And it came back after a few hours of working. Thhinking I may be hitting some rate limits, avoided using it for a day, and still does not work.