improved env config

This commit is contained in:
Daniel 2023-07-21 10:17:26 -04:00
parent fb721fb67a
commit e7d76616ca
9 changed files with 14 additions and 13 deletions

View File

@ -1,18 +1,19 @@
NEXTAUTH_SECRET=very_sensitive_secret NEXTAUTH_SECRET=very_sensitive_secret
DATABASE_URL=postgresql://user:password@localhost:5432/linkwarden DATABASE_URL=postgresql://user:password@localhost:5432/linkwarden
NEXTAUTH_URL=http://localhost:3000 NEXTAUTH_URL=http://localhost:3000
PAGINATION_TAKE_COUNT=20
# Don't define this if you're defining the "AWS S3 Settings" below # Additional Optional Settings
STORAGE_FOLDER=data
# AWS S3 Settings (Optional) PAGINATION_TAKE_COUNT=
STORAGE_FOLDER=
# AWS S3 Settings
SPACES_KEY= SPACES_KEY=
SPACES_SECRET= SPACES_SECRET=
SPACES_ENDPOINT= SPACES_ENDPOINT=
SPACES_REGION= SPACES_REGION=
# SMTP Settings (Optional) # SMTP Settings
NEXT_PUBLIC_EMAIL_PROVIDER= NEXT_PUBLIC_EMAIL_PROVIDER=
EMAIL_FROM= EMAIL_FROM=
EMAIL_SERVER= EMAIL_SERVER=

View File

@ -33,7 +33,7 @@ export default async function getLink(userId: number, body: string) {
}; };
const links = await prisma.link.findMany({ const links = await prisma.link.findMany({
take: Number(process.env.PAGINATION_TAKE_COUNT), take: Number(process.env.PAGINATION_TAKE_COUNT) || 20,
skip: query.cursor ? 1 : undefined, skip: query.cursor ? 1 : undefined,
cursor: query.cursor cursor: query.cursor
? { ? {

View File

@ -16,7 +16,7 @@ export default async function getCollection(body: string) {
if (collection) { if (collection) {
const links = await prisma.link.findMany({ const links = await prisma.link.findMany({
take: Number(process.env.PAGINATION_TAKE_COUNT), take: Number(process.env.PAGINATION_TAKE_COUNT) || 20,
skip: query.cursor ? 1 : undefined, skip: query.cursor ? 1 : undefined,
cursor: query.cursor cursor: query.cursor
? { ? {

View File

@ -28,7 +28,7 @@ export default async function createFile({
return false; return false;
} }
} else { } else {
const storagePath = process.env.STORAGE_FOLDER; const storagePath = process.env.STORAGE_FOLDER || "data";
const creationPath = path.join(process.cwd(), storagePath + "/" + filePath); const creationPath = path.join(process.cwd(), storagePath + "/" + filePath);
fs.writeFile(creationPath, data, isBase64 ? "base64" : {}, function (err) { fs.writeFile(creationPath, data, isBase64 ? "base64" : {}, function (err) {

View File

@ -6,7 +6,7 @@ export default function createFolder({ filePath }: { filePath: string }) {
if (s3Client) { if (s3Client) {
// Do nothing, S3 creates directories recursively // Do nothing, S3 creates directories recursively
} else { } else {
const storagePath = process.env.STORAGE_FOLDER; const storagePath = process.env.STORAGE_FOLDER || "data";
const creationPath = path.join(process.cwd(), storagePath + "/" + filePath); const creationPath = path.join(process.cwd(), storagePath + "/" + filePath);
fs.mkdirSync(creationPath, { recursive: true }); fs.mkdirSync(creationPath, { recursive: true });

View File

@ -41,7 +41,7 @@ export default async function readFile({ filePath }: { filePath: string }) {
}; };
} }
} else { } else {
const storagePath = process.env.STORAGE_FOLDER; const storagePath = process.env.STORAGE_FOLDER || "data";
const creationPath = path.join(process.cwd(), storagePath + "/" + filePath); const creationPath = path.join(process.cwd(), storagePath + "/" + filePath);
const file = fs.existsSync(creationPath) const file = fs.existsSync(creationPath)

View File

@ -16,7 +16,7 @@ export default async function removeFile({ filePath }: { filePath: string }) {
console.log("Error", err); console.log("Error", err);
} }
} else { } else {
const storagePath = process.env.STORAGE_FOLDER; const storagePath = process.env.STORAGE_FOLDER || "data";
const creationPath = path.join(process.cwd(), storagePath + "/" + filePath); const creationPath = path.join(process.cwd(), storagePath + "/" + filePath);
fs.unlink(creationPath, (err) => { fs.unlink(creationPath, (err) => {

View File

@ -45,7 +45,7 @@ export default async function removeFolder({ filePath }: { filePath: string }) {
console.log("Error", err); console.log("Error", err);
} }
} else { } else {
const storagePath = process.env.STORAGE_FOLDER; const storagePath = process.env.STORAGE_FOLDER || "data";
const creationPath = path.join(process.cwd(), storagePath + "/" + filePath); const creationPath = path.join(process.cwd(), storagePath + "/" + filePath);
try { try {

View File

@ -4,7 +4,7 @@ declare global {
NEXTAUTH_SECRET: string; NEXTAUTH_SECRET: string;
DATABASE_URL: string; DATABASE_URL: string;
NEXTAUTH_URL: string; NEXTAUTH_URL: string;
PAGINATION_TAKE_COUNT: string; PAGINATION_TAKE_COUNT?: string;
STORAGE_FOLDER?: string; STORAGE_FOLDER?: string;
SPACES_KEY?: string; SPACES_KEY?: string;