@@ -5,6 +5,8 @@ import { getSessionUserId } from "~/lib/auth/session.server";
55import {
66 consumeSearchRateLimit ,
77 getCachedSearchResult ,
8+ getChannelBlacklistByChannelId ,
9+ getChannelBySlug ,
810 searchCatalogSongs as searchCatalogSongsInDb ,
911 upsertCachedSearchResult ,
1012} from "~/lib/db/repositories" ;
@@ -20,6 +22,8 @@ function normalizeSearchCacheInput(
2022) {
2123 return {
2224 query : input . query ?? "" ,
25+ channelSlug : input . channelSlug ?? "" ,
26+ showBlacklisted : input . showBlacklisted ?? false ,
2327 field : input . field ,
2428 title : input . title ?? "" ,
2529 artist : input . artist ?? "" ,
@@ -62,6 +66,8 @@ export const Route = createFileRoute("/api/search")({
6266
6367 const payload = {
6468 query : url . searchParams . get ( "query" ) ?? undefined ,
69+ channelSlug : url . searchParams . get ( "channelSlug" ) ?? undefined ,
70+ showBlacklisted : url . searchParams . get ( "showBlacklisted" ) ?? undefined ,
6571 field : url . searchParams . get ( "field" ) ?? undefined ,
6672 title : url . searchParams . get ( "title" ) ?? undefined ,
6773 artist : url . searchParams . get ( "artist" ) ?? undefined ,
@@ -137,10 +143,37 @@ export const Route = createFileRoute("/api/search")({
137143 }
138144
139145 try {
140- const results = await searchCatalogSongsInDb (
141- runtimeEnv ,
142- normalizedInput
143- ) ;
146+ let blacklistFilterInput = { } ;
147+ if ( normalizedInput . channelSlug && ! normalizedInput . showBlacklisted ) {
148+ const channel = await getChannelBySlug (
149+ runtimeEnv ,
150+ normalizedInput . channelSlug
151+ ) ;
152+
153+ if ( channel ) {
154+ const blacklist = await getChannelBlacklistByChannelId (
155+ runtimeEnv ,
156+ channel . id
157+ ) ;
158+
159+ blacklistFilterInput = {
160+ excludeSongIds : blacklist . blacklistSongs . map (
161+ ( song ) => song . songId
162+ ) ,
163+ excludeArtistNames : blacklist . blacklistArtists . map (
164+ ( artist ) => artist . artistName
165+ ) ,
166+ excludeCreatorNames : blacklist . blacklistCharters . map (
167+ ( charter ) => charter . charterName
168+ ) ,
169+ } ;
170+ }
171+ }
172+
173+ const results = await searchCatalogSongsInDb ( runtimeEnv , {
174+ ...normalizedInput ,
175+ ...blacklistFilterInput ,
176+ } ) ;
144177
145178 await upsertCachedSearchResult ( runtimeEnv , {
146179 cacheKey,
0 commit comments