From 00cf619c68bec79ca659c1078af20cc97fd0861f Mon Sep 17 00:00:00 2001 From: Sli Date: Sun, 13 Oct 2024 02:04:45 +0200 Subject: [PATCH] Remove hand crafted urls on viewer-index.ts --- sas/schemas.py | 6 ++++++ sas/static/webpack/sas/viewer-index.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/sas/schemas.py b/sas/schemas.py index b039f6c3..90bbfc90 100644 --- a/sas/schemas.py +++ b/sas/schemas.py @@ -1,5 +1,6 @@ from datetime import datetime +from django.urls import reverse from ninja import FilterSchema, ModelSchema, Schema from pydantic import Field, NonNegativeInt @@ -20,11 +21,16 @@ class PictureSchema(ModelSchema): fields = ["id", "name", "date", "size", "is_moderated", "asked_for_removal"] owner: UserProfileSchema + sas_url: str full_size_url: str compressed_url: str thumb_url: str album: str + @staticmethod + def resolve_sas_url(obj: Picture) -> str: + return reverse("sas:picture", kwargs={"picture_id": obj.id}) + @staticmethod def resolve_full_size_url(obj: Picture) -> str: return obj.get_download_url() diff --git a/sas/static/webpack/sas/viewer-index.ts b/sas/static/webpack/sas/viewer-index.ts index f1b7b76a..a40e2470 100644 --- a/sas/static/webpack/sas/viewer-index.ts +++ b/sas/static/webpack/sas/viewer-index.ts @@ -217,7 +217,7 @@ exportToHtml("loadViewer", (config: ViewerConfig) => { const updateArgs = { data: { sasPictureId: this.currentPicture.id }, unused: "", - url: `/sas/picture/${this.currentPicture.id}/`, + url: this.currentPicture.sas_url, }; if (this.pushstate === History.Replace) { window.history.replaceState(