mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-25 19:11:09 +00:00
parent
aee8dc16af
commit
e0decbfd1d
1 changed files with 10 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
from uuid import uuid4
|
from uuid import uuid4
|
||||||
|
from urllib.parse import urlparse, unquote
|
||||||
|
|
||||||
from boto3.session import Session as BotoSession
|
from boto3.session import Session as BotoSession
|
||||||
from s3_tar import S3Tar
|
from s3_tar import S3Tar
|
||||||
|
@ -97,6 +98,12 @@ class BookwyrmExportJob(ParentJob):
|
||||||
self.complete_job()
|
self.complete_job()
|
||||||
|
|
||||||
|
|
||||||
|
def url2relativepath(url: str) -> str:
|
||||||
|
"""turn an absolute URL into a relative filesystem path"""
|
||||||
|
parsed = urlparse(url)
|
||||||
|
return unquote(parsed.path[1:])
|
||||||
|
|
||||||
|
|
||||||
class AddBookToUserExportJob(ChildJob):
|
class AddBookToUserExportJob(ChildJob):
|
||||||
"""append book metadata for each book in an export"""
|
"""append book metadata for each book in an export"""
|
||||||
|
|
||||||
|
@ -112,9 +119,9 @@ class AddBookToUserExportJob(ChildJob):
|
||||||
book["edition"] = self.edition.to_activity()
|
book["edition"] = self.edition.to_activity()
|
||||||
|
|
||||||
if book["edition"].get("cover"):
|
if book["edition"].get("cover"):
|
||||||
# change the URL to be relative to the JSON file
|
book["edition"]["cover"]["url"] = url2relativepath(
|
||||||
filename = book["edition"]["cover"]["url"].rsplit("/", maxsplit=1)[-1]
|
book["edition"]["cover"]["url"]
|
||||||
book["edition"]["cover"]["url"] = f"covers/{filename}"
|
)
|
||||||
|
|
||||||
# authors
|
# authors
|
||||||
book["authors"] = []
|
book["authors"] = []
|
||||||
|
|
Loading…
Reference in a new issue