mirror of
https://github.com/maxdorninger/MediaManager.git
synced 2026-04-17 15:13:24 +02:00
refactor: improve async data fetching in load functions
This commit is contained in:
@@ -2,17 +2,17 @@ import type { LayoutLoad } from './$types';
|
||||
import client from '$lib/api';
|
||||
|
||||
export const load: LayoutLoad = async ({ params, fetch }) => {
|
||||
const show = await client.GET('/api/v1/tv/shows/{show_id}', {
|
||||
const show = client.GET('/api/v1/tv/shows/{show_id}', {
|
||||
fetch: fetch,
|
||||
params: { path: { show_id: params.showId } }
|
||||
});
|
||||
const torrents = await client.GET('/api/v1/tv/shows/{show_id}/torrents', {
|
||||
const torrents = client.GET('/api/v1/tv/shows/{show_id}/torrents', {
|
||||
fetch: fetch,
|
||||
params: { path: { show_id: params.showId } }
|
||||
});
|
||||
|
||||
return {
|
||||
showData: show.data,
|
||||
torrentsData: torrents.data
|
||||
showData: await show.then((x) => x.data),
|
||||
torrentsData: await torrents.then((x) => x.data)
|
||||
};
|
||||
};
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { PageLoad } from './$types';
|
||||
import client from '$lib/api';
|
||||
|
||||
export const load: PageLoad = async ({ fetch, params }) => {
|
||||
const season = await client.GET('/api/v1/tv/seasons/{season_id}', {
|
||||
const season = client.GET('/api/v1/tv/seasons/{season_id}', {
|
||||
fetch: fetch,
|
||||
params: {
|
||||
path: {
|
||||
@@ -10,7 +10,7 @@ export const load: PageLoad = async ({ fetch, params }) => {
|
||||
}
|
||||
}
|
||||
});
|
||||
const seasonFiles = await client.GET('/api/v1/tv/seasons/{season_id}/files', {
|
||||
const seasonFiles = client.GET('/api/v1/tv/seasons/{season_id}/files', {
|
||||
fetch: fetch,
|
||||
params: {
|
||||
path: {
|
||||
@@ -19,7 +19,7 @@ export const load: PageLoad = async ({ fetch, params }) => {
|
||||
}
|
||||
});
|
||||
return {
|
||||
files: seasonFiles.data,
|
||||
season: season.data
|
||||
files: await seasonFiles.then((x) => x.data),
|
||||
season: await season.then((x) => x.data)
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user