From e7d76616cab006150e112c9a096ce9401c25e430 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 21 Jul 2023 10:17:26 -0400 Subject: [PATCH] improved env config --- .env.sample | 11 ++++++----- lib/api/controllers/links/getLinks.ts | 2 +- lib/api/controllers/public/getCollection.ts | 2 +- lib/api/storage/createFile.ts | 2 +- lib/api/storage/createFolder.ts | 2 +- lib/api/storage/readFile.ts | 2 +- lib/api/storage/removeFile.ts | 2 +- lib/api/storage/removeFolder.ts | 2 +- types/enviornment.d.ts | 2 +- 9 files changed, 14 insertions(+), 13 deletions(-) diff --git a/.env.sample b/.env.sample index 8e0d4a5..ea08bfa 100644 --- a/.env.sample +++ b/.env.sample @@ -1,18 +1,19 @@ NEXTAUTH_SECRET=very_sensitive_secret DATABASE_URL=postgresql://user:password@localhost:5432/linkwarden NEXTAUTH_URL=http://localhost:3000 -PAGINATION_TAKE_COUNT=20 -# Don't define this if you're defining the "AWS S3 Settings" below -STORAGE_FOLDER=data +# Additional Optional Settings -# AWS S3 Settings (Optional) +PAGINATION_TAKE_COUNT= +STORAGE_FOLDER= + +# AWS S3 Settings SPACES_KEY= SPACES_SECRET= SPACES_ENDPOINT= SPACES_REGION= -# SMTP Settings (Optional) +# SMTP Settings NEXT_PUBLIC_EMAIL_PROVIDER= EMAIL_FROM= EMAIL_SERVER= diff --git a/lib/api/controllers/links/getLinks.ts b/lib/api/controllers/links/getLinks.ts index 127ccd1..d5ed6df 100644 --- a/lib/api/controllers/links/getLinks.ts +++ b/lib/api/controllers/links/getLinks.ts @@ -33,7 +33,7 @@ export default async function getLink(userId: number, body: string) { }; 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, cursor: query.cursor ? { diff --git a/lib/api/controllers/public/getCollection.ts b/lib/api/controllers/public/getCollection.ts index 2564df7..a9a2753 100644 --- a/lib/api/controllers/public/getCollection.ts +++ b/lib/api/controllers/public/getCollection.ts @@ -16,7 +16,7 @@ export default async function getCollection(body: string) { if (collection) { 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, cursor: query.cursor ? { diff --git a/lib/api/storage/createFile.ts b/lib/api/storage/createFile.ts index 1190ec8..8f55b45 100644 --- a/lib/api/storage/createFile.ts +++ b/lib/api/storage/createFile.ts @@ -28,7 +28,7 @@ export default async function createFile({ return false; } } else { - const storagePath = process.env.STORAGE_FOLDER; + const storagePath = process.env.STORAGE_FOLDER || "data"; const creationPath = path.join(process.cwd(), storagePath + "/" + filePath); fs.writeFile(creationPath, data, isBase64 ? "base64" : {}, function (err) { diff --git a/lib/api/storage/createFolder.ts b/lib/api/storage/createFolder.ts index 7c2f0b0..42b5dab 100644 --- a/lib/api/storage/createFolder.ts +++ b/lib/api/storage/createFolder.ts @@ -6,7 +6,7 @@ export default function createFolder({ filePath }: { filePath: string }) { if (s3Client) { // Do nothing, S3 creates directories recursively } else { - const storagePath = process.env.STORAGE_FOLDER; + const storagePath = process.env.STORAGE_FOLDER || "data"; const creationPath = path.join(process.cwd(), storagePath + "/" + filePath); fs.mkdirSync(creationPath, { recursive: true }); diff --git a/lib/api/storage/readFile.ts b/lib/api/storage/readFile.ts index 74fdc3e..237fac5 100644 --- a/lib/api/storage/readFile.ts +++ b/lib/api/storage/readFile.ts @@ -41,7 +41,7 @@ export default async function readFile({ filePath }: { filePath: string }) { }; } } else { - const storagePath = process.env.STORAGE_FOLDER; + const storagePath = process.env.STORAGE_FOLDER || "data"; const creationPath = path.join(process.cwd(), storagePath + "/" + filePath); const file = fs.existsSync(creationPath) diff --git a/lib/api/storage/removeFile.ts b/lib/api/storage/removeFile.ts index 83e4bdd..491e24c 100644 --- a/lib/api/storage/removeFile.ts +++ b/lib/api/storage/removeFile.ts @@ -16,7 +16,7 @@ export default async function removeFile({ filePath }: { filePath: string }) { console.log("Error", err); } } else { - const storagePath = process.env.STORAGE_FOLDER; + const storagePath = process.env.STORAGE_FOLDER || "data"; const creationPath = path.join(process.cwd(), storagePath + "/" + filePath); fs.unlink(creationPath, (err) => { diff --git a/lib/api/storage/removeFolder.ts b/lib/api/storage/removeFolder.ts index 54f6632..7383b88 100644 --- a/lib/api/storage/removeFolder.ts +++ b/lib/api/storage/removeFolder.ts @@ -45,7 +45,7 @@ export default async function removeFolder({ filePath }: { filePath: string }) { console.log("Error", err); } } else { - const storagePath = process.env.STORAGE_FOLDER; + const storagePath = process.env.STORAGE_FOLDER || "data"; const creationPath = path.join(process.cwd(), storagePath + "/" + filePath); try { diff --git a/types/enviornment.d.ts b/types/enviornment.d.ts index a093c11..047994c 100644 --- a/types/enviornment.d.ts +++ b/types/enviornment.d.ts @@ -4,7 +4,7 @@ declare global { NEXTAUTH_SECRET: string; DATABASE_URL: string; NEXTAUTH_URL: string; - PAGINATION_TAKE_COUNT: string; + PAGINATION_TAKE_COUNT?: string; STORAGE_FOLDER?: string; SPACES_KEY?: string;