diff --git a/frontends/web-simple/src/lib/api.mjs b/frontends/web-simple/src/lib/api.mjs index d3532d5..9c6f34b 100644 --- a/frontends/web-simple/src/lib/api.mjs +++ b/frontends/web-simple/src/lib/api.mjs @@ -1,10 +1,16 @@ async function json(/** @type {string} */ url, /** @type {RequestInit | undefined} */ init) { - return await (await fetch(url, init)).json(); + const response = await (await fetch(url, init)).json(); + + if (response.data) { + return response.data; + } else { + throw response.error; + } } -export function listMedia(server) { - return json(server + '/media'); +export async function listMedia(server) { + return (await json(server + '/media')).list; } export function getMediaById(server, { mediaId }) { diff --git a/frontends/web-simple/src/routes/+page.server.js b/frontends/web-simple/src/routes/+page.server.js index a1339cd..10de7af 100644 --- a/frontends/web-simple/src/routes/+page.server.js +++ b/frontends/web-simple/src/routes/+page.server.js @@ -18,6 +18,7 @@ export async function load({ cookies, request }) { try { mediaList.push(...await API.listMedia(server)); } catch (e) { + console.error(e); errors.push(e.toString()); } } diff --git a/frontends/web-simple/src/routes/media/[mediaId]/+page.svelte b/frontends/web-simple/src/routes/media/[mediaId]/+page.svelte index 273c361..b272b07 100644 --- a/frontends/web-simple/src/routes/media/[mediaId]/+page.svelte +++ b/frontends/web-simple/src/routes/media/[mediaId]/+page.svelte @@ -35,36 +35,31 @@ - - - - - - - - + + - - +
Directors: - {data.media.info.people.directors.join(', ')} - Studios: - {data.media.info.studios.join(', ')} -
Writers: - {data.media.info.people.writers.join(', ')} + {data.media.info.studios.map((s) => s.name).join(', ')} Video:Directors: - {data.media.files.streams.video.map((s) => s.name || s.codec).join(', ')} + {data.media.info.directors.map((p) => p.name).join(', ')}
Starring: - {data.media.info.people.actors.join(', ')} + {data.media.info.actors.map((p) => p.name).join(', ')} Audio:Codecs: - {data.media.files.streams.audio.map((s) => s.name || s.codec).join(', ')} + {data.media.files.streams.video + .map((s) => s.name || s.codec.toUpperCase()) + .join(', ')} +
+ {data.media.files.streams.audio + .map((s) => s.name || s.codec.toUpperCase()) + .join(', ')}
diff --git a/server/src/main/java/xyz/e3ndr/athena/server/http/MediaRoutes.java b/server/src/main/java/xyz/e3ndr/athena/server/http/MediaRoutes.java index 67b9dba..c48ae52 100644 --- a/server/src/main/java/xyz/e3ndr/athena/server/http/MediaRoutes.java +++ b/server/src/main/java/xyz/e3ndr/athena/server/http/MediaRoutes.java @@ -6,6 +6,7 @@ import co.casterlabs.rakurai.io.http.StandardHttpStatus; import co.casterlabs.rakurai.io.http.server.HttpResponse; import co.casterlabs.rakurai.json.Rson; +import co.casterlabs.rakurai.json.element.JsonObject; import co.casterlabs.sora.api.http.HttpProvider; import co.casterlabs.sora.api.http.SoraHttpSession; import co.casterlabs.sora.api.http.annotations.HttpEndpoint; @@ -18,7 +19,7 @@ class MediaRoutes implements HttpProvider { public HttpResponse onListMedia(SoraHttpSession session) { return new JsonResponse( StandardHttpStatus.OK, - Rson.DEFAULT.toJson(Athena.listMedia()), + JsonObject.singleton("list", Rson.DEFAULT.toJson(Athena.listMedia())), Map.of("media", "GET /api/media/:mediaId") ) .putHeader("Access-Control-Allow-Origin", session.getHeaders().getOrDefault("Origin", Arrays.asList("*")).get(0));