diff --git a/sdbs_pile/pile/urls.py b/sdbs_pile/pile/urls.py index ac37b55..936f3f7 100644 --- a/sdbs_pile/pile/urls.py +++ b/sdbs_pile/pile/urls.py @@ -1,7 +1,7 @@ from django.urls import path from . import views -from .views import IPFSView +from .views import IPFSView, ExternalLinkView app_name = 'pile' urlpatterns = [ @@ -11,5 +11,6 @@ urlpatterns = [ path('label/', views.LabelView.as_view(), name='label'), path('retrieve/', views.DocumentWithLabelView.as_view(), name='retrieve'), path('feed', views.RecentlyUploadedFeed()), + path('api/external_links', ExternalLinkView), path('api/ipfs_cids', IPFSView) ] diff --git a/sdbs_pile/pile/views.py b/sdbs_pile/pile/views.py index a84832a..c2b9521 100644 --- a/sdbs_pile/pile/views.py +++ b/sdbs_pile/pile/views.py @@ -172,6 +172,12 @@ class RecentlyUploadedFeed(Feed): return item.uploaded or datetime.now() +def ExternalLinkView(request: HttpRequest): + external_links = Document.objects.all().external().values_list("external_url", flat=True) + external_links = [link for link in external_links if "pile.sdbs.cz" not in link] + return HttpResponse("\n".join(external_links), content_type='text/plain') + + def IPFSView(request: HttpRequest): ipfs_matches = [re.search(r'Qm[\w]{44}', doc.url) for doc in Document.objects.all() if 'ipfs' in doc.url] ipfs_cids = [match.group(0) for match in ipfs_matches if match]