chore: update Angular TypeScript build info cache
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { HttpClient, HttpParams } from '@angular/common/http';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
export interface Playlist {
|
||||
id: string;
|
||||
userId?: string;
|
||||
title: string;
|
||||
description?: string | null;
|
||||
thumbnail?: string | null;
|
||||
isPrivate: boolean | number;
|
||||
createdAt: string;
|
||||
updatedAt: string;
|
||||
itemsCount?: number;
|
||||
}
|
||||
|
||||
export interface PlaylistItem {
|
||||
id: string;
|
||||
playlistId: string;
|
||||
provider: string;
|
||||
videoId: string;
|
||||
title?: string | null;
|
||||
thumbnail?: string | null;
|
||||
addedAt: string;
|
||||
position: number;
|
||||
}
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class PlaylistsService {
|
||||
private http = inject(HttpClient);
|
||||
|
||||
private apiBase(): string {
|
||||
try {
|
||||
const port = window?.location?.port || '';
|
||||
return port && port !== '4000' ? '/proxy/api' : '/api';
|
||||
} catch {
|
||||
return '/api';
|
||||
}
|
||||
}
|
||||
|
||||
list(limit = 100, offset = 0, q?: string): Observable<Playlist[]> {
|
||||
let params = new HttpParams().set('limit', String(limit)).set('offset', String(offset));
|
||||
if (q && q.trim().length) params = params.set('q', q.trim());
|
||||
return this.http.get<Playlist[]>(`${this.apiBase()}/playlists`, { params, withCredentials: true });
|
||||
}
|
||||
|
||||
get(id: string, limit = 200, offset = 0): Observable<Playlist & { items: PlaylistItem[] }> {
|
||||
const params = new HttpParams().set('limit', String(limit)).set('offset', String(offset));
|
||||
return this.http.get<Playlist & { items: PlaylistItem[] }>(`${this.apiBase()}/playlists/${encodeURIComponent(id)}`, { params, withCredentials: true });
|
||||
}
|
||||
|
||||
create(title: string, description?: string, thumbnail?: string, isPrivate: boolean = true): Observable<Playlist> {
|
||||
return this.http.post<Playlist>(`${this.apiBase()}/playlists`, { title, description, thumbnail, isPrivate }, { withCredentials: true });
|
||||
}
|
||||
|
||||
update(id: string, patch: Partial<{ title: string; description: string; thumbnail: string; isPrivate: boolean }>): Observable<Playlist> {
|
||||
return this.http.put<Playlist>(`${this.apiBase()}/playlists/${encodeURIComponent(id)}`, patch, { withCredentials: true });
|
||||
}
|
||||
|
||||
remove(id: string): Observable<void> {
|
||||
return this.http.delete<void>(`${this.apiBase()}/playlists/${encodeURIComponent(id)}`, { withCredentials: true });
|
||||
}
|
||||
|
||||
addVideo(playlistId: string, provider: string, videoId: string, title?: string, thumbnail?: string, opts?: { slug?: string; instance?: string; sourceUrl?: string }): Observable<PlaylistItem> {
|
||||
const body: any = { provider, videoId, title, thumbnail };
|
||||
if (opts?.slug) body.slug = opts.slug;
|
||||
if (opts?.instance) body.instance = opts.instance;
|
||||
if (opts?.sourceUrl) body.sourceUrl = opts.sourceUrl;
|
||||
return this.http.post<PlaylistItem>(`${this.apiBase()}/playlists/${encodeURIComponent(playlistId)}/videos`, body, { withCredentials: true });
|
||||
}
|
||||
|
||||
removeVideo(playlistId: string, provider: string, videoId: string): Observable<{ removed: boolean }> {
|
||||
const params = new HttpParams().set('provider', provider);
|
||||
return this.http.delete<{ removed: boolean }>(`${this.apiBase()}/playlists/${encodeURIComponent(playlistId)}/videos/${encodeURIComponent(videoId)}`, { params, withCredentials: true });
|
||||
}
|
||||
|
||||
reorder(playlistId: string, order: Array<string | { id?: string; provider?: string; videoId?: string }>): Observable<{ changed: number }> {
|
||||
return this.http.put<{ changed: number }>(`${this.apiBase()}/playlists/${encodeURIComponent(playlistId)}/reorder`, { order }, { withCredentials: true });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user