1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-10-05 10:50:10 +02:00
pingvin-share/frontend/src/services/config.service.ts

58 lines
1.6 KiB
TypeScript
Raw Normal View History

import axios from "axios";
import Config, { AdminConfig, UpdateConfig } from "../types/config.type";
import api from "./api.service";
2022-12-01 23:07:49 +01:00
const list = async (): Promise<Config[]> => {
return (await api.get("/configs")).data;
};
2022-12-01 23:07:49 +01:00
const listForAdmin = async (): Promise<AdminConfig[]> => {
return (await api.get("/configs/admin")).data;
};
const updateMany = async (data: UpdateConfig[]): Promise<AdminConfig[]> => {
return (await api.patch("/configs/admin", data)).data;
2022-12-01 23:07:49 +01:00
};
const get = (key: string, configVariables: Config[]): any => {
2022-12-01 23:07:49 +01:00
if (!configVariables) return null;
const configVariable = configVariables.filter(
(variable) => variable.key == key
)[0];
if (!configVariable) throw new Error(`Config variable ${key} not found`);
if (configVariable.type == "number") return parseInt(configVariable.value);
if (configVariable.type == "boolean") return configVariable.value == "true";
if (configVariable.type == "string" || configVariable.type == "text")
return configVariable.value;
};
2022-12-01 23:07:49 +01:00
const finishSetup = async (): Promise<AdminConfig[]> => {
return (await api.post("/configs/admin/finishSetup")).data;
};
const sendTestEmail = async (email: string) => {
await api.post("/configs/admin/testEmail", { email });
};
const isNewReleaseAvailable = async () => {
const response = (
await axios.get(
"https://api.github.com/repos/stonith404/pingvin-share/releases/latest"
)
).data;
return response.tag_name.replace("v", "") != process.env.VERSION;
};
export default {
2022-12-01 23:07:49 +01:00
list,
listForAdmin,
updateMany,
get,
2022-12-01 23:07:49 +01:00
finishSetup,
sendTestEmail,
isNewReleaseAvailable,
};