@@ -8,6 +8,11 @@ import type { Artist, Tape, Year, ArtistShows, Show, Day } from '@/types';
88export class RelistenAPI {
99 private static baseURL = API_DOMAIN ;
1010
11+ // Validate artist slug format
12+ private static isValidArtistSlug ( slug : string ) : boolean {
13+ return / ^ [ a - z - ] + $ / i. test ( slug ) ;
14+ }
15+
1116 // Generic cached fetch method
1217 private static cachedFetch = cache (
1318 async < T > (
@@ -72,10 +77,8 @@ export class RelistenAPI {
7277 static fetchRandomShow = cache ( async ( artistSlug : string ) : Promise < Partial < Tape > | undefined > => {
7378 if ( ! artistSlug ) return undefined ;
7479
75- // if doesnt match
76- if ( ! / ^ [ a - z - ] + $ / i. test ( artistSlug ) ) {
80+ if ( ! this . isValidArtistSlug ( artistSlug ) ) {
7781 console . error ( 'Tried to load url that doesnt match artist slug format:' , artistSlug ) ;
78-
7982 return notFound ( ) ;
8083 }
8184
@@ -88,6 +91,11 @@ export class RelistenAPI {
8891 static fetchYears = cache ( async ( slug ?: string ) : Promise < Year [ ] > => {
8992 if ( ! slug ) return [ ] ;
9093
94+ if ( ! this . isValidArtistSlug ( slug ) ) {
95+ console . error ( 'Tried to load url that doesnt match artist slug format:' , slug ) ;
96+ return notFound ( ) ;
97+ }
98+
9199 return this . cachedFetch < Year [ ] > ( `/api/v2/artists/${ slug } /years` ) ;
92100 } ) ;
93101
@@ -123,9 +131,7 @@ export class RelistenAPI {
123131 static fetchRecentlyAdded = cache ( async ( artistSlug ?: string ) : Promise < Show [ ] > => {
124132 if ( ! artistSlug ) return [ ] ;
125133
126- return this . cachedFetch < Show [ ] > (
127- `/api/v2/artists/${ artistSlug } /shows/recently-added`
128- ) ;
134+ return this . cachedFetch < Show [ ] > ( `/api/v2/artists/${ artistSlug } /shows/recently-added` ) ;
129135 } ) ;
130136
131137 // Live API
0 commit comments