2022-12-30 19:23:17 +01:00
|
|
|
import axios from "axios";
|
2022-12-30 14:40:23 +01:00
|
|
|
import Config, { AdminConfig, UpdateConfig } from "../types/config.type";
|
2022-11-28 17:50:36 +01:00
|
|
|
import api from "./api.service";
|
|
|
|
|
2022-12-01 23:07:49 +01:00
|
|
|
const list = async (): Promise<Config[]> => {
|
2022-11-28 17:50:36 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2022-12-30 14:40:23 +01:00
|
|
|
const updateMany = async (data: UpdateConfig[]): Promise<AdminConfig[]> => {
|
|
|
|
return (await api.patch("/configs/admin", data)).data;
|
2022-12-01 23:07:49 +01:00
|
|
|
};
|
|
|
|
|
2022-11-28 17:50:36 +01:00
|
|
|
const get = (key: string, configVariables: Config[]): any => {
|
2022-12-01 23:07:49 +01:00
|
|
|
if (!configVariables) return null;
|
|
|
|
|
2022-11-28 17:50:36 +01:00
|
|
|
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";
|
2022-12-30 14:40:23 +01:00
|
|
|
if (configVariable.type == "string" || configVariable.type == "text")
|
|
|
|
return configVariable.value;
|
2022-11-28 17:50:36 +01:00
|
|
|
};
|
|
|
|
|
2022-12-01 23:07:49 +01:00
|
|
|
const finishSetup = async (): Promise<AdminConfig[]> => {
|
|
|
|
return (await api.post("/configs/admin/finishSetup")).data;
|
|
|
|
};
|
|
|
|
|
2022-12-30 14:40:23 +01:00
|
|
|
const sendTestEmail = async (email: string) => {
|
|
|
|
await api.post("/configs/admin/testEmail", { email });
|
|
|
|
};
|
|
|
|
|
2022-12-30 19:23:17 +01:00
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
2022-11-28 17:50:36 +01:00
|
|
|
export default {
|
2022-12-01 23:07:49 +01:00
|
|
|
list,
|
|
|
|
listForAdmin,
|
2022-12-30 14:40:23 +01:00
|
|
|
updateMany,
|
2022-11-28 17:50:36 +01:00
|
|
|
get,
|
2022-12-01 23:07:49 +01:00
|
|
|
finishSetup,
|
2022-12-30 14:40:23 +01:00
|
|
|
sendTestEmail,
|
2022-12-30 19:23:17 +01:00
|
|
|
isNewReleaseAvailable,
|
2022-11-28 17:50:36 +01:00
|
|
|
};
|