database driven image uploader and storage service model
This commit is contained in:
@@ -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}`;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
|
||||
Reference in New Issue
Block a user