working basic site admin

This commit is contained in:
2026-06-21 02:56:49 +00:00
parent 53d932655e
commit f52625b37b
38 changed files with 1163 additions and 56 deletions
@@ -0,0 +1,67 @@
import { Injectable, inject, signal } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { firstValueFrom } from 'rxjs';
import { StationConfig } from '../interfaces/station-config';
import { getAppConfig } from './app-config.service';
/** Hardcoded defaults — used when the API is unavailable (dev fallback). */
const DEFAULT_CONFIG: StationConfig = {
id: 0,
key: 'default',
callsign: 'KMTN',
name_primary: 'KMountain',
name_secondary: 'Flower Radio',
tagline: 'Community Radio — Est. 1987',
frequency: '98.7 FM',
founded_year: 1987,
nonprofit_type: '501(c)(3)',
ein: '84-XXXXXXX',
logo_url: 'svg/small-flower.svg',
hero_background_url: 'svg/mountain-landscape.svg',
hero_icon_url: 'svg/orange-flower.svg',
hero_divider_url: 'svg/mountain-divider.svg',
address: '42 Pine Street\nMountain View, CO 80424',
phone: '(970) 555-0198',
email: 'hello@kmountainflower.org',
website: 'kmountainflower.org',
};
@Injectable({
providedIn: 'root',
})
export class StationConfigService {
private http = inject(HttpClient);
private baseUrl = `${getAppConfig().apiBaseUrl}/api/station-config`;
readonly config = signal<StationConfig>(DEFAULT_CONFIG);
/** Load station config from the API. Falls back to defaults on error. */
async load(): Promise<void> {
try {
const data = await firstValueFrom(this.http.get<StationConfig>(this.baseUrl));
this.config.set(data);
} catch {
// Keep the default config if the API is unavailable.
console.warn('StationConfigService: Failed to load config, using defaults.');
}
}
/** Update station config (admin only). */
async updateConfig(payload: Partial<StationConfig>): Promise<void> {
const data = await firstValueFrom(
this.http.put<StationConfig>(this.baseUrl, payload),
);
this.config.set(data);
}
/** Upload an image file for station branding (admin only). Returns the relative URL. */
async uploadImage(file: File): Promise<string> {
const formData = new FormData();
formData.append('file', file);
const response = await firstValueFrom(
this.http.post<{ url: string }>(`${this.baseUrl}/upload`, formData),
);
return response.url;
}
}