Modern Docker Management, Designed for Everyone
Go composecontainer-managementcontainersdockerdocker-composedocker-managementgoself-hostedsveltekittypescriptweb-ui
fix: use correct settings return type
Kyle Mendell02db09a0402c
diff --git a/frontend/src/lib/services/api/settings-api-service.ts b/frontend/src/lib/services/api/settings-api-service.tsindex 676373f38..640961e6c 100644--- a/frontend/src/lib/services/api/settings-api-service.ts+++ b/frontend/src/lib/services/api/settings-api-service.ts@@ -1,77 +1,61 @@import BaseAPIService from './api-service';import type { Settings, SettingRawResponse, OidcStatusInfo } from '$lib/types/settings.type';+type KeyValuePair = { key: string; value: string };+export default class SettingsAPIService extends BaseAPIService {async getSettings(): Promise<Settings> {- const response = await this.api.get('/settings');- return this.parseConfigList(response.data);+ const res = await this.api.get('/settings');+ return this.normalize(res.data);}async getPublicSettings(): Promise<Settings> {- const response = await this.api.get('/settings/public');- return this.parseConfigList(response.data);+ const res = await this.api.get('/settings/public');+ return this.normalize(res.data);}async updateSettings(settings: Settings) {- // Convert all values to string, with special handling for objects- const settingsConvertedToString = {};+ const payload: Record<string, string> = {};for (const key in settings) {- const value = (settings as any)[key];- if (typeof value === 'object' && value !== null) {- // Serialize objects to JSON string- (settingsConvertedToString as any)[key] = JSON.stringify(value);- } else {- // Convert primitives to string- (settingsConvertedToString as any)[key] = value.toString();- }- }- const res = await this.api.put('/settings', settingsConvertedToString);-- // Check if response has the expected structure- if (res.data && res.data.settings && Array.isArray(res.data.settings)) {- return this.parseConfigList(res.data.settings);- } else {- // If the response doesn't have the expected array format, return the response as-is- // or handle it differently based on your API's actual response structure- console.warn('Unexpected response format from updateSettings:', res.data);- return res.data;+ const v = (settings as any)[key];+ payload[key] = typeof v === 'object' && v !== null ? JSON.stringify(v) : String(v);}+ const res = await this.api.put('/settings', payload);+ return this.normalize(res.data);}async getOidcStatus(): Promise<OidcStatusInfo> {return this.handleResponse(this.api.get('/oidc/status'));}- private parseConfigList(data: SettingRawResponse) {- const settings: Partial<Settings> = {};- data.forEach(({ key, value }) => {- (settings as any)[key] = this.parseValue(key, value);- });+ private normalize(data: any): Settings {+ if (data && !Array.isArray(data) && !Array.isArray(data?.settings)) {+ return data as Settings;+ }++ let list: KeyValuePair[] = [];+ if (Array.isArray(data)) list = data;+ else if (Array.isArray(data?.settings)) list = data.settings;+ const settings: Record<string, unknown> = {};+ list.forEach(({ key, value }) => {+ settings[key] = this.parseValue(key, value);+ });return settings as Settings;}private parseValue(key: string, value: string) {- // Special handling for JSON fieldsif (key === 'onboardingSteps' || key === 'registryCredentials' || key === 'templateRegistries') {try {return JSON.parse(value);} catch {- // Return default empty object/array if parsing failsif (key === 'onboardingSteps') return {};return [];}}-- // Handle other data types- if (value === 'true') {- return true;- } else if (value === 'false') {- return false;- } else if (/^-?\d+(\.\d+)?$/.test(value)) {- return parseFloat(value);- } else {- return value;- }+ if (value === 'true') return true;+ if (value === 'false') return false;+ if (/^-?\d+(\.\d+)?$/.test(value)) return Number(value);+ return value;}}