1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-09-21 12:30:12 +02:00
pingvin-share/backend/prisma/seed/config.seed.ts

266 lines
6.9 KiB
TypeScript
Raw Normal View History

2022-12-08 19:14:06 +01:00
import { Prisma, PrismaClient } from "@prisma/client";
2022-12-02 15:10:49 +01:00
import * as crypto from "crypto";
2022-12-08 19:14:06 +01:00
const configVariables: Prisma.ConfigCreateInput[] = [
2022-12-02 15:10:49 +01:00
{
2023-01-26 14:06:25 +01:00
order: 0,
key: "SETUP_STATUS",
2023-01-26 14:06:25 +01:00
description: "Status of the setup wizard",
type: "string",
value: "STARTED", // STARTED, REGISTERED, FINISHED
category: "internal",
2022-12-02 15:10:49 +01:00
secret: false,
locked: true,
},
{
2023-01-26 14:06:25 +01:00
order: 0,
key: "JWT_SECRET",
description: "Long random string used to sign JWT tokens",
type: "string",
value: crypto.randomBytes(256).toString("base64"),
category: "internal",
locked: true,
},
{
order: 1,
key: "APP_URL",
2022-12-02 15:10:49 +01:00
description: "On which URL Pingvin Share is available",
type: "string",
value: "http://localhost:3000",
category: "general",
2022-12-02 15:10:49 +01:00
secret: false,
},
{
2023-01-26 14:06:25 +01:00
order: 2,
key: "SHOW_HOME_PAGE",
2022-12-02 15:10:49 +01:00
description: "Whether to show the home page",
type: "boolean",
value: "true",
category: "general",
2022-12-02 15:10:49 +01:00
secret: false,
},
{
2023-01-26 14:06:25 +01:00
order: 3,
key: "ALLOW_REGISTRATION",
2022-12-02 15:10:49 +01:00
description: "Whether registration is allowed",
type: "boolean",
value: "true",
category: "share",
2022-12-02 15:10:49 +01:00
secret: false,
},
{
2023-01-26 14:06:25 +01:00
order: 4,
key: "ALLOW_UNAUTHENTICATED_SHARES",
2022-12-02 15:10:49 +01:00
description: "Whether unauthorized users can create shares",
type: "boolean",
value: "false",
category: "share",
2022-12-02 15:10:49 +01:00
secret: false,
},
{
2023-01-26 14:06:25 +01:00
order: 5,
key: "MAX_SHARE_SIZE",
description: "Maximum share size in bytes",
2022-12-02 15:10:49 +01:00
type: "number",
value: "1073741824",
category: "share",
2022-12-02 15:10:49 +01:00
secret: false,
},
2023-01-26 14:06:25 +01:00
2022-12-02 15:10:49 +01:00
{
2023-01-26 14:06:25 +01:00
order: 6,
key: "ENABLE_SHARE_EMAIL_RECIPIENTS",
2022-12-02 15:10:49 +01:00
description:
"Whether to allow emails to share recipients. Only enable this if you have enabled SMTP.",
2022-12-02 15:10:49 +01:00
type: "boolean",
value: "false",
category: "email",
2022-12-02 15:10:49 +01:00
secret: false,
},
2022-12-15 21:44:04 +01:00
{
2023-01-26 14:06:25 +01:00
order: 7,
2023-02-09 18:17:53 +01:00
key: "SHARE_RECEPIENTS_EMAIL_SUBJECT",
description:
"Subject of the email which gets sent to the share recipients.",
type: "string",
value: "Files shared with you",
category: "email",
},
{
order: 8,
key: "SHARE_RECEPIENTS_EMAIL_MESSAGE",
2022-12-23 10:57:09 +01:00
description:
"Message which gets sent to the share recipients. {creator} and {shareUrl} will be replaced with the creator's name and the share URL.",
2022-12-15 21:44:04 +01:00
type: "text",
2022-12-23 10:57:09 +01:00
value:
"Hey!\n{creator} shared some files with you. View or download the files with this link: {shareUrl}\nShared securely with Pingvin Share 🐧",
category: "email",
2022-12-23 10:57:09 +01:00
},
{
2023-02-09 18:17:53 +01:00
order: 9,
key: "REVERSE_SHARE_EMAIL_SUBJECT",
description:
2023-02-09 18:17:53 +01:00
"Subject of the email which gets sent when someone created a share with your reverse share link.",
2022-12-23 10:57:09 +01:00
type: "string",
2023-02-09 18:17:53 +01:00
value: "Reverse share link used",
category: "email",
2022-12-15 21:44:04 +01:00
},
2022-12-02 15:10:49 +01:00
{
2023-02-09 18:17:53 +01:00
order: 10,
key: "REVERSE_SHARE_EMAIL_MESSAGE",
description:
"Message which gets sent when someone created a share with your reverse share link. {shareUrl} will be replaced with the creator's name and the share URL.",
type: "text",
value:
"Hey!\nA share was just created with your reverse share link: {shareUrl}\nShared securely with Pingvin Share 🐧",
category: "email",
},
{
2023-02-09 18:17:53 +01:00
order: 11,
key: "RESET_PASSWORD_EMAIL_SUBJECT",
description:
2023-02-09 18:17:53 +01:00
"Subject of the email which gets sent when a user requests a password reset.",
type: "string",
2023-02-09 18:17:53 +01:00
value: "Pingvin Share password reset",
category: "email",
},
{
2023-02-09 18:17:53 +01:00
order: 12,
key: "RESET_PASSWORD_EMAIL_MESSAGE",
description:
"Message which gets sent when a user requests a password reset. {url} will be replaced with the reset password URL.",
type: "text",
value:
"Hey!\nYou requested a password reset. Click this link to reset your password: {url}\nThe link expires in a hour.\nPingvin Share 🐧",
category: "email",
},
{
order: 13,
2023-02-21 08:51:04 +01:00
key: "INVITE_EMAIL_SUBJECT",
description:
"Subject of the email which gets sent when an admin invites an user.",
type: "string",
value: "Pingvin Share invite",
category: "email",
},
{
order: 14,
key: "INVITE_EMAIL_MESSAGE",
description:
"Message which gets sent when an admin invites an user. {url} will be replaced with the invite URL and {password} with the password.",
type: "text",
value:
"Hey!\nYou were invited to Pingvin Share. Click this link to accept the invite: {url}\nYour password is: {password}\nPingvin Share 🐧",
category: "email",
},
{
order: 15,
key: "SMTP_ENABLED",
description:
"Whether SMTP is enabled. Only set this to true if you entered the host, port, email, user and password of your SMTP server.",
type: "boolean",
value: "false",
category: "smtp",
secret: false,
},
{
2023-02-21 08:51:04 +01:00
order: 16,
key: "SMTP_HOST",
2022-12-02 15:10:49 +01:00
description: "Host of the SMTP server",
type: "string",
value: "",
category: "smtp",
2022-12-02 15:10:49 +01:00
},
{
2023-02-21 08:51:04 +01:00
order: 17,
key: "SMTP_PORT",
2022-12-02 15:10:49 +01:00
description: "Port of the SMTP server",
type: "number",
value: "0",
category: "smtp",
2022-12-02 15:10:49 +01:00
},
{
2023-02-21 08:51:04 +01:00
order: 18,
key: "SMTP_EMAIL",
description: "Email address which the emails get sent from",
type: "string",
value: "",
category: "smtp",
},
{
2023-02-21 08:51:04 +01:00
order: 19,
key: "SMTP_USERNAME",
description: "Username of the SMTP server",
2022-12-02 15:10:49 +01:00
type: "string",
value: "",
category: "smtp",
2022-12-02 15:10:49 +01:00
},
{
2023-02-21 08:51:04 +01:00
order: 20,
key: "SMTP_PASSWORD",
2022-12-02 15:10:49 +01:00
description: "Password of the SMTP server",
type: "string",
value: "",
2022-12-08 19:14:06 +01:00
obscured: true,
category: "smtp",
2022-12-02 15:10:49 +01:00
},
];
const prisma = new PrismaClient();
async function main() {
for (const variable of configVariables) {
const existingConfigVariable = await prisma.config.findUnique({
where: { key: variable.key },
});
// Create a new config variable if it doesn't exist
if (!existingConfigVariable) {
await prisma.config.create({
data: variable,
});
}
}
const configVariablesFromDatabase = await prisma.config.findMany();
// Delete the config variable if it doesn't exist anymore
for (const configVariableFromDatabase of configVariablesFromDatabase) {
const configVariable = configVariables.find(
(v) => v.key == configVariableFromDatabase.key
);
if (!configVariable) {
await prisma.config.delete({
where: { key: configVariableFromDatabase.key },
});
// Update the config variable if the metadata changed
} else if (
JSON.stringify({
2022-12-08 21:58:58 +01:00
...configVariable,
key: configVariableFromDatabase.key,
value: configVariableFromDatabase.value,
}) != JSON.stringify(configVariableFromDatabase)
) {
await prisma.config.update({
where: { key: configVariableFromDatabase.key },
2022-12-08 21:58:58 +01:00
data: {
...configVariable,
key: configVariableFromDatabase.key,
value: configVariableFromDatabase.value,
},
});
}
}
}
main()
.then(async () => {
await prisma.$disconnect();
})
.catch(async (e) => {
console.error(e);
await prisma.$disconnect();
process.exit(1);
});