import { Injectable, inject } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { firstValueFrom } from 'rxjs'; import { getAppConfig } from './app-config.service'; /** Shared service for uploading image files via the admin API. */ @Injectable({ providedIn: 'root', }) export class UploadService { private http = inject(HttpClient); private baseUrl = `${getAppConfig().apiBaseUrl}/api/upload/image`; /** Upload an image file. Returns the relative URL (e.g. `uploads/abc123.png`). */ async uploadImage(file: File): Promise { const formData = new FormData(); formData.append('file', file); const response = await firstValueFrom( this.http.post<{ url: string }>(this.baseUrl, formData), ); return response.url; } }