Images may already be absolute paths

This commit is contained in:
Mouse Reeve 2021-04-28 17:18:14 -07:00
parent 8eec3eca5b
commit 95fce963d1

View file

@ -1,4 +1,6 @@
""" inventaire data connector """ """ inventaire data connector """
import re
from bookwyrm import models from bookwyrm import models
from .abstract_connector import AbstractConnector, SearchResult, Mapping from .abstract_connector import AbstractConnector, SearchResult, Mapping
from .abstract_connector import get_data from .abstract_connector import get_data
@ -148,11 +150,15 @@ class Connector(AbstractConnector):
"""format the relative cover url into an absolute one: """format the relative cover url into an absolute one:
{"url": "/img/entities/e794783f01b9d4f897a1ea9820b96e00d346994f"} {"url": "/img/entities/e794783f01b9d4f897a1ea9820b96e00d346994f"}
""" """
# covers may or may not be a list
if isinstance(cover_blob, list) and len(cover_blob) > 0: if isinstance(cover_blob, list) and len(cover_blob) > 0:
cover_blob = cover_blob[0] cover_blob = cover_blob[0]
cover_id = cover_blob.get("url") cover_id = cover_blob.get("url")
if not cover_id: if not cover_id:
return None return None
# cover may or may not be an absolute url already
if re.match(r"^http", cover_id):
return cover_id
return "%s%s" % (self.covers_url, cover_id) return "%s%s" % (self.covers_url, cover_id)
def resolve_keys(self, keys): def resolve_keys(self, keys):