add /api/ipfs_cids view for easier mass pinning
This commit is contained in:
parent
05983d6718
commit
010c9c7a07
2 changed files with 11 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
from django.urls import path
|
from django.urls import path
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
|
from .views import IPFSView
|
||||||
|
|
||||||
app_name = 'pile'
|
app_name = 'pile'
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
|
@ -9,5 +10,6 @@ urlpatterns = [
|
||||||
path('item/<int:document_id>', views.DocumentView.as_view(), name='document'),
|
path('item/<int:document_id>', views.DocumentView.as_view(), name='document'),
|
||||||
path('label/<int:document_id>', views.LabelView.as_view(), name='label'),
|
path('label/<int:document_id>', views.LabelView.as_view(), name='label'),
|
||||||
path('retrieve/<int:document_id>', views.DocumentWithLabelView.as_view(), name='retrieve'),
|
path('retrieve/<int:document_id>', views.DocumentWithLabelView.as_view(), name='retrieve'),
|
||||||
path('feed', views.RecentlyUploadedFeed())
|
path('feed', views.RecentlyUploadedFeed()),
|
||||||
|
path('api/ipfs_cids', IPFSView)
|
||||||
]
|
]
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
import io
|
import io
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from operator import itemgetter
|
from operator import itemgetter
|
||||||
from random import choice
|
from random import choice
|
||||||
|
@ -9,7 +10,7 @@ import weasyprint
|
||||||
from PyPDF2 import PdfFileWriter, PdfFileReader
|
from PyPDF2 import PdfFileWriter, PdfFileReader
|
||||||
from django.contrib.syndication.views import Feed
|
from django.contrib.syndication.views import Feed
|
||||||
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
|
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.shortcuts import redirect
|
||||||
from django.template.loader import render_to_string
|
from django.template.loader import render_to_string
|
||||||
from django.utils.text import slugify
|
from django.utils.text import slugify
|
||||||
|
@ -169,3 +170,9 @@ class RecentlyUploadedFeed(Feed):
|
||||||
|
|
||||||
def item_pubdate(self, item: Document):
|
def item_pubdate(self, item: Document):
|
||||||
return item.uploaded or datetime.now()
|
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')
|
||||||
|
|
Loading…
Reference in a new issue