database driven image uploader and storage service model

This commit is contained in:
2026-06-22 19:29:06 +00:00
parent 76894061c5
commit 3b61a131c1
31 changed files with 433 additions and 149 deletions
+13
View File
@@ -42,3 +42,16 @@ export const appConfigInitProvider = {
export function getAppConfig(): AppConfig {
return _appConfig;
}
/** Resolve an image URL for rendering.
* - Absolute HTTP(S) URLs are returned as-is.
* - Static SVG assets (svg/…) are served by the Angular build — returned as-is.
* - API paths (/api/storage/…) and legacy paths (uploads/…) are prefixed with apiBaseUrl.
*/
export function resolveImageUrl(url: string): string {
if (!url) return '';
if (url.startsWith('http://') || url.startsWith('https://')) return url;
if (url.startsWith('svg/')) return url;
if (url.startsWith('/')) return `${getAppConfig().apiBaseUrl}${url}`;
return `${getAppConfig().apiBaseUrl}/${url}`;
}
+1 -1
View File
@@ -60,7 +60,7 @@ export class StationConfigService {
const formData = new FormData();
formData.append('file', file);
const response = await firstValueFrom(
this.http.post<{ url: string }>(`${this.baseUrl}/upload`, formData),
this.http.post<{ url: string }>(`${getAppConfig().apiBaseUrl}/api/storage/upload`, formData),
);
return response.url;
}
+1 -1
View File
@@ -10,7 +10,7 @@ import { getAppConfig } from './app-config.service';
})
export class UploadService {
private http = inject(HttpClient);
private baseUrl = `${getAppConfig().apiBaseUrl}/api/upload/image`;
private baseUrl = `${getAppConfig().apiBaseUrl}/api/storage/upload`;
/** Upload an image file. Returns the relative URL (e.g. `uploads/abc123.png`). */
async uploadImage(file: File): Promise<string> {