Skip to content

Commit

Permalink
Frontend: Get the frontend working with the new API.
Browse files Browse the repository at this point in the history
Also fixed a small snafu.
  • Loading branch information
e3ndr committed Sep 21, 2023
1 parent 14ef2f6 commit afd9044
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 22 deletions.
12 changes: 9 additions & 3 deletions frontends/web-simple/src/lib/api.mjs
Original file line number Diff line number Diff line change
@@ -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 }) {
Expand Down
1 change: 1 addition & 0 deletions frontends/web-simple/src/routes/+page.server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
31 changes: 13 additions & 18 deletions frontends/web-simple/src/routes/media/[mediaId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,31 @@

<table>
<tr>
<td>Directors:</td>
<td>
{data.media.info.people.directors.join(', ')}
</td>

<td>Studios:</td>
<td>
{data.media.info.studios.join(', ')}
</td>
</tr>
<tr>
<td>Writers:</td>
<td>
{data.media.info.people.writers.join(', ')}
{data.media.info.studios.map((s) => s.name).join(', ')}
</td>

<td>Video:</td>
<td>Directors:</td>
<td>
{data.media.files.streams.video.map((s) => s.name || s.codec).join(', ')}
{data.media.info.directors.map((p) => p.name).join(', ')}
</td>
</tr>
<tr />
<tr>
<td>Starring:</td>
<td>
{data.media.info.people.actors.join(', ')}
{data.media.info.actors.map((p) => p.name).join(', ')}
</td>

<td>Audio:</td>
<td>Codecs:</td>
<td>
{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(', ')}
<br />
{data.media.files.streams.audio
.map((s) => s.name || s.codec.toUpperCase())
.join(', ')}
</td>
</tr>
</table>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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));
Expand Down

0 comments on commit afd9044

Please sign in to comment.