diff --git a/.env.example b/.env.example index 1bf6d5406..ee2ccd45a 100644 --- a/.env.example +++ b/.env.example @@ -71,6 +71,9 @@ ENABLE_THUMBNAIL_GENERATION=true USE_S3=false AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= +# seconds for signed S3 urls to expire +# this is currently only used for user export files +S3_SIGNED_URL_EXPIRY=900 # Commented are example values if you use a non-AWS, S3-compatible service # AWS S3 should work with only AWS_STORAGE_BUCKET_NAME and AWS_S3_REGION_NAME diff --git a/bookwyrm/settings.py b/bookwyrm/settings.py index 77bec0d8e..d2ba490b7 100644 --- a/bookwyrm/settings.py +++ b/bookwyrm/settings.py @@ -375,6 +375,7 @@ if USE_HTTPS: USE_S3 = env.bool("USE_S3", False) USE_AZURE = env.bool("USE_AZURE", False) +S3_SIGNED_URL_EXPIRY = env.int("S3_SIGNED_URL_EXPIRY", 900) if USE_S3: # AWS settings diff --git a/bookwyrm/views/preferences/export.py b/bookwyrm/views/preferences/export.py index 54d6df261..09b43155b 100644 --- a/bookwyrm/views/preferences/export.py +++ b/bookwyrm/views/preferences/export.py @@ -146,7 +146,12 @@ class Export(View): # pylint: disable=no-self-use @method_decorator(login_required, name="dispatch") class ExportUser(View): - """Let users export user data to import into another Bookwyrm instance""" + """ + Let users export user data to import into another Bookwyrm instance + This view creates signed URLs to pre-processed export files in + s3 storage on load (if they exist) and allows the user to create + a new file. + """ def get(self, request): """Request tar file""" @@ -166,8 +171,10 @@ class ExportUser(View): # for s3 we download directly from s3, so we need a signed url export["url"] = S3Boto3Storage.url( - storage, f"/exports/{job.task_id}.tar.gz", expire=900 - ) # temporarily downloadable file, expires after 5 minutes + storage, + f"/exports/{job.task_id}.tar.gz", + expire=settings.S3_SIGNED_URL_EXPIRY, + ) # for s3 we create a new tar file in s3, # so we need to check the size of _that_ file @@ -207,7 +214,7 @@ class ExportUser(View): return TemplateResponse(request, "preferences/export-user.html", data) def post(self, request): - """Download the json file of a user's data""" + """Trigger processing of a new user export file""" job = BookwyrmExportJob.objects.create(user=request.user) job.start_job()