remote_version API endpoint

This commit is contained in:
Michael Shamoon 2022-04-01 01:48:05 -07:00
parent 6f0ac7ae45
commit d76eccad1c
2 changed files with 37 additions and 0 deletions

View File

@ -1,6 +1,8 @@
import logging import logging
import os import os
import re
import tempfile import tempfile
import urllib
import uuid import uuid
import zipfile import zipfile
from datetime import datetime from datetime import datetime
@ -24,6 +26,8 @@ from django.views.decorators.cache import cache_control
from django.views.generic import TemplateView from django.views.generic import TemplateView
from django_filters.rest_framework import DjangoFilterBackend from django_filters.rest_framework import DjangoFilterBackend
from django_q.tasks import async_task from django_q.tasks import async_task
from packaging import version as packaging_version
from paperless import version
from paperless.db import GnuPG from paperless.db import GnuPG
from paperless.views import StandardPagination from paperless.views import StandardPagination
from rest_framework import parsers from rest_framework import parsers
@ -666,3 +670,30 @@ class BulkDownloadView(GenericAPIView):
) )
return response return response
class RemoteVersionView(GenericAPIView):
def get(self, request, format=None):
try:
with urllib.request.urlopen(
"https://raw.githubusercontent.com/paperless-ngx/paperless-ngx"
+ "/main/src/paperless/version.py",
) as response:
remote = response.read().decode("utf-8")
match = re.search("(\\d+, \\d+, \\d+)", remote)
if match:
remote_version = ".".join(match[0].split(", "))
except urllib.error.URLError:
remote_version = "0.0.0"
current_version = ".".join([str(_) for _ in version.__version__[:3]])
is_greater = packaging_version.parse(remote_version) > packaging_version.parse(
current_version,
)
return Response(
{
"version": remote_version,
"greater_than_current": is_greater,
},
)

View File

@ -14,6 +14,7 @@ from documents.views import DocumentTypeViewSet
from documents.views import IndexView from documents.views import IndexView
from documents.views import LogViewSet from documents.views import LogViewSet
from documents.views import PostDocumentView from documents.views import PostDocumentView
from documents.views import RemoteVersionView
from documents.views import SavedViewViewSet from documents.views import SavedViewViewSet
from documents.views import SearchAutoCompleteView from documents.views import SearchAutoCompleteView
from documents.views import SelectionDataView from documents.views import SelectionDataView
@ -72,6 +73,11 @@ urlpatterns = [
BulkDownloadView.as_view(), BulkDownloadView.as_view(),
name="bulk_download", name="bulk_download",
), ),
re_path(
r"^remote_version/",
RemoteVersionView.as_view(),
name="remoteversion",
),
path("token/", views.obtain_auth_token), path("token/", views.obtain_auth_token),
] ]
+ api_router.urls, + api_router.urls,