ФУНКЦИИ - МЕЖПРОЕКТНАЯ КОММУНИКАЦИЯ: очистка хранилища и проектные квоты

This commit is contained in:
DCCONSTRUCTIONS
2026-04-28 13:25:37 +03:00
parent 02d79da6f9
commit 46e27a326c
15 changed files with 870 additions and 66 deletions
@@ -6,10 +6,28 @@ from urllib.parse import quote
from botocore.exceptions import ClientError
from django.http import HttpResponse, StreamingHttpResponse
from django.utils import timezone
from plane.settings.storage import S3Storage
def _mark_preview_state(asset, status, error=None):
attributes = dict(asset.attributes or {})
if status == "failed":
attributes["preview_status"] = "failed"
attributes["preview_failed_at"] = timezone.now().isoformat()
if error:
attributes["preview_error"] = str(error)
else:
attributes.pop("preview_failed_at", None)
attributes.pop("preview_error", None)
attributes["preview_status"] = "ok"
asset.attributes = attributes
asset.save(update_fields=["attributes", "updated_at"])
def attachment_object_exists(asset):
storage = S3Storage(request=None)
try:
@@ -34,7 +52,11 @@ def get_attachment_preview_response(request, asset, disposition="inline"):
try:
storage_response = storage.s3_client.get_object(**request_kwargs)
except ClientError:
if disposition == "inline" and asset.attributes.get("preview_status") == "failed":
_mark_preview_state(asset, "ok")
except ClientError as exc:
if disposition == "inline":
_mark_preview_state(asset, "failed", error=exc.response.get("Error", {}).get("Code", exc))
return HttpResponse("Attachment object not found.", status=404)
content_type = (