add /api/external_links endpoint

This commit is contained in:
Tomáš Mládek 2020-07-16 23:44:38 +02:00
parent 010c9c7a07
commit 6c8963531b
2 changed files with 8 additions and 1 deletions

View file

@ -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/<int:document_id>', views.LabelView.as_view(), name='label'),
path('retrieve/<int:document_id>', views.DocumentWithLabelView.as_view(), name='retrieve'),
path('feed', views.RecentlyUploadedFeed()),
path('api/external_links', ExternalLinkView),
path('api/ipfs_cids', IPFSView)
]

View file

@ -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]