# written to database. Both arrays must be filled at the same time or else
# update_data() will fail
_pending = {
- # Detection mode: 'AUTO_DISCOVERY', 'STATIC_CHECKS' or 'GENERATOR'
+ # Detection mode
# NULL means all detection methods have failed (maybe still reachable instance)
"detection_mode" : {},
# Found nodeinfo URL
def add(domain: str, origin: str, command: str, path: str = None, software: str = None):
logger.debug("domain='%s',origin='%s',command='%s',path='%s',software='%s' - CALLED!", domain, origin, command, path, software)
domain_helper.raise_on(domain)
+
if not isinstance(origin, str) and origin is not None:
raise ValueError(f"origin[]='{type(origin)}' is not 'str'")
elif origin == "":
raise ValueError(f"Bad origin name='{origin}'")
elif blacklist.is_blacklisted(domain):
raise Exception(f"domain='{domain}' is blacklisted, but method invoked")
- elif domain.find("/profile/") > 0 or domain.find("/users/") > 0 or (software == "lemmy" and domain.find("/c/") > 0):
+ elif domain.find("/profile/") > 0 or domain.find("/users/") > 0 or (is_registered(domain.split("/")[0]) and domain.find("/c/") > 0):
raise Exception(f"domain='{domain}' is a single user")
+ elif domain.find("/tag/") > 0:
+ raise Exception(f"domain='{domain}' is a tag")
if software is None:
try:
logger.debug("Marking domain='%s' as registered.", domain)
cache.set_sub_key("is_registered", domain, True)
+ logger.debug("Checking if domain='%s' has pending updates ...", domain)
if has_pending(domain):
- logger.debug("domain='%s' has pending nodeinfo being updated ...", domain)
+ logger.debug("Flushing updates for domain='%s' ...", domain)
update_data(domain)
logger.debug("EXIT!")
logger.debug("EXIT!")
+def set_success(domain: str):
+ logger.debug("domain='%s' - CALLED!", domain)
+ domain_helper.raise_on(domain)
+
+ # Set both to success
+ _set_data("last_status_code" , domain, 200)
+ _set_data("last_error_details", domain, None)
+
+ logger.debug("EXIT!")
+
def is_registered(domain: str) -> bool:
logger.debug("domain='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
logger.debug("registered='%s' - EXIT!", registered)
return registered
-def is_recent(domain: str) -> bool:
- logger.debug("domain='%s' - CALLED!", domain)
+def is_recent(domain: str, column: str = "last_instance_fetch") -> bool:
+ logger.debug("domain='%s',column='%s' - CALLED!", domain)
domain_helper.raise_on(domain)
- if not is_registered(domain):
+
+ if not isinstance(column, str):
+ raise ValueError(f"Parameter column[]='{type(column)}' is not 'str'")
+ elif column not in ["last_instance_fetch", "last_blocked"]:
+ raise ValueError(f"Parameter column='{column}' is not expected")
+ elif not is_registered(domain):
logger.debug("domain='%s' is not registered, returning False - EXIT!", domain)
return False
# Query database
- database.cursor.execute("SELECT last_instance_fetch FROM instances WHERE domain = ? LIMIT 1", [domain])
+ database.cursor.execute(f"SELECT {column} FROM instances WHERE domain = ? LIMIT 1", [domain])
# Fetch row
fetched = database.cursor.fetchone()[0]
domain_helper.raise_on(domain)
if not isinstance(peers, list):
- raise ValueError(f"Parameter peers[]='{type(peers)}' is not 'list'")
+ raise ValueError(f"Parameter peers[]='{type(peers)}' is not 'list': '%s'")
# Set timestamp
_set_data("total_peers", domain, len(peers))