Files
showbridge-webui/src/app/services/settings.service.ts
T
2026-03-21 11:52:06 -05:00

55 lines
1.6 KiB
TypeScript

import { computed, Injectable, signal } from '@angular/core';
@Injectable({
providedIn: 'root',
})
export class SettingsService {
public isDummySite: boolean = false;
public configPath = signal('/api/v1/config');
public configSchemaPath = signal('/schema/config.schema.json');
public modulesSchemaPath = signal('/schema/modules.schema.json');
public routesSchemaPath = signal('/schema/routes.schema.json');
public processorsSchemaPath = signal('/schema/processors.schema.json');
public wsPath = signal('/ws');
public baseUrl = signal('http://localhost:8080');
public configUrl = computed(() => {
return new URL(this.configPath(), this.baseUrl());
});
public configSchemaUrl = computed(() => {
return new URL(this.configSchemaPath(), this.baseUrl());
});
public modulesSchemaUrl = computed(() => {
return new URL(this.modulesSchemaPath(), this.baseUrl());
});
public routesSchemaUrl = computed(() => {
return new URL(this.routesSchemaPath(), this.baseUrl());
});
public processorsSchemaUrl = computed(() => {
return new URL(this.processorsSchemaPath(), this.baseUrl());
});
public wsUrl = computed(() => {
const url = new URL(this.baseUrl());
url.protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
url.pathname = this.wsPath();
return url;
});
constructor() {
const storedBaseUrl = localStorage.getItem('baseUrl');
if (storedBaseUrl) {
this.baseUrl.set(storedBaseUrl);
}
}
updateBaseUrl(baseUrl: string) {
this.baseUrl.set(baseUrl);
localStorage.setItem('baseUrl', baseUrl);
}
}