2024-10-03 11:27:31 +02:00
|
|
|
import type { AllAppConfig, AppConfigRawResponse } from '$lib/types/application-configuration';
|
2024-08-12 11:00:25 +02:00
|
|
|
import APIService from './api-service';
|
|
|
|
|
|
2024-09-09 10:29:41 +02:00
|
|
|
export default class AppConfigService extends APIService {
|
2024-08-12 11:00:25 +02:00
|
|
|
async list(showAll = false) {
|
2024-08-13 20:51:10 +02:00
|
|
|
let url = '/application-configuration';
|
|
|
|
|
if (showAll) {
|
|
|
|
|
url += '/all';
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-09 10:29:41 +02:00
|
|
|
const { data } = await this.api.get<AppConfigRawResponse>(url);
|
2024-08-12 11:00:25 +02:00
|
|
|
|
2024-09-09 10:29:41 +02:00
|
|
|
const appConfig: Partial<AllAppConfig> = {};
|
2024-08-12 11:00:25 +02:00
|
|
|
data.forEach(({ key, value }) => {
|
2024-09-09 10:29:41 +02:00
|
|
|
(appConfig as any)[key] = value;
|
2024-08-12 11:00:25 +02:00
|
|
|
});
|
|
|
|
|
|
2024-09-09 10:29:41 +02:00
|
|
|
return appConfig as AllAppConfig;
|
2024-08-12 11:00:25 +02:00
|
|
|
}
|
|
|
|
|
|
2024-09-09 10:29:41 +02:00
|
|
|
async update(appConfig: AllAppConfig) {
|
|
|
|
|
const res = await this.api.put('/application-configuration', appConfig);
|
|
|
|
|
return res.data as AllAppConfig;
|
2024-08-12 11:00:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async updateFavicon(favicon: File) {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('file', favicon!);
|
|
|
|
|
|
|
|
|
|
await this.api.put(`/application-configuration/favicon`, formData);
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 11:27:31 +02:00
|
|
|
async updateLogo(logo: File, light = true) {
|
2024-08-12 11:00:25 +02:00
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('file', logo!);
|
|
|
|
|
|
2024-10-03 11:27:31 +02:00
|
|
|
await this.api.put(`/application-configuration/logo`, formData, {
|
|
|
|
|
params: { light }
|
|
|
|
|
});
|
2024-08-12 11:00:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async updateBackgroundImage(backgroundImage: File) {
|
|
|
|
|
const formData = new FormData();
|
|
|
|
|
formData.append('file', backgroundImage!);
|
|
|
|
|
|
|
|
|
|
await this.api.put(`/application-configuration/background-image`, formData);
|
|
|
|
|
}
|
|
|
|
|
}
|