new api to get metadata
This commit is contained in:
parent
0c47170a32
commit
92e67aca0b
|
@ -6,3 +6,11 @@ pics=Picture.objects.order_by("?")
|
||||||
|
|
||||||
def get_random_picture_url():
|
def get_random_picture_url():
|
||||||
return "https://cdn.clf3.org/tianyi-random/"+pics[0].name+".webp"
|
return "https://cdn.clf3.org/tianyi-random/"+pics[0].name+".webp"
|
||||||
|
def get_random_picture_meta():
|
||||||
|
return {
|
||||||
|
"name":pics[0].name,
|
||||||
|
"description":pics[0].description,
|
||||||
|
"author":pics[0].author,
|
||||||
|
"author_url":pics[0].author_url,
|
||||||
|
"original_url":pics[0].original_url
|
||||||
|
}
|
|
@ -4,4 +4,5 @@ from . import views
|
||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path("", views.index, name="index"),
|
path("", views.index, name="index"),
|
||||||
|
path("metadata", views.metadata, name="metadata")
|
||||||
]
|
]
|
|
@ -1,6 +1,9 @@
|
||||||
from django.shortcuts import render, redirect
|
from django.shortcuts import render, redirect
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from .random_picture import get_random_picture_url
|
from .random_picture import get_random_picture_url, get_random_picture_meta
|
||||||
|
import json
|
||||||
# Create your views here.
|
# Create your views here.
|
||||||
def index(request):
|
def index(request):
|
||||||
return redirect(get_random_picture_url())
|
return redirect(get_random_picture_url())
|
||||||
|
def metadata(request):
|
||||||
|
return HttpResponse(json.dumps(get_random_picture_meta()), content_type="application/json")
|
Loading…
Reference in New Issue