new api to get metadata

This commit is contained in:
ClF3 2024-04-30 13:40:39 +08:00
parent 0c47170a32
commit 92e67aca0b
3 changed files with 15 additions and 3 deletions

View File

@ -5,4 +5,12 @@ from .models import Picture
pics=Picture.objects.order_by("?")
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
}

View File

@ -4,4 +4,5 @@ from . import views
urlpatterns = [
path("", views.index, name="index"),
path("metadata", views.metadata, name="metadata")
]

View File

@ -1,6 +1,9 @@
from django.shortcuts import render, redirect
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.
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")