]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Tue, 13 Jun 2023 09:19:23 +0000 (11:19 +0200)
committerRoland Häder <roland@mxchange.org>
Tue, 13 Jun 2023 09:19:23 +0000 (11:19 +0200)
- added 'software' as optional parameter to instances.add()
- also prevent bad invocations when a link to a user profile has provided

fba/federation.py
fba/models/instances.py

index 118c45dd4d8de200527e90fd15902a8f9f5b46a4..941b192b8ae79646f5a3e6930602d6293f2c05f7 100644 (file)
@@ -69,7 +69,9 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path:
     elif domain.endswith(".arpa"):
         print(f"WARNING: domain='{domain}' is a reversed .arpa domain and should not be used generally.")
         return
-    elif not instances.is_registered(domain):
+    elif not validators.domain(domain):
+        raise ValueError(f"domain='{domain}' is not a valid domain")
+    elif not instances.is_registered(domain.split("/")[0]):
         # DEBUG: print("DEBUG: Adding new domain:", domain, origin)
         instances.add(domain, origin, command, path)
 
@@ -114,6 +116,9 @@ def fetch_instances(domain: str, origin: str, software: str, command: str, path:
         if instance.endswith(".arpa"):
             print(f"WARNING: instance='{instance}' is a reversed .arpa domain and should not be used generally.")
             continue
+        elif instance.find("/profile/") > 0 or instance.find("/users/") > 0:
+            print(f"DEBUG: instance='{instance}' is a link to a single user profile - SKIPPED!")
+            continue
         elif not instances.is_registered(instance):
             # DEBUG: print("DEBUG: Adding new instance:", instance, domain)
             instances.add(instance, domain, command)
index 91c4722554c0805a08bf5edd642d76022fffa27b..154dbfacdb1ce05dfec9750e61bebfc8e7916740 100644 (file)
@@ -146,8 +146,8 @@ def update_data(domain: str):
 
     # DEBUG: print("DEBUG: EXIT!")
 
-def add(domain: str, origin: str, command: str, path: str = None):
-    # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',command='{command}',path='{path}' - CALLED!")
+def add(domain: str, origin: str, command: str, path: str = None, software: str = None):
+    # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',command='{command}',path='{path}',software='{software}' - CALLED!")
     if not isinstance(domain, str):
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
@@ -162,21 +162,29 @@ def add(domain: str, origin: str, command: str, path: str = None):
         raise ValueError("Parameter 'command' is empty")
     elif not validators.domain(domain.split("/")[0]):
         raise ValueError(f"Bad domain name='{domain}'")
+    elif not isinstance(path, str) and path is not None:
+        raise ValueError(f"path[]='{type(path)}' is not 'str'")
+    elif path == "":
+        raise ValueError("Parameter 'path' is empty")
+    elif not isinstance(software, str) and software is not None:
+        raise ValueError(f"software[]='{type(software)}' is not 'str'")
+    elif software == "":
+        raise ValueError("Parameter 'software' is empty")
     elif domain.endswith(".arpa"):
         raise ValueError(f"Please don't crawl .arpa domains: domain='{domain}'")
     elif origin is not None and not validators.domain(origin.split("/")[0]):
         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:
+    elif domain.find("/profile/") > 0 or domain.find("/users/") > 0 or (software == "lemmy" and domain.find("/c/") > 0):
         raise Exception(f"domain='{domain}' is a single user")
 
-    software = None
-    try:
-        # DEBUG: print("DEBUG: domain,origin,command,path:", domain, origin, command, path)
-        software = federation.determine_software(domain, path)
-    except network.exceptions as exception:
-        print(f"WARNING Exception '{type(exception)}' during determining software type")
+    if isinstance(software, str):
+        try:
+            # DEBUG: print("DEBUG: domain,origin,command,path:", domain, origin, command, path)
+            software = federation.determine_software(domain, path)
+        except network.exceptions as exception:
+            print(f"WARNING Exception '{type(exception)}' during determining software type")
 
     # DEBUG: print("DEBUG: Determined software:", software)
     if software == "lemmy" and domain.find("/c/") > 0: