Merge branch 'sized-deletion' into 'develop'
Sized deletion See merge request funkwhale/funkwhale!1210
This commit is contained in:
commit
6bd77f24d6
|
@ -2,6 +2,7 @@ import click
|
||||||
|
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from django.core.files.storage import default_storage
|
||||||
|
|
||||||
from versatileimagefield.image_warmer import VersatileImageFieldWarmer
|
from versatileimagefield.image_warmer import VersatileImageFieldWarmer
|
||||||
from versatileimagefield import settings as vif_settings
|
from versatileimagefield import settings as vif_settings
|
||||||
|
@ -19,13 +20,23 @@ def media():
|
||||||
|
|
||||||
|
|
||||||
@media.command("generate-thumbnails")
|
@media.command("generate-thumbnails")
|
||||||
def generate_thumbnails():
|
@click.option("-d", "--delete", is_flag=True)
|
||||||
|
def generate_thumbnails(delete):
|
||||||
"""
|
"""
|
||||||
Generate thumbnails for all images (avatars, covers, etc.).
|
Generate thumbnails for all images (avatars, covers, etc.).
|
||||||
|
|
||||||
This can take a long time and generate a lot of I/O depending of the size
|
This can take a long time and generate a lot of I/O depending of the size
|
||||||
of your library.
|
of your library.
|
||||||
"""
|
"""
|
||||||
|
click.echo("Deleting existing thumbnails…")
|
||||||
|
if delete:
|
||||||
|
try:
|
||||||
|
# FileSystemStorage doesn't support deleting a non-empty directory
|
||||||
|
# so we reimplemented a method to do so
|
||||||
|
default_storage.force_delete("__sized__")
|
||||||
|
except AttributeError:
|
||||||
|
# backends doesn't support directory deletion
|
||||||
|
pass
|
||||||
MODELS = [
|
MODELS = [
|
||||||
(Attachment, "file", "attachment_square"),
|
(Attachment, "file", "attachment_square"),
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
import slugify
|
import slugify
|
||||||
|
|
||||||
from django.core.files.storage import FileSystemStorage
|
from django.core.files.storage import FileSystemStorage
|
||||||
|
@ -15,6 +17,16 @@ class ASCIIFileSystemStorage(FileSystemStorage):
|
||||||
def get_valid_name(self, name):
|
def get_valid_name(self, name):
|
||||||
return super().get_valid_name(asciionly(name))
|
return super().get_valid_name(asciionly(name))
|
||||||
|
|
||||||
|
def force_delete(self, name):
|
||||||
|
path = self.path(name)
|
||||||
|
try:
|
||||||
|
if os.path.isdir(path):
|
||||||
|
shutil.rmtree(path)
|
||||||
|
else:
|
||||||
|
return super().delete(name)
|
||||||
|
except FileNotFoundError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ASCIIS3Boto3Storage(S3Boto3Storage):
|
class ASCIIS3Boto3Storage(S3Boto3Storage):
|
||||||
def get_valid_name(self, name):
|
def get_valid_name(self, name):
|
||||||
|
|
|
@ -251,6 +251,10 @@ def process_upload(upload, update_denormalization=True):
|
||||||
fail_import(upload, "unknown_error")
|
fail_import(upload, "unknown_error")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
broadcast = getter(
|
||||||
|
internal_config, "funkwhale", "config", "broadcast", default=True
|
||||||
|
)
|
||||||
|
|
||||||
# under some situations, we want to skip the import (
|
# under some situations, we want to skip the import (
|
||||||
# for instance if the user already owns the files)
|
# for instance if the user already owns the files)
|
||||||
owned_duplicates = get_owned_duplicates(upload, track)
|
owned_duplicates = get_owned_duplicates(upload, track)
|
||||||
|
@ -266,6 +270,7 @@ def process_upload(upload, update_denormalization=True):
|
||||||
upload.save(
|
upload.save(
|
||||||
update_fields=["import_details", "import_status", "import_date", "track"]
|
update_fields=["import_details", "import_status", "import_date", "track"]
|
||||||
)
|
)
|
||||||
|
if broadcast:
|
||||||
signals.upload_import_status_updated.send(
|
signals.upload_import_status_updated.send(
|
||||||
old_status=old_status,
|
old_status=old_status,
|
||||||
new_status=upload.import_status,
|
new_status=upload.import_status,
|
||||||
|
@ -308,9 +313,6 @@ def process_upload(upload, update_denormalization=True):
|
||||||
track.album, source=final_metadata.get("upload_source"),
|
track.album, source=final_metadata.get("upload_source"),
|
||||||
)
|
)
|
||||||
|
|
||||||
broadcast = getter(
|
|
||||||
internal_config, "funkwhale", "config", "broadcast", default=True
|
|
||||||
)
|
|
||||||
if broadcast:
|
if broadcast:
|
||||||
signals.upload_import_status_updated.send(
|
signals.upload_import_status_updated.send(
|
||||||
old_status=old_status,
|
old_status=old_status,
|
||||||
|
|
Loading…
Reference in New Issue