Skip to content

Commit

Permalink
Fix human-readable name for ImageMetadata
Browse files Browse the repository at this point in the history
The Webpage Capture boefje creates images from HostnameHTTPURL OOIs,
which means that after the normalizer creates an ImageMetadata OOI
its reference points to a HostnameHTTPURL OOI instead of an HTTPResource
OOI. #1560 was created to fix this, but for
now we can fix the human-readable name by trying to the reference as a
HTTPResource first and HostnameHTTPURL if this fails.

This fixes the "IndexError at /en/mispoes/objects/, pop from empty list"
error.
  • Loading branch information
praseodym committed Aug 7, 2023
1 parent 8a49ba4 commit f48753b
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions octopoes/octopoes/models/ooi/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,18 +219,24 @@ class ImageMetadata(OOI):

@classmethod
def format_reference_human_readable(cls, reference: Reference) -> str:
t = reference.tokenized

port = f":{t.resource.web_url.port}" if t.resource.web_url.port else ""
try:
netloc = t.resource.web_url.netloc.address
except KeyError:
netloc = t.resource.web_url.netloc.name

web_url = f"{t.resource.web_url.scheme}://{netloc}{port}{t.resource.web_url.path}"
address = t.resource.website.ip_service.ip_port.address.address

return f"{web_url} @ {address}"
t = reference.tokenized

port = f":{t.resource.web_url.port}" if t.resource.web_url.port else ""
try:
netloc = t.resource.web_url.netloc.address
except KeyError:
netloc = t.resource.web_url.netloc.name

web_url = f"{t.resource.web_url.scheme}://{netloc}{port}{t.resource.web_url.path}"
address = t.resource.website.ip_service.ip_port.address.address

return f"{web_url} @ {address}"
except IndexError:
# try parsing reference as a HostnameHTTPURL instead
tokenized = HostnameHTTPURL.get_tokenized_primary_key(reference.natural_key)
port = f":{tokenized.port}" if tokenized.port else ""
return f"{tokenized.scheme}://{tokenized.netloc.name}{port}{tokenized.path}"


class RESTAPI(OOI):
Expand Down

0 comments on commit f48753b

Please sign in to comment.