import { Injectable } from '@angular/core'; import { HttpClient, HttpParams } from '@angular/common/http'; import { Observable } from 'rxjs'; export interface ImageRecord { id: string; hash: string; filename: string; mime_type: string; size_bytes: number; width: number; height: number; storage_key: string; thumbnail_key: string | null; created_at: string; tags: string[]; duplicate?: boolean; } export interface ImageListResponse { items: ImageRecord[]; total: number; limit: number; offset: number; } @Injectable({ providedIn: 'root' }) export class ImageService { private readonly base = '/api/v1'; constructor(private http: HttpClient) {} upload(file: File, tags: string[]): Observable { const form = new FormData(); form.append('file', file); if (tags.length) { form.append('tags', tags.join(',')); } return this.http.post(`${this.base}/images`, form); } list(tagFilter: string[] = [], limit = 50, offset = 0): Observable { let params = new HttpParams().set('limit', limit).set('offset', offset); if (tagFilter.length) { params = params.set('tags', tagFilter.join(',')); } return this.http.get(`${this.base}/images`, { params }); } get(id: string): Observable { return this.http.get(`${this.base}/images/${id}`); } getFileUrl(id: string): string { return `${this.base}/images/${id}/file`; } getThumbnailUrl(id: string): string { return `${this.base}/images/${id}/thumbnail`; } updateTags(id: string, tags: string[]): Observable { return this.http.patch(`${this.base}/images/${id}/tags`, { tags }); } delete(id: string): Observable { return this.http.delete(`${this.base}/images/${id}`); } }