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
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
key: "SETUP_FINISHED",
|
2022-12-02 15:10:49 +01:00
|
|
|
description: "Whether the setup has been finished",
|
|
|
|
type: "boolean",
|
|
|
|
value: "false",
|
|
|
|
secret: false,
|
|
|
|
locked: true,
|
|
|
|
},
|
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
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",
|
|
|
|
secret: false,
|
|
|
|
},
|
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
key: "SHOW_HOME_PAGE",
|
2022-12-02 15:10:49 +01:00
|
|
|
description: "Whether to show the home page",
|
|
|
|
type: "boolean",
|
|
|
|
value: "true",
|
|
|
|
secret: false,
|
|
|
|
},
|
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
key: "ALLOW_REGISTRATION",
|
2022-12-02 15:10:49 +01:00
|
|
|
description: "Whether registration is allowed",
|
|
|
|
type: "boolean",
|
|
|
|
value: "true",
|
|
|
|
secret: false,
|
|
|
|
},
|
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
key: "ALLOW_UNAUTHENTICATED_SHARES",
|
2022-12-02 15:10:49 +01:00
|
|
|
description: "Whether unauthorized users can create shares",
|
|
|
|
type: "boolean",
|
|
|
|
value: "false",
|
|
|
|
secret: false,
|
|
|
|
},
|
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
key: "MAX_FILE_SIZE",
|
2022-12-02 15:10:49 +01:00
|
|
|
description: "Maximum file size in bytes",
|
|
|
|
type: "number",
|
|
|
|
value: "1000000000",
|
|
|
|
secret: false,
|
|
|
|
},
|
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
key: "JWT_SECRET",
|
2022-12-02 15:10:49 +01:00
|
|
|
description: "Long random string used to sign JWT tokens",
|
|
|
|
type: "string",
|
|
|
|
value: crypto.randomBytes(256).toString("base64"),
|
|
|
|
locked: true,
|
|
|
|
},
|
2022-12-21 17:58:37 +01:00
|
|
|
{
|
|
|
|
key: "TOTP_SECRET",
|
|
|
|
description: "A 16 byte random string used to generate TOTP secrets",
|
|
|
|
type: "string",
|
|
|
|
value: crypto.randomBytes(16).toString("base64"),
|
|
|
|
locked: true,
|
|
|
|
},
|
2022-12-02 15:10:49 +01:00
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
key: "ENABLE_EMAIL_RECIPIENTS",
|
2022-12-02 15:10:49 +01:00
|
|
|
description:
|
2022-12-08 23:12:25 +01:00
|
|
|
"Whether to send emails to recipients. Only set this to true if you entered the host, port, email, user and password of your SMTP server.",
|
2022-12-02 15:10:49 +01:00
|
|
|
type: "boolean",
|
|
|
|
value: "false",
|
|
|
|
secret: false,
|
|
|
|
},
|
2022-12-15 21:44:04 +01:00
|
|
|
{
|
|
|
|
key: "EMAIL_MESSAGE",
|
2022-12-23 10:57:09 +01:00
|
|
|
description:
|
|
|
|
"Message which gets sent to the 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 🐧",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "EMAIL_SUBJECT",
|
|
|
|
description: "Subject of the email which gets sent to the recipients.",
|
|
|
|
type: "string",
|
|
|
|
value: "Files shared with you",
|
2022-12-15 21:44:04 +01:00
|
|
|
},
|
2022-12-02 15:10:49 +01:00
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
key: "SMTP_HOST",
|
2022-12-02 15:10:49 +01:00
|
|
|
description: "Host of the SMTP server",
|
|
|
|
type: "string",
|
|
|
|
value: "",
|
|
|
|
},
|
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
key: "SMTP_PORT",
|
2022-12-02 15:10:49 +01:00
|
|
|
description: "Port of the SMTP server",
|
|
|
|
type: "number",
|
|
|
|
value: "",
|
|
|
|
},
|
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
key: "SMTP_EMAIL",
|
2022-12-08 20:00:04 +01:00
|
|
|
description: "Email address which the emails get sent from",
|
|
|
|
type: "string",
|
|
|
|
value: "",
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: "SMTP_USERNAME",
|
|
|
|
description: "Username of the SMTP server",
|
2022-12-02 15:10:49 +01:00
|
|
|
type: "string",
|
|
|
|
value: "",
|
|
|
|
},
|
|
|
|
{
|
2022-12-05 16:53:52 +01:00
|
|
|
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,
|
2022-12-02 15:10:49 +01:00
|
|
|
},
|
|
|
|
];
|
2022-11-28 15:04:32 +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();
|
|
|
|
|
2022-12-08 20:00:04 +01:00
|
|
|
// Delete the config variable if it doesn't exist anymore
|
2022-11-28 15:04:32 +01:00
|
|
|
for (const configVariableFromDatabase of configVariablesFromDatabase) {
|
2022-12-08 20:00:04 +01:00
|
|
|
const configVariable = configVariables.find(
|
|
|
|
(v) => v.key == configVariableFromDatabase.key
|
|
|
|
);
|
|
|
|
if (!configVariable) {
|
2022-11-28 15:04:32 +01:00
|
|
|
await prisma.config.delete({
|
|
|
|
where: { key: configVariableFromDatabase.key },
|
|
|
|
});
|
2022-12-08 20:00:04 +01:00
|
|
|
|
|
|
|
// Update the config variable if the metadata changed
|
|
|
|
} else if (
|
|
|
|
JSON.stringify({
|
2022-12-08 21:58:58 +01:00
|
|
|
...configVariable,
|
2022-12-08 20:00:04 +01:00
|
|
|
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,
|
|
|
|
},
|
2022-12-08 20:00:04 +01:00
|
|
|
});
|
2022-11-28 15:04:32 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
main()
|
|
|
|
.then(async () => {
|
|
|
|
await prisma.$disconnect();
|
|
|
|
})
|
|
|
|
.catch(async (e) => {
|
|
|
|
console.error(e);
|
|
|
|
await prisma.$disconnect();
|
|
|
|
process.exit(1);
|
|
|
|
});
|