* More email share vars + unfinished placeolders config
{desc} {expires} vars
(unfinished) config placeholder vals
* done
* migrate
* edit seed
* removed comments
* refactor: replace dependecy `luxon` with `moment`
* update shareRecipientsMessage message
* chore: remove `luxon`
* fix: grammatically incorrect `shareRecipientsMessage` message
* changed to defaultValue and value instead
* fix: don't expose defaultValue to non admin user
* fix: update default value if default value changes
* refactor: set config value to null instead of a empty string
* refactor: merge two migrations into one
* fix value check empty
---------
Co-authored-by: Elias Schneider <login@eliasschneider.com>
67 lines
1.8 KiB
TypeScript
67 lines
1.8 KiB
TypeScript
import axios from "axios";
|
|
import Config, { AdminConfig, UpdateConfig } from "../types/config.type";
|
|
import api from "./api.service";
|
|
|
|
const list = async (): Promise<Config[]> => {
|
|
return (await api.get("/configs")).data;
|
|
};
|
|
|
|
const getByCategory = async (category: string): Promise<AdminConfig[]> => {
|
|
return (await api.get(`/configs/admin/${category}`)).data;
|
|
};
|
|
|
|
const updateMany = async (data: UpdateConfig[]): Promise<AdminConfig[]> => {
|
|
return (await api.patch("/configs/admin", data)).data;
|
|
};
|
|
|
|
const get = (key: string, configVariables: Config[]): any => {
|
|
if (!configVariables) return null;
|
|
|
|
const configVariable = configVariables.filter(
|
|
(variable) => variable.key == key
|
|
)[0];
|
|
|
|
if (!configVariable) throw new Error(`Config variable ${key} not found`);
|
|
|
|
const value = configVariable.value ?? configVariable.defaultValue;
|
|
|
|
if (configVariable.type == "number") return parseInt(value);
|
|
if (configVariable.type == "boolean") return value == "true";
|
|
if (configVariable.type == "string" || configVariable.type == "text")
|
|
return value;
|
|
};
|
|
|
|
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;
|
|
};
|
|
|
|
const changeLogo = async (file: File) => {
|
|
const form = new FormData();
|
|
form.append("file", file);
|
|
|
|
await api.post("/configs/admin/logo", form);
|
|
};
|
|
export default {
|
|
list,
|
|
getByCategory,
|
|
updateMany,
|
|
get,
|
|
finishSetup,
|
|
sendTestEmail,
|
|
isNewReleaseAvailable,
|
|
changeLogo,
|
|
};
|