Consistent naming to Share Link Bundle

This commit is contained in:
shamoon
2025-11-05 17:24:23 -08:00
parent c5ec073a5b
commit 931e2321b3
24 changed files with 283 additions and 271 deletions

View File

@@ -43,8 +43,8 @@ from documents.models import CustomFieldInstance
from documents.models import Document
from documents.models import DocumentType
from documents.models import PaperlessTask
from documents.models import ShareBundle
from documents.models import ShareLink
from documents.models import ShareLinkBundle
from documents.models import StoragePath
from documents.models import Tag
from documents.models import Workflow
@@ -572,17 +572,19 @@ def update_document_parent_tags(tag: Tag, new_parent: Tag) -> None:
@shared_task
def build_share_bundle(bundle_id: int):
def build_share_link_bundle(bundle_id: int):
try:
bundle = (
ShareBundle.objects.filter(pk=bundle_id).prefetch_related("documents").get()
ShareLinkBundle.objects.filter(pk=bundle_id)
.prefetch_related("documents")
.get()
)
except ShareBundle.DoesNotExist:
logger.warning("Share bundle %s no longer exists.", bundle_id)
except ShareLinkBundle.DoesNotExist:
logger.warning("Share link bundle %s no longer exists.", bundle_id)
return
bundle.remove_file()
bundle.status = ShareBundle.Status.PROCESSING
bundle.status = ShareLinkBundle.Status.PROCESSING
bundle.last_error = ""
bundle.size_bytes = None
bundle.built_at = None
@@ -617,7 +619,7 @@ def build_share_bundle(bundle_id: int):
for document in documents:
strategy.add_document(document)
output_dir = settings.SHARE_BUNDLE_DIR
output_dir = settings.SHARE_LINK_BUNDLE_DIR
output_dir.mkdir(parents=True, exist_ok=True)
final_path = (output_dir / f"{bundle.slug}.zip").resolve()
if final_path.exists():
@@ -629,7 +631,7 @@ def build_share_bundle(bundle_id: int):
except ValueError:
bundle.file_path = str(final_path)
bundle.size_bytes = final_path.stat().st_size
bundle.status = ShareBundle.Status.READY
bundle.status = ShareLinkBundle.Status.READY
bundle.built_at = timezone.now()
bundle.last_error = ""
bundle.save(
@@ -641,10 +643,14 @@ def build_share_bundle(bundle_id: int):
"last_error",
],
)
logger.info("Built share bundle %s", bundle.pk)
logger.info("Built share link bundle %s", bundle.pk)
except Exception as exc:
logger.exception("Failed to build share bundle %s: %s", bundle_id, exc)
bundle.status = ShareBundle.Status.FAILED
logger.exception(
"Failed to build share link bundle %s: %s",
bundle_id,
exc,
)
bundle.status = ShareLinkBundle.Status.FAILED
bundle.last_error = str(exc)
bundle.save(update_fields=["status", "last_error"])
try:
@@ -661,9 +667,9 @@ def build_share_bundle(bundle_id: int):
@shared_task
def cleanup_expired_share_bundles():
def cleanup_expired_share_link_bundles():
now = timezone.now()
expired_qs = ShareBundle.objects.filter(
expired_qs = ShareLinkBundle.objects.filter(
deleted_at__isnull=True,
expiration__isnull=False,
expiration__lt=now,
@@ -675,9 +681,9 @@ def cleanup_expired_share_bundles():
bundle.hard_delete()
except Exception as exc:
logger.warning(
"Failed to delete expired share bundle %s: %s",
"Failed to delete expired share link bundle %s: %s",
bundle.pk,
exc,
)
if count:
logger.info("Deleted %s expired share bundle(s)", count)
logger.info("Deleted %s expired share link bundle(s)", count)