Skip to content

Commit

Permalink
fix: Change the .server loaders to regular +page.ts and fix show dete…
Browse files Browse the repository at this point in the history
…ction for magnet replace (#117)

* fix: make the loader client-side now that we don't have db calls

* fix: move the item page to frontend loading

* fix: shows not being recognized as shows

* refactor: lint

* fix: fix the typings of loaders
  • Loading branch information
filiptrplan authored Oct 10, 2024
1 parent b15dfec commit c540b1d
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 74 deletions.
58 changes: 0 additions & 58 deletions src/routes/[type]/[id]/+page.server.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/routes/[type]/[id]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
let productionCompanies = 4;
let magnetLink = '';
let magnetLoading = false;
let isShow = data.db ? data.db.type === 'show' : false;
let isShow = data.db ? data.db.type === 'Show' : false;
let selectedMagnetItem: Selected<{ id: string; file?: string; folder?: string }>;
$: buttonEnabled = magnetLink && !magnetLoading && (isShow ? selectedMagnetItem : true);
Expand Down
19 changes: 17 additions & 2 deletions src/routes/[type]/[id]/+page.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import type { PageLoad } from './$types';
import { getMovieDetails, getTVDetails } from '$lib/tmdb';
import { ItemsService } from '$lib/client';

export const load = (async ({ fetch, params, data }) => {
export const load = (async ({ fetch, params }) => {
const type = params.type;
const id = Number(params.id);

const { data } = await ItemsService.getItem({
path: {
id: id
},
query: {
use_tmdb_id: true
}
});

if (data) {
data.requested_at = new Date(data.requested_at as string);
}

async function getDetails(type: string, id: number) {
switch (type) {
case 'movie':
Expand All @@ -29,6 +43,7 @@ export const load = (async ({ fetch, params, data }) => {
details: await getDetails(type, id),
mediaType: type,
mediaID: id,
...data
// eslint-disable-next-line @typescript-eslint/no-explicit-any
db: data as any
};
}) satisfies PageLoad;
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { PageServerLoad } from './$types';
import type { PageLoad } from './$types';
import { ItemsService, type ItemsResponse } from '$lib/client';
import { error } from '@sveltejs/kit';

export const load = (async ({ url }) => {
export const load: PageLoad = async ({ url }) => {
async function getLibraryApi(): Promise<ItemsResponse> {
const limit = Number(url.searchParams.get('limit')) || 24;
const page = Number(url.searchParams.get('page')) || 1;
Expand Down Expand Up @@ -35,4 +35,4 @@ export const load = (async ({ url }) => {
library: items,
total: total_items
};
}) satisfies PageServerLoad;
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PageServerLoad } from './$types';
import type { PageLoad } from './$types';
import { superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import {
Expand All @@ -8,7 +8,7 @@ import {
} from '$lib/forms/helpers';
import { SettingsService } from '$lib/client';

export const load: PageServerLoad = async () => {
export const load: PageLoad = async () => {
const { data } = await SettingsService.getSettings({
path: {
paths: generalSettingsToGet.join(',')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PageServerLoad } from './$types';
import type { PageLoad } from './$types';
import { superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import {
Expand All @@ -8,7 +8,7 @@ import {
} from '$lib/forms/helpers';
import { SettingsService } from '$lib/client';

export const load: PageServerLoad = async () => {
export const load: PageLoad = async () => {
const { data } = await SettingsService.getSettings({
path: {
paths: mediaServerSettingsToGet.join(',')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PageServerLoad } from './$types';
import type { PageLoad } from './$types';
import { superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import {
Expand All @@ -8,7 +8,7 @@ import {
} from '$lib/forms/helpers';
import { SettingsService } from '$lib/client';

export const load: PageServerLoad = async () => {
export const load: PageLoad = async () => {
const { data } = await SettingsService.getSettings({
path: {
paths: contentSettingsToGet.join(',')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { PageServerLoad } from './$types';
import type { PageLoad } from './$types';
import { superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import {
Expand All @@ -8,7 +8,7 @@ import {
} from '$lib/forms/helpers';
import { SettingsService } from '$lib/client';

export const load: PageServerLoad = async () => {
export const load: PageLoad = async () => {
const { data } = await SettingsService.getSettings({
path: {
paths: scrapersSettingsToGet.join(',')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import type { PageServerLoad } from './$types';
import type { PageLoad } from './$types';
import { error } from '@sveltejs/kit';
import fs from 'fs/promises';
import path from 'path';
import { dev } from '$app/environment';
import { SettingsService } from '$lib/client';

export const load: PageServerLoad = async () => {
export const load: PageLoad = async () => {
async function getAboutInfo() {
const toGet = ['version', 'symlink'];
const { data, error: apiError } = await SettingsService.getSettings({
Expand Down

0 comments on commit c540b1d

Please sign in to comment.