forked from 00dani/lemoncurry
Implement the Micropub source query internally rather than by simply parsing the visible content
This commit is contained in:
parent
d68dda85ad
commit
1e4df2d1b5
1 changed files with 17 additions and 11 deletions
|
@ -1,10 +1,13 @@
|
||||||
from django.http import JsonResponse
|
from django.http import JsonResponse
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
|
from entries.from_url import from_url
|
||||||
from lemoncurry import requests
|
from lemoncurry import requests
|
||||||
from lemoncurry.utils import absolute_url
|
from lemoncurry.utils import absolute_url
|
||||||
from .. import error
|
from .. import error
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def config(request):
|
def config(request):
|
||||||
config = syndicate_to(request)
|
config = syndicate_to(request)
|
||||||
config['media-endpoint'] = absolute_url(request, reverse('micropub:media'))
|
config['media-endpoint'] = absolute_url(request, reverse('micropub:media'))
|
||||||
|
@ -12,19 +15,22 @@ def config(request):
|
||||||
|
|
||||||
|
|
||||||
def source(request):
|
def source(request):
|
||||||
get = request.GET
|
if 'url' not in request.GET:
|
||||||
if 'url' not in get:
|
|
||||||
raise error.bad_req('must specify url parameter for source query')
|
raise error.bad_req('must specify url parameter for source query')
|
||||||
mf2 = requests.mf2(get['url']).to_dict(filter_by_type='h-entry')
|
entry = from_url(request.GET['url'])
|
||||||
if not mf2:
|
props = {}
|
||||||
raise error.bad_req('no h-entry at the requested url')
|
|
||||||
entry = mf2[0]
|
|
||||||
keys = get.getlist('properties', []) + get.getlist('properties[]', [])
|
|
||||||
if not keys:
|
|
||||||
return entry
|
|
||||||
|
|
||||||
props = entry['properties']
|
keys = set(request.GET.getlist('properties') + request.GET.getlist('properties[]'))
|
||||||
return {'properties': {k: props[k] for k in keys if k in props}}
|
if not keys or 'content' in keys:
|
||||||
|
props['content'] = [entry.content]
|
||||||
|
if (not keys or 'category' in keys) and entry.cats.exists():
|
||||||
|
props['category'] = [cat.name for cat in entry.cats.all()]
|
||||||
|
if (not keys or 'name' in keys) and entry.name:
|
||||||
|
props['name'] = [entry.name]
|
||||||
|
if (not keys or 'syndication' in keys) and entry.syndications.exists():
|
||||||
|
props['syndication'] = [synd.url for synd in entry.syndications.all()]
|
||||||
|
|
||||||
|
return {'type': ['h-entry'], 'properties': props}
|
||||||
|
|
||||||
|
|
||||||
def syndicate_to(request):
|
def syndicate_to(request):
|
||||||
|
|
Loading…
Reference in a new issue