Skip to content

⚡️⚡️⚡️ Self-hosted collaborative bookmark manager to collect, read, annotate, and fully preserve what matters, all in one place.

improved env config

Daniele7d76616cab0
diff --git a/.env.sample b/.env.sample
index 8e0d4a53..ea08bfa9 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 127ccd19..d5ed6dfb 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 2564df7a..a9a27532 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 1190ec8b..8f55b451 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 7c2f0b0b..42b5dab0 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 74fdc3e8..237fac55 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 83e4bddd..491e24c7 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 54f66325..7383b884 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 a093c11c..047994ce 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;