mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-08-13 22:33:19 +00:00
Enhancment: Formatted filename for single document downloads (#12095)
--------- Co-authored-by: shamoon <4887959+shamoon@users.noreply.github.com>
This commit is contained in:
+27
-3
@@ -10,6 +10,7 @@ from collections import deque
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
from time import mktime
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import Any
|
||||
from typing import Literal
|
||||
from unicodedata import normalize
|
||||
@@ -616,6 +617,12 @@ class EmailDocumentDetailSchema(EmailSerializer):
|
||||
type=OpenApiTypes.BOOL,
|
||||
location=OpenApiParameter.QUERY,
|
||||
),
|
||||
OpenApiParameter(
|
||||
name="follow_formatting",
|
||||
description="Whether or not to use the filename on disk",
|
||||
type=OpenApiTypes.BOOL,
|
||||
location=OpenApiParameter.QUERY,
|
||||
),
|
||||
],
|
||||
responses={200: OpenApiTypes.BINARY},
|
||||
),
|
||||
@@ -1061,6 +1068,7 @@ class DocumentViewSet(
|
||||
use_archive=not self.original_requested(request)
|
||||
and file_doc.has_archive_version,
|
||||
disposition=disposition,
|
||||
follow_formatting=request.query_params.get("follow_formatting", False),
|
||||
)
|
||||
|
||||
def get_metadata(self, file, mime_type):
|
||||
@@ -3445,14 +3453,30 @@ class SharedLinkView(View):
|
||||
return response
|
||||
|
||||
|
||||
def serve_file(*, doc: Document, use_archive: bool, disposition: str) -> HttpResponse:
|
||||
def serve_file(
|
||||
*,
|
||||
doc: Document,
|
||||
use_archive: bool,
|
||||
disposition: str,
|
||||
follow_formatting: bool = False,
|
||||
) -> HttpResponse:
|
||||
if use_archive:
|
||||
if TYPE_CHECKING:
|
||||
assert doc.archive_filename
|
||||
|
||||
file_handle = doc.archive_file
|
||||
filename = doc.get_public_filename(archive=True)
|
||||
filename = (
|
||||
doc.archive_filename
|
||||
if follow_formatting
|
||||
else doc.get_public_filename(archive=True)
|
||||
)
|
||||
mime_type = "application/pdf"
|
||||
else:
|
||||
if TYPE_CHECKING:
|
||||
assert doc.filename
|
||||
|
||||
file_handle = doc.source_file
|
||||
filename = doc.get_public_filename()
|
||||
filename = doc.filename if follow_formatting else doc.get_public_filename()
|
||||
mime_type = doc.mime_type
|
||||
# Support browser previewing csv files by using text mime type
|
||||
if mime_type in {"application/csv", "text/csv"} and disposition == "inline":
|
||||
|
||||
Reference in New Issue
Block a user