mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2026-11-27 23:45:14 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9feb7aaa14 |
No files matched your search
@@ -23,7 +23,6 @@ dependencies = [
|
|||||||
"channels~=4.2",
|
"channels~=4.2",
|
||||||
"channels-redis~=4.2",
|
"channels-redis~=4.2",
|
||||||
"concurrent-log-handler~=0.9.25",
|
"concurrent-log-handler~=0.9.25",
|
||||||
"cryptography>=50",
|
|
||||||
"dateparser~=1.4",
|
"dateparser~=1.4",
|
||||||
# WARNING: django does not use semver.
|
# WARNING: django does not use semver.
|
||||||
# Only patch versions are guaranteed to not introduce breaking changes.
|
# Only patch versions are guaranteed to not introduce breaking changes.
|
||||||
@@ -47,7 +46,6 @@ dependencies = [
|
|||||||
"flower>=2.0.1,<2.3",
|
"flower>=2.0.1,<2.3",
|
||||||
"gotenberg-client[httpx]~=1.0",
|
"gotenberg-client[httpx]~=1.0",
|
||||||
"httpx-oauth~=0.17",
|
"httpx-oauth~=0.17",
|
||||||
"humanize>=4.15",
|
|
||||||
"ijson>=3.5.1",
|
"ijson>=3.5.1",
|
||||||
"imap-tools>=1.14,<1.16",
|
"imap-tools>=1.14,<1.16",
|
||||||
"jinja2~=3.1.6",
|
"jinja2~=3.1.6",
|
||||||
@@ -58,13 +56,10 @@ dependencies = [
|
|||||||
"llama-index-embeddings-openai-like>=0.2.2",
|
"llama-index-embeddings-openai-like>=0.2.2",
|
||||||
"llama-index-llms-ollama>=0.9.1",
|
"llama-index-llms-ollama>=0.9.1",
|
||||||
"llama-index-llms-openai-like>=0.7.1",
|
"llama-index-llms-openai-like>=0.7.1",
|
||||||
"lxml>=6.1",
|
|
||||||
"ocrmypdf[heic]>=17.12,<17.13",
|
"ocrmypdf[heic]>=17.12,<17.13",
|
||||||
"ollama>=0.6.1",
|
|
||||||
"openai>=2.48",
|
"openai>=2.48",
|
||||||
"pathvalidate~=3.3.1",
|
"pathvalidate~=3.3.1",
|
||||||
"pdf2image~=1.17.0",
|
"pdf2image~=1.17.0",
|
||||||
"pikepdf>=10.13",
|
|
||||||
"python-dateutil~=2.9.0",
|
"python-dateutil~=2.9.0",
|
||||||
"python-dotenv~=1.2.1",
|
"python-dotenv~=1.2.1",
|
||||||
"python-gnupg~=0.5.4",
|
"python-gnupg~=0.5.4",
|
||||||
|
|||||||
+10
-21
@@ -6,7 +6,6 @@ import zipfile
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from tempfile import TemporaryDirectory
|
from tempfile import TemporaryDirectory
|
||||||
from tempfile import mkstemp
|
|
||||||
|
|
||||||
from celery import Task
|
from celery import Task
|
||||||
from celery import shared_task
|
from celery import shared_task
|
||||||
@@ -897,26 +896,25 @@ def build_share_link_bundle(bundle_id: int) -> None:
|
|||||||
|
|
||||||
documents = list(bundle.documents.all().order_by("pk"))
|
documents = list(bundle.documents.all().order_by("pk"))
|
||||||
|
|
||||||
_, temp_zip_path_str = mkstemp(suffix=".zip", dir=settings.SCRATCH_DIR)
|
|
||||||
temp_zip_path = Path(temp_zip_path_str)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
strategy_class = (
|
strategy_class = (
|
||||||
ArchiveOnlyStrategy
|
ArchiveOnlyStrategy
|
||||||
if bundle.file_version == ShareLink.FileVersion.ARCHIVE
|
if bundle.file_version == ShareLink.FileVersion.ARCHIVE
|
||||||
else OriginalsOnlyStrategy
|
else OriginalsOnlyStrategy
|
||||||
)
|
)
|
||||||
with zipfile.ZipFile(temp_zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
|
|
||||||
strategy = strategy_class(zipf)
|
|
||||||
for document in documents:
|
|
||||||
strategy.add_document(document)
|
|
||||||
|
|
||||||
output_dir = settings.SHARE_LINK_BUNDLE_DIR
|
output_dir = settings.SHARE_LINK_BUNDLE_DIR
|
||||||
output_dir.mkdir(parents=True, exist_ok=True)
|
output_dir.mkdir(parents=True, exist_ok=True)
|
||||||
final_path = (output_dir / f"{bundle.slug}.zip").resolve()
|
final_path = (output_dir / f"{bundle.slug}.zip").resolve()
|
||||||
if final_path.exists():
|
|
||||||
final_path.unlink()
|
with TemporaryDirectory(dir=settings.SCRATCH_DIR) as tmp_dir:
|
||||||
shutil.move(temp_zip_path, final_path)
|
temp_zip_path = Path(tmp_dir) / "bundle.zip"
|
||||||
|
with zipfile.ZipFile(temp_zip_path, "w", zipfile.ZIP_DEFLATED) as zipf:
|
||||||
|
strategy = strategy_class(zipf)
|
||||||
|
for document in documents:
|
||||||
|
strategy.add_document(document)
|
||||||
|
|
||||||
|
final_path.unlink(missing_ok=True)
|
||||||
|
shutil.move(temp_zip_path, final_path)
|
||||||
|
|
||||||
bundle.file_path = f"{bundle.slug}.zip"
|
bundle.file_path = f"{bundle.slug}.zip"
|
||||||
bundle.size_bytes = final_path.stat().st_size
|
bundle.size_bytes = final_path.stat().st_size
|
||||||
@@ -947,16 +945,7 @@ def build_share_link_bundle(bundle_id: int) -> None:
|
|||||||
"timestamp": timezone.now().isoformat(),
|
"timestamp": timezone.now().isoformat(),
|
||||||
}
|
}
|
||||||
bundle.save(update_fields=["status", "last_error"])
|
bundle.save(update_fields=["status", "last_error"])
|
||||||
try:
|
|
||||||
temp_zip_path.unlink()
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
raise
|
raise
|
||||||
finally:
|
|
||||||
try:
|
|
||||||
temp_zip_path.unlink(missing_ok=True)
|
|
||||||
except OSError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@shared_task
|
@shared_task
|
||||||
|
|||||||
@@ -434,13 +434,9 @@ class ShareLinkBundleBuildTaskTests(DirectoriesMixin, APITestCase):
|
|||||||
"documents.tasks.OriginalsOnlyStrategy.add_document",
|
"documents.tasks.OriginalsOnlyStrategy.add_document",
|
||||||
side_effect=RuntimeError("zip failure"),
|
side_effect=RuntimeError("zip failure"),
|
||||||
),
|
),
|
||||||
mock.patch("pathlib.Path.unlink") as unlink_mock,
|
self.assertRaises(RuntimeError),
|
||||||
):
|
):
|
||||||
unlink_mock.side_effect = [OSError("unlink"), OSError("unlink-finally")] + [
|
build_share_link_bundle(bundle.pk)
|
||||||
None,
|
|
||||||
] * 5
|
|
||||||
with self.assertRaises(RuntimeError):
|
|
||||||
build_share_link_bundle(bundle.pk)
|
|
||||||
|
|
||||||
bundle.refresh_from_db()
|
bundle.refresh_from_db()
|
||||||
self.assertEqual(bundle.status, ShareLinkBundle.Status.FAILED)
|
self.assertEqual(bundle.status, ShareLinkBundle.Status.FAILED)
|
||||||
@@ -448,10 +444,6 @@ class ShareLinkBundleBuildTaskTests(DirectoriesMixin, APITestCase):
|
|||||||
assert isinstance(bundle.last_error, dict)
|
assert isinstance(bundle.last_error, dict)
|
||||||
self.assertEqual(bundle.last_error.get("message"), "zip failure")
|
self.assertEqual(bundle.last_error.get("message"), "zip failure")
|
||||||
self.assertEqual(bundle.last_error.get("exception_type"), "RuntimeError")
|
self.assertEqual(bundle.last_error.get("exception_type"), "RuntimeError")
|
||||||
scratch_zips = list(Path(settings.SCRATCH_DIR).glob("*.zip"))
|
|
||||||
self.assertTrue(scratch_zips)
|
|
||||||
for path in scratch_zips:
|
|
||||||
path.unlink(missing_ok=True)
|
|
||||||
|
|
||||||
def test_build_share_link_bundle_missing_bundle_noop(self) -> None:
|
def test_build_share_link_bundle_missing_bundle_noop(self) -> None:
|
||||||
# Should not raise when bundle does not exist
|
# Should not raise when bundle does not exist
|
||||||
|
|||||||
@@ -2516,7 +2516,6 @@ dependencies = [
|
|||||||
{ name = "channels" },
|
{ name = "channels" },
|
||||||
{ name = "channels-redis" },
|
{ name = "channels-redis" },
|
||||||
{ name = "concurrent-log-handler" },
|
{ name = "concurrent-log-handler" },
|
||||||
{ name = "cryptography" },
|
|
||||||
{ name = "dateparser" },
|
{ name = "dateparser" },
|
||||||
{ name = "django" },
|
{ name = "django" },
|
||||||
{ name = "django-allauth", extra = ["mfa", "socialaccount"] },
|
{ name = "django-allauth", extra = ["mfa", "socialaccount"] },
|
||||||
@@ -2538,7 +2537,6 @@ dependencies = [
|
|||||||
{ name = "flower" },
|
{ name = "flower" },
|
||||||
{ name = "gotenberg-client", extra = ["httpx"] },
|
{ name = "gotenberg-client", extra = ["httpx"] },
|
||||||
{ name = "httpx-oauth" },
|
{ name = "httpx-oauth" },
|
||||||
{ name = "humanize" },
|
|
||||||
{ name = "ijson" },
|
{ name = "ijson" },
|
||||||
{ name = "imap-tools" },
|
{ name = "imap-tools" },
|
||||||
{ name = "jinja2" },
|
{ name = "jinja2" },
|
||||||
@@ -2549,13 +2547,10 @@ dependencies = [
|
|||||||
{ name = "llama-index-embeddings-openai-like" },
|
{ name = "llama-index-embeddings-openai-like" },
|
||||||
{ name = "llama-index-llms-ollama" },
|
{ name = "llama-index-llms-ollama" },
|
||||||
{ name = "llama-index-llms-openai-like" },
|
{ name = "llama-index-llms-openai-like" },
|
||||||
{ name = "lxml" },
|
|
||||||
{ name = "ocrmypdf", extra = ["heic"] },
|
{ name = "ocrmypdf", extra = ["heic"] },
|
||||||
{ name = "ollama" },
|
|
||||||
{ name = "openai" },
|
{ name = "openai" },
|
||||||
{ name = "pathvalidate" },
|
{ name = "pathvalidate" },
|
||||||
{ name = "pdf2image" },
|
{ name = "pdf2image" },
|
||||||
{ name = "pikepdf" },
|
|
||||||
{ name = "python-dateutil" },
|
{ name = "python-dateutil" },
|
||||||
{ name = "python-dotenv" },
|
{ name = "python-dotenv" },
|
||||||
{ name = "python-gnupg" },
|
{ name = "python-gnupg" },
|
||||||
@@ -2673,7 +2668,6 @@ requires-dist = [
|
|||||||
{ name = "channels", specifier = "~=4.2" },
|
{ name = "channels", specifier = "~=4.2" },
|
||||||
{ name = "channels-redis", specifier = "~=4.2" },
|
{ name = "channels-redis", specifier = "~=4.2" },
|
||||||
{ name = "concurrent-log-handler", specifier = "~=0.9.25" },
|
{ name = "concurrent-log-handler", specifier = "~=0.9.25" },
|
||||||
{ name = "cryptography", specifier = ">=50.0.0" },
|
|
||||||
{ name = "dateparser", specifier = "~=1.4" },
|
{ name = "dateparser", specifier = "~=1.4" },
|
||||||
{ name = "django", specifier = "~=5.2.18" },
|
{ name = "django", specifier = "~=5.2.18" },
|
||||||
{ name = "django-allauth", extras = ["mfa", "socialaccount"], specifier = "~=65.21.1" },
|
{ name = "django-allauth", extras = ["mfa", "socialaccount"], specifier = "~=65.21.1" },
|
||||||
@@ -2696,7 +2690,6 @@ requires-dist = [
|
|||||||
{ name = "gotenberg-client", extras = ["httpx"], specifier = "~=1.0" },
|
{ name = "gotenberg-client", extras = ["httpx"], specifier = "~=1.0" },
|
||||||
{ name = "granian", extras = ["uvloop"], marker = "extra == 'webserver'", specifier = ">=2.7,<2.9" },
|
{ name = "granian", extras = ["uvloop"], marker = "extra == 'webserver'", specifier = ">=2.7,<2.9" },
|
||||||
{ name = "httpx-oauth", specifier = "~=0.17" },
|
{ name = "httpx-oauth", specifier = "~=0.17" },
|
||||||
{ name = "humanize", specifier = ">=4.15.0" },
|
|
||||||
{ name = "ijson", specifier = ">=3.5.1" },
|
{ name = "ijson", specifier = ">=3.5.1" },
|
||||||
{ name = "imap-tools", specifier = ">=1.14,<1.16" },
|
{ name = "imap-tools", specifier = ">=1.14,<1.16" },
|
||||||
{ name = "jinja2", specifier = "~=3.1.6" },
|
{ name = "jinja2", specifier = "~=3.1.6" },
|
||||||
@@ -2707,14 +2700,11 @@ requires-dist = [
|
|||||||
{ name = "llama-index-embeddings-openai-like", specifier = ">=0.2.2" },
|
{ name = "llama-index-embeddings-openai-like", specifier = ">=0.2.2" },
|
||||||
{ name = "llama-index-llms-ollama", specifier = ">=0.9.1" },
|
{ name = "llama-index-llms-ollama", specifier = ">=0.9.1" },
|
||||||
{ name = "llama-index-llms-openai-like", specifier = ">=0.7.1" },
|
{ name = "llama-index-llms-openai-like", specifier = ">=0.7.1" },
|
||||||
{ name = "lxml", specifier = ">=6.1.0" },
|
|
||||||
{ name = "mysqlclient", marker = "extra == 'mariadb'", specifier = ">=2.2.7,<2.4" },
|
{ name = "mysqlclient", marker = "extra == 'mariadb'", specifier = ">=2.2.7,<2.4" },
|
||||||
{ name = "ocrmypdf", extras = ["heic"], specifier = ">=17.12,<17.13" },
|
{ name = "ocrmypdf", extras = ["heic"], specifier = ">=17.12,<17.13" },
|
||||||
{ name = "ollama", specifier = ">=0.6.1" },
|
|
||||||
{ name = "openai", specifier = ">=2.48" },
|
{ name = "openai", specifier = ">=2.48" },
|
||||||
{ name = "pathvalidate", specifier = "~=3.3.1" },
|
{ name = "pathvalidate", specifier = "~=3.3.1" },
|
||||||
{ name = "pdf2image", specifier = "~=1.17.0" },
|
{ name = "pdf2image", specifier = "~=1.17.0" },
|
||||||
{ name = "pikepdf", specifier = ">=10.13" },
|
|
||||||
{ name = "psycopg", extras = ["c", "pool"], marker = "extra == 'postgres'", specifier = "==3.3.8" },
|
{ name = "psycopg", extras = ["c", "pool"], marker = "extra == 'postgres'", specifier = "==3.3.8" },
|
||||||
{ name = "psycopg-c", marker = "python_full_version == '3.12.*' and platform_machine == 'aarch64' and sys_platform == 'linux' and extra == 'postgres'", url = "https://github.com/paperless-ngx/builder/releases/download/psycopg-trixie-3.3.8/psycopg_c-3.3.8-cp312-cp312-manylinux_2_38_aarch64.whl" },
|
{ name = "psycopg-c", marker = "python_full_version == '3.12.*' and platform_machine == 'aarch64' and sys_platform == 'linux' and extra == 'postgres'", url = "https://github.com/paperless-ngx/builder/releases/download/psycopg-trixie-3.3.8/psycopg_c-3.3.8-cp312-cp312-manylinux_2_38_aarch64.whl" },
|
||||||
{ name = "psycopg-c", marker = "python_full_version == '3.14.*' and platform_machine == 'aarch64' and sys_platform == 'linux' and extra == 'postgres'", url = "https://github.com/paperless-ngx/builder/releases/download/psycopg-trixie-3.3.8/psycopg_c-3.3.8-cp314-cp314-manylinux_2_38_aarch64.whl" },
|
{ name = "psycopg-c", marker = "python_full_version == '3.14.*' and platform_machine == 'aarch64' and sys_platform == 'linux' and extra == 'postgres'", url = "https://github.com/paperless-ngx/builder/releases/download/psycopg-trixie-3.3.8/psycopg_c-3.3.8-cp314-cp314-manylinux_2_38_aarch64.whl" },
|
||||||
|
|||||||
Reference in new issue
Block a user