chore: update Angular cache and TypeScript build info files
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { BehaviorSubject, combineLatest, distinctUntilChanged, debounceTime, map, switchMap } from 'rxjs';
|
||||
import type { ProviderId } from '../core/providers/provider-registry';
|
||||
|
||||
export interface SuggestionItem {
|
||||
title: string;
|
||||
id: string;
|
||||
duration?: number;
|
||||
isShort?: boolean;
|
||||
thumbnail?: string;
|
||||
uploaderName?: string;
|
||||
url?: string;
|
||||
type?: string; // 'video' | 'channel' | ...
|
||||
}
|
||||
|
||||
export interface SearchResponse {
|
||||
q: string;
|
||||
providers: ProviderId[];
|
||||
groups: Record<ProviderId, SuggestionItem[]>;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class SearchService {
|
||||
private http = inject(HttpClient);
|
||||
|
||||
readonly q$ = new BehaviorSubject<string>('');
|
||||
readonly providers$ = new BehaviorSubject<ProviderId[] | 'all'>('all');
|
||||
|
||||
readonly params$ = combineLatest([this.q$, this.providers$]).pipe(
|
||||
debounceTime(120),
|
||||
distinctUntilChanged((a, b) => JSON.stringify(a) === JSON.stringify(b))
|
||||
);
|
||||
|
||||
readonly request$ = this.params$.pipe(
|
||||
switchMap(([q, prov]) => {
|
||||
const providersParam = (prov === 'all')
|
||||
? 'yt,dm,tw,pt,od,ru'
|
||||
: (Array.isArray(prov) && prov.length > 0 ? prov.join(',') : '');
|
||||
return this.http.get<SearchResponse>('/api/search', {
|
||||
params: { q, providers: providersParam }
|
||||
});
|
||||
})
|
||||
);
|
||||
|
||||
// Convenience setter helpers
|
||||
setQuery(q: string) { this.q$.next(q || ''); }
|
||||
setProviders(list: ProviderId[] | 'all') { this.providers$.next(list && (Array.isArray(list) ? list : 'all')); }
|
||||
}
|
||||
Reference in New Issue
Block a user