diff --git a/src/lib/components/bandcamp/index.svelte b/src/lib/components/bandcamp/index.svelte index 0654772..dfdf2d9 100644 --- a/src/lib/components/bandcamp/index.svelte +++ b/src/lib/components/bandcamp/index.svelte @@ -33,7 +33,7 @@ rel="noreferrer" >

{album.title.length > 20 ? `${album.title.slice(0, 20)}...` : album.title}

-

by {album.artist}

+

{album.artist}

{/each} diff --git a/src/lib/util/fetchBandcampAlbums.ts b/src/lib/util/fetchBandcampAlbums.ts index 3a0932a..351757c 100644 --- a/src/lib/util/fetchBandcampAlbums.ts +++ b/src/lib/util/fetchBandcampAlbums.ts @@ -1,15 +1,16 @@ import { BANDCAMP_USERNAME, USE_REDIS_CACHE } from '$env/static/private'; import scrapeIt from 'scrape-it'; +import type { ScrapeResult } from 'scrape-it'; import { redis } from '../server/redis'; import type { Album } from '../types/album'; export async function fetchBandcampAlbums() { try { if (USE_REDIS_CACHE) { - const cached = await redis.get('bandcampAlbums'); + const cached: string | null = await redis.get('bandcampAlbums'); if (cached) { - const response = JSON.parse(cached); + const response: Album[] = JSON.parse(cached); console.log(`Cache hit!`); const ttl = await redis.ttl('bandcampAlbums'); @@ -17,27 +18,30 @@ export async function fetchBandcampAlbums() { } } - const { data } = await scrapeIt(`https://bandcamp.com/${BANDCAMP_USERNAME}`, { - collectionItems: { - listItem: '.collection-item-container', - data: { - url: { - selector: '.collection-title-details > a.item-link', - attr: 'href' - }, - artwork: { - selector: 'div.collection-item-art-container a img', - attr: 'src' - }, - title: { - selector: 'span.item-link-alt > div.collection-item-title' - }, - artist: { - selector: 'span.item-link-alt > div.collection-item-artist' + const { data }: ScrapeResult = await scrapeIt( + `https://bandcamp.com/${BANDCAMP_USERNAME}`, + { + collectionItems: { + listItem: '.collection-item-container', + data: { + url: { + selector: '.collection-title-details > a.item-link', + attr: 'href' + }, + artwork: { + selector: 'div.collection-item-art-container a img', + attr: 'src' + }, + title: { + selector: 'span.item-link-alt > div.collection-item-title' + }, + artist: { + selector: 'span.item-link-alt > div.collection-item-artist' + } } } } - }); + ); const albums: Album[] = data?.collectionItems || []; // console.log(`Albums ${JSON.stringify(albums)}`); diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 335f2d9..46c88d5 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -1,5 +1,4 @@ import type { PageServerLoad } from './lib/$types'; -import { PAGE_SIZE } from '$env/static/private'; import { fetchBandcampAlbums } from '$root/lib/util/fetchBandcampAlbums'; export const load: PageServerLoad = async ({ fetch, setHeaders }) => { diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index b07fce3..b7546c3 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -77,7 +77,7 @@