From dc728b86fe6485b7d7c05714e630b3446358cfd8 Mon Sep 17 00:00:00 2001 From: Luca Bosin Date: Fri, 25 Aug 2023 13:16:49 +0200 Subject: [PATCH] Move to TypeScript --- src/lib/components/Gallery.svelte | 11 +- src/lib/components/Header.svelte | 5 +- src/lib/components/Icon.svelte | 24 ++-- src/lib/components/Photo.svelte | 53 ++++----- src/lib/data/{album.js => album.ts} | 0 src/lib/data/{language.js => language.ts} | 22 +--- src/lib/icons/arrow-expand.js | 2 - src/lib/icons/arrow-expand.ts | 1 + src/lib/icons/arrow-left.js | 2 - src/lib/icons/arrow-left.ts | 1 + src/lib/util/album.js | 103 ------------------ src/lib/util/album.ts | 66 +++++++++++ src/lib/util/links.js | 42 ------- src/lib/util/links.ts | 22 ++++ src/routes/+error.svelte | 2 +- src/routes/+layout.svelte | 2 +- src/routes/+page.svelte | 2 +- .../{+page.server.js => +page.server.ts} | 4 +- src/routes/[slug]/[[timestamp]]/+page.svelte | 8 +- .../download/{+server.js => +server.ts} | 4 +- .../{+page.server.js => +page.server.ts} | 6 +- .../[[timestamp]]/i/[...item]/+page.svelte | 6 +- .../download/{+server.js => +server.ts} | 4 +- .../t/[[width]]/{+server.js => +server.ts} | 7 +- .../random/{+server.js => +server.ts} | 5 +- static/vime.svelte | 2 +- jsconfig.json => tsconfig.json | 0 27 files changed, 160 insertions(+), 246 deletions(-) rename src/lib/data/{album.js => album.ts} (100%) rename src/lib/data/{language.js => language.ts} (72%) delete mode 100644 src/lib/icons/arrow-expand.js create mode 100644 src/lib/icons/arrow-expand.ts delete mode 100644 src/lib/icons/arrow-left.js create mode 100644 src/lib/icons/arrow-left.ts delete mode 100644 src/lib/util/album.js create mode 100644 src/lib/util/album.ts delete mode 100644 src/lib/util/links.js create mode 100644 src/lib/util/links.ts rename src/routes/[slug]/[[timestamp]]/{+page.server.js => +page.server.ts} (68%) rename src/routes/[slug]/[[timestamp]]/download/{+server.js => +server.ts} (89%) rename src/routes/[slug]/[[timestamp]]/i/[...item]/{+page.server.js => +page.server.ts} (74%) rename src/routes/[slug]/[[timestamp]]/i/[...item]/download/{+server.js => +server.ts} (90%) rename src/routes/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/{+server.js => +server.ts} (88%) rename src/routes/[slug]/[[timestamp]]/random/{+server.js => +server.ts} (83%) rename jsconfig.json => tsconfig.json (100%) diff --git a/src/lib/components/Gallery.svelte b/src/lib/components/Gallery.svelte index 3b6b2d7..9962120 100644 --- a/src/lib/components/Gallery.svelte +++ b/src/lib/components/Gallery.svelte @@ -1,12 +1,13 @@ - diff --git a/src/lib/components/Header.svelte b/src/lib/components/Header.svelte index e7d5062..add0a37 100644 --- a/src/lib/components/Header.svelte +++ b/src/lib/components/Header.svelte @@ -1,10 +1,9 @@ -
diff --git a/src/lib/components/Icon.svelte b/src/lib/components/Icon.svelte index b3d0847..7660f62 100644 --- a/src/lib/components/Icon.svelte +++ b/src/lib/components/Icon.svelte @@ -1,30 +1,28 @@ - diff --git a/src/lib/components/Photo.svelte b/src/lib/components/Photo.svelte index 73beebf..86abc6f 100644 --- a/src/lib/components/Photo.svelte +++ b/src/lib/components/Photo.svelte @@ -1,43 +1,28 @@ - diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 460904f..7957360 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -1,4 +1,4 @@ - diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 1fc8ebe..6779e89 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -1,4 +1,4 @@ - diff --git a/src/routes/[slug]/[[timestamp]]/+page.server.js b/src/routes/[slug]/[[timestamp]]/+page.server.ts similarity index 68% rename from src/routes/[slug]/[[timestamp]]/+page.server.js rename to src/routes/[slug]/[[timestamp]]/+page.server.ts index 6852e83..7f2ced1 100644 --- a/src/routes/[slug]/[[timestamp]]/+page.server.js +++ b/src/routes/[slug]/[[timestamp]]/+page.server.ts @@ -1,8 +1,8 @@ import { getMetadata } from '$lib/util/album'; import { getAlbumUri, getZipName } from '$lib/util/links'; +import type { PageServerLoad } from './$types'; -/** @type {import('./$types').PageLoad} */ -export async function load({ params }) { +export const load: PageServerLoad = async ({ params }) => { const album = await getMetadata(getZipName(params)); const base = getAlbumUri(params); diff --git a/src/routes/[slug]/[[timestamp]]/+page.svelte b/src/routes/[slug]/[[timestamp]]/+page.svelte index f949c58..a38d9ea 100644 --- a/src/routes/[slug]/[[timestamp]]/+page.svelte +++ b/src/routes/[slug]/[[timestamp]]/+page.svelte @@ -1,13 +1,11 @@ -
diff --git a/src/routes/[slug]/[[timestamp]]/download/+server.js b/src/routes/[slug]/[[timestamp]]/download/+server.ts similarity index 89% rename from src/routes/[slug]/[[timestamp]]/download/+server.js rename to src/routes/[slug]/[[timestamp]]/download/+server.ts index 2547d86..b79febc 100644 --- a/src/routes/[slug]/[[timestamp]]/download/+server.js +++ b/src/routes/[slug]/[[timestamp]]/download/+server.ts @@ -2,9 +2,9 @@ import { getMetadata } from '$lib/util/album'; import { getZipName } from '$lib/util/links'; import { error } from '@sveltejs/kit'; import fs from 'node:fs/promises'; +import type { RequestHandler } from './$types'; -/** @type {import('./$types').RequestHandler} */ -export async function GET({ params, url }) { +export const GET: RequestHandler = async ({ params, url }) => { try { const zipName = getZipName(params); const album = await getMetadata(zipName); diff --git a/src/routes/[slug]/[[timestamp]]/i/[...item]/+page.server.js b/src/routes/[slug]/[[timestamp]]/i/[...item]/+page.server.ts similarity index 74% rename from src/routes/[slug]/[[timestamp]]/i/[...item]/+page.server.js rename to src/routes/[slug]/[[timestamp]]/i/[...item]/+page.server.ts index bc30add..a1a3020 100644 --- a/src/routes/[slug]/[[timestamp]]/i/[...item]/+page.server.js +++ b/src/routes/[slug]/[[timestamp]]/i/[...item]/+page.server.ts @@ -1,8 +1,8 @@ import { getMetadata } from '$lib/util/album'; -import { getFileName, getFilePath, getZipName } from '$lib/util/links.js'; +import { getFileName, getFilePath, getZipName } from '$lib/util/links'; +import type { PageServerLoad } from './$types'; -/** @type {import('./$types').PageLoad} */ -export async function load({ params }) { +export const load: PageServerLoad = async ({ params }) => { const album = await getMetadata(getZipName(params)); const filePath = getFilePath(params.item); const item = album.items.find(item => item.item === filePath); diff --git a/src/routes/[slug]/[[timestamp]]/i/[...item]/+page.svelte b/src/routes/[slug]/[[timestamp]]/i/[...item]/+page.svelte index 13fcbc6..a1382f0 100644 --- a/src/routes/[slug]/[[timestamp]]/i/[...item]/+page.svelte +++ b/src/routes/[slug]/[[timestamp]]/i/[...item]/+page.svelte @@ -1,8 +1,8 @@ -
diff --git a/src/routes/[slug]/[[timestamp]]/i/[...item]/download/+server.js b/src/routes/[slug]/[[timestamp]]/i/[...item]/download/+server.ts similarity index 90% rename from src/routes/[slug]/[[timestamp]]/i/[...item]/download/+server.js rename to src/routes/[slug]/[[timestamp]]/i/[...item]/download/+server.ts index d5c2dc9..65538bd 100644 --- a/src/routes/[slug]/[[timestamp]]/i/[...item]/download/+server.js +++ b/src/routes/[slug]/[[timestamp]]/i/[...item]/download/+server.ts @@ -1,9 +1,9 @@ import { getMetadataAndFile } from '$lib/util/album'; import { getZipName, getFileName, getFilePath } from '$lib/util/links'; import { error } from '@sveltejs/kit'; +import type { RequestHandler } from './$types'; -/** @type {import('./$types').RequestHandler} */ -export async function GET({ params }) { +export const GET: RequestHandler = async ({ params }) => { try { const {album, content} = await getMetadataAndFile(getZipName(params), getFilePath(params.item)); const allowDownload = album.allowDownload === false ? false : true; diff --git a/src/routes/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/+server.js b/src/routes/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/+server.ts similarity index 88% rename from src/routes/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/+server.js rename to src/routes/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/+server.ts index 9ac6fb4..9b271bd 100644 --- a/src/routes/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/+server.js +++ b/src/routes/[slug]/[[timestamp]]/i/[...item]/t/[[width]]/+server.ts @@ -2,9 +2,10 @@ import { getFile } from '$lib/util/album'; import { getFileName, getFilePath, getZipName } from '$lib/util/links'; import { error } from '@sveltejs/kit'; import sharp from 'sharp'; +import type { RequestHandler } from './$types'; -/** @type {import('./$types').RequestHandler} */ -export async function GET({ params }) { +/** @type {RequestHandler} */ +export const GET: RequestHandler = async ({ params }) => { let thumbnail = null; console.log(`Getting thumbnail for ${params}`); let width = 400; @@ -24,7 +25,7 @@ export async function GET({ params }) { } } thumbnail = thumbnail || await sharp(content).resize(width).webp({ quality: 90 }).toBuffer(); - } catch (err) { + } catch (err: any) { console.error(`${/** @type {Error} */(err).stack}`.replaceAll('/home/sveltekit', '.')); throw error(500, 'Error getting thumbnail'); } diff --git a/src/routes/[slug]/[[timestamp]]/random/+server.js b/src/routes/[slug]/[[timestamp]]/random/+server.ts similarity index 83% rename from src/routes/[slug]/[[timestamp]]/random/+server.js rename to src/routes/[slug]/[[timestamp]]/random/+server.ts index 35b23fe..5856dfc 100644 --- a/src/routes/[slug]/[[timestamp]]/random/+server.js +++ b/src/routes/[slug]/[[timestamp]]/random/+server.ts @@ -1,8 +1,9 @@ import StreamZip from 'node-stream-zip'; import sharp from 'sharp'; +import type { RequestHandler } from './$types'; -/** @type {import('./$types').RequestHandler} */ -export async function GET({ params }) { +/** @type {RequestHandler} */ +export const GET: RequestHandler = async ({ params }) => { let entryData = null; try { diff --git a/static/vime.svelte b/static/vime.svelte index 7bc0647..89ad5a8 100644 --- a/static/vime.svelte +++ b/static/vime.svelte @@ -1,4 +1,4 @@ - diff --git a/jsconfig.json b/tsconfig.json similarity index 100% rename from jsconfig.json rename to tsconfig.json