From 010c9c7a07afd5ae4d363a347126a464bc25ca51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Wed, 17 Jun 2020 11:11:25 +0200 Subject: [PATCH] add /api/ipfs_cids view for easier mass pinning --- sdbs_pile/pile/urls.py | 4 +++- sdbs_pile/pile/views.py | 9 ++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/sdbs_pile/pile/urls.py b/sdbs_pile/pile/urls.py index 03a3542..ac37b55 100644 --- a/sdbs_pile/pile/urls.py +++ b/sdbs_pile/pile/urls.py @@ -1,6 +1,7 @@ from django.urls import path from . import views +from .views import IPFSView app_name = 'pile' urlpatterns = [ @@ -9,5 +10,6 @@ urlpatterns = [ path('item/', views.DocumentView.as_view(), name='document'), path('label/', views.LabelView.as_view(), name='label'), path('retrieve/', views.DocumentWithLabelView.as_view(), name='retrieve'), - path('feed', views.RecentlyUploadedFeed()) + path('feed', views.RecentlyUploadedFeed()), + path('api/ipfs_cids', IPFSView) ] diff --git a/sdbs_pile/pile/views.py b/sdbs_pile/pile/views.py index ea9e782..a84832a 100644 --- a/sdbs_pile/pile/views.py +++ b/sdbs_pile/pile/views.py @@ -1,6 +1,7 @@ # Create your views here. import io import logging +import re from datetime import datetime from operator import itemgetter from random import choice @@ -9,7 +10,7 @@ import weasyprint from PyPDF2 import PdfFileWriter, PdfFileReader from django.contrib.syndication.views import Feed from django.core.exceptions import ObjectDoesNotExist, PermissionDenied -from django.http import Http404, FileResponse, HttpRequest +from django.http import Http404, FileResponse, HttpRequest, HttpResponse from django.shortcuts import redirect from django.template.loader import render_to_string from django.utils.text import slugify @@ -169,3 +170,9 @@ class RecentlyUploadedFeed(Feed): def item_pubdate(self, item: Document): return item.uploaded or datetime.now() + + +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] + return HttpResponse("\n".join(ipfs_cids), content_type='text/plain')