feat: update Angular cache with latest TypeScript definitions
This commit is contained in:
@@ -1,26 +1,37 @@
|
||||
import { HttpClient } from '@angular/common/http';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { firstValueFrom } from 'rxjs';
|
||||
import type { ProviderAdapter, ProviderSearchParams, SearchResult } from '../models';
|
||||
import { VideoItem } from 'src/app/shared/models/video-item.model';
|
||||
|
||||
export class OdAdapter implements ProviderAdapter {
|
||||
export class OdAdapter implements ProviderAdapter<VideoItem> {
|
||||
key = 'od' as const;
|
||||
label = 'Odysee';
|
||||
constructor(private http: HttpClient) {}
|
||||
async search(params: ProviderSearchParams, _signal: AbortSignal): Promise<SearchResult> {
|
||||
const res = await firstValueFrom(this.http.get<any>(`/api/search`, { params: { q: params.q, providers: 'od' } }));
|
||||
const items = (res?.groups?.od || []).map((it: any) => ({
|
||||
id: it.id,
|
||||
provider: this.key,
|
||||
title: it.title,
|
||||
channel: it.uploaderName,
|
||||
durationSec: it.duration,
|
||||
thumbUrl: it.thumbnail,
|
||||
watchUrl: it.url || '',
|
||||
views: undefined,
|
||||
publishedAt: undefined,
|
||||
isLive: false,
|
||||
isShort: it.isShort === true
|
||||
}));
|
||||
async search(params: ProviderSearchParams, _signal: AbortSignal): Promise<SearchResult<VideoItem>> {
|
||||
let httpParams = new HttpParams().set('q', params.q).set('providers', 'od');
|
||||
if (params.pageToken) httpParams = httpParams.set('page', params.pageToken);
|
||||
if (params.sort) httpParams = httpParams.set('sort', params.sort);
|
||||
const res = await firstValueFrom(this.http.get<any>(`/api/search`, { params: httpParams }));
|
||||
const items: VideoItem[] = (res?.groups?.od || []).map((it: any) => {
|
||||
let slug: string | undefined;
|
||||
try {
|
||||
const url: string | undefined = it?.url;
|
||||
if (url && /^https?:\/\/odysee\.com\//i.test(url)) {
|
||||
slug = url.replace(/^https?:\/\/odysee\.com\//i, '').replace(/^\//, '');
|
||||
}
|
||||
} catch {}
|
||||
return {
|
||||
id: it.id,
|
||||
provider: 'odysee',
|
||||
title: it.title,
|
||||
channelName: it.uploaderName,
|
||||
durationSec: it.duration,
|
||||
thumbnailUrl: it.thumbnail,
|
||||
viewCount: undefined,
|
||||
publishedAt: undefined,
|
||||
slug,
|
||||
} as VideoItem;
|
||||
});
|
||||
return { items, total: Array.isArray(res?.groups?.od) ? res.groups.od.length : 0 };
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user