Steamline errors
This commit is contained in:
@ -1,9 +1,16 @@
|
|||||||
import { getMetadata } from '$lib/util/album';
|
import { getMetadata } from '$lib/util/album';
|
||||||
import { getAlbumUri, getZipName } from '$lib/util/links';
|
import { getAlbumUri, getZipName } from '$lib/util/links';
|
||||||
|
import { error } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params }) => {
|
export const load: PageServerLoad = async ({ params }) => {
|
||||||
const album = await getMetadata(getZipName(params));
|
let album;
|
||||||
|
try {
|
||||||
|
album = await getMetadata(getZipName(params));
|
||||||
|
} catch (e) {
|
||||||
|
throw error(404, 'Album not found');
|
||||||
|
}
|
||||||
|
|
||||||
const base = getAlbumUri(params);
|
const base = getAlbumUri(params);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
13
src/routes/[slug]/[[timestamp]]/i/+page.server.ts
Normal file
13
src/routes/[slug]/[[timestamp]]/i/+page.server.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
import { error } from '@sveltejs/kit';
|
||||||
|
import type { PageServerLoad } from './$types';
|
||||||
|
import { getZipName } from '$lib/util/links';
|
||||||
|
import { getMetadata } from '$lib/util/album';
|
||||||
|
|
||||||
|
export const load: PageServerLoad = async ({ params }) => {
|
||||||
|
try {
|
||||||
|
await getMetadata(getZipName(params));
|
||||||
|
} catch (e) {
|
||||||
|
throw error(404, 'Album not found');
|
||||||
|
}
|
||||||
|
throw error(400, 'No item specified');
|
||||||
|
};
|
||||||
@ -1,14 +1,26 @@
|
|||||||
import { getMetadata } from '$lib/util/album';
|
import { getMetadata } from '$lib/util/album';
|
||||||
import { getFileName, getFilePath, getZipName } from '$lib/util/links';
|
import { getAlbumUri, getFileName, getFilePath, getZipName } from '$lib/util/links';
|
||||||
|
import { error } from '@sveltejs/kit';
|
||||||
import type { PageServerLoad } from './$types';
|
import type { PageServerLoad } from './$types';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params }) => {
|
export const load: PageServerLoad = async ({ params }) => {
|
||||||
const album = await getMetadata(getZipName(params));
|
let album;
|
||||||
|
try {
|
||||||
|
album = await getMetadata(getZipName(params));
|
||||||
|
} catch (e) {
|
||||||
|
throw error(404, 'Album not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
const base = getAlbumUri(params);
|
||||||
|
|
||||||
const filePath = getFilePath(params.item);
|
const filePath = getFilePath(params.item);
|
||||||
const item = album.items.find(item => item.item === filePath);
|
const item = album.items.find(item => item.item === filePath);
|
||||||
|
if (!item)
|
||||||
|
throw error(404, `Item not found.`);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
item,
|
item,
|
||||||
|
base,
|
||||||
filename: getFileName(params.item)
|
filename: getFileName(params.item)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user