From c1522ef35c72707d0efd325bdc0ee2f746d072fe Mon Sep 17 00:00:00 2001 From: Elias Schneider <58886915+stonith404@users.noreply.github.com> Date: Tue, 11 Oct 2022 09:17:25 +0200 Subject: [PATCH 1/5] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d454e986..12f0d272 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ Demo: https://pingvin-share.dev.eliasschneider.com 2. Rename the `.env.example` file to `.env` and change the environment variables so that they fit to your environment. If you need help with the environment variables take a look [here](#environment-variables) 3. Run `docker-compose up -d` -The website is now listening available on `http://localhost:8080`, have fun with Pingvin Share 🐧! +The website is now listening available on `http://localhost:3000`, have fun with Pingvin Share 🐧! ### Environment variables @@ -29,10 +29,10 @@ The website is now listening available on `http://localhost:8080`, have fun with | -------------------- | --------------------------------------------------------------------------------------------------------------------- | --------------- | | `APP_URL` | On which URL Pingvin Share is available. E.g http://localhost or https://pingvin-share.com. | URL | | `BACKEND_URL` | Where the backend is listening on your local machine. If you use the default installation, use `http://backend:8080`. | URL | -| `SHOW_HOME_PAGE` | Wether the Pingvin Share home page should be shown. | true/false | -| `ALLOW_REGISTRATION` | Wether a new user can create a new account. | true/false | +| `SHOW_HOME_PAGE` | Whether the Pingvin Share home page should be shown. | true/false | +| `ALLOW_REGISTRATION` | Whether a new user can create a new account. | true/false | | `MAX_FILE_SIZE` | Maximum allowed size per file in bytes. | Number | -| `JWT_SECRET` | Random string to sign the JWT's. | Random string | +| `JWT_SECRET` | Random string to sign the JWT's. | Long random string | ## 🖤 Contribute @@ -43,7 +43,7 @@ Contact me, create an issue or directly create a pull request. #### Database & Backend -1. Open the `backend` +1. Open the `backend` folder 2. Duplicate the `.env.example` file, rename the duplicate to `.env` and change the environment variables if needed 3. Install the dependencies with `npm install` 4. Start the database by running `docker-compose up -d` From 7522221ee163cb0bd6144e7b924c77065f223fb9 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Tue, 11 Oct 2022 11:37:14 +0200 Subject: [PATCH 2/5] fix: upload volume path --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 71df8ee7..0494bce9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -24,7 +24,7 @@ services: depends_on: - db volumes: - - "./uploads:/usr/src/app/uploads" + - "./uploads:/opt/app/uploads" frontend: restart: unless-stopped ports: From 759db40ac9f42ff71a795ceec521a7f9531d71c9 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Tue, 11 Oct 2022 23:21:14 +0200 Subject: [PATCH 3/5] fix: wrong environment configuration for `ALLOW_REGISTRATION` --- backend/src/auth/auth.controller.ts | 2 +- frontend/src/pages/auth/signUp.tsx | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/backend/src/auth/auth.controller.ts b/backend/src/auth/auth.controller.ts index 3809ed66..e6d24b1a 100644 --- a/backend/src/auth/auth.controller.ts +++ b/backend/src/auth/auth.controller.ts @@ -21,7 +21,7 @@ export class AuthController { @Post("signUp") signUp(@Body() dto: AuthRegisterDTO) { - if (!this.config.get("ALLOW_REGISTRATION")) + if (this.config.get("ALLOW_REGISTRATION") == "false") throw new ForbiddenException("Registration is not allowed"); return this.authService.signUp(dto); } diff --git a/frontend/src/pages/auth/signUp.tsx b/frontend/src/pages/auth/signUp.tsx index 9d136e38..b4e44643 100644 --- a/frontend/src/pages/auth/signUp.tsx +++ b/frontend/src/pages/auth/signUp.tsx @@ -1,14 +1,17 @@ +import getConfig from "next/config"; import { useRouter } from "next/router"; import AuthForm from "../../components/auth/AuthForm"; import Meta from "../../components/Meta"; import useUser from "../../hooks/user.hook"; +const { publicRuntimeConfig } = getConfig(); + const SignUp = () => { const user = useUser(); const router = useRouter(); if (user) { router.replace("/"); - } else if (process.env.NEXT_PUBLIC_DISABLE_REGISTRATION) { + } else if (publicRuntimeConfig.ALLOW_REGISTRATION == "false") { router.replace("/auth/signIn"); } else { return ( From 80cdcda93c385a8f5c1e22c7b84740f5d8119ef1 Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Wed, 12 Oct 2022 00:38:38 +0200 Subject: [PATCH 4/5] feat: put db and uploads in same folder --- .gitignore | 2 +- Dockerfile | 4 ---- backend/prisma/schema.prisma | 2 +- backend/src/file/file.controller.ts | 2 +- backend/src/file/file.service.ts | 15 ++++++++------- backend/src/main.ts | 2 +- backend/src/prisma/prisma.service.ts | 2 +- backend/src/share/share.service.ts | 2 +- docker-compose.yml | 3 +-- 9 files changed, 15 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index 23c1afd4..fbae8431 100644 --- a/.gitignore +++ b/.gitignore @@ -35,6 +35,6 @@ yarn-error.log* /frontend/public/sw.* # project specific -/backend/uploads/ +/backend/data/ /data/ /backend/prisma/pingvin-share.db* diff --git a/Dockerfile b/Dockerfile index 9de63567..61068871 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,10 +13,6 @@ COPY ./backend . RUN npx prisma generate RUN npm run build - - - - FROM node:18 AS runner WORKDIR /opt/app/frontend ENV NODE_ENV=production diff --git a/backend/prisma/schema.prisma b/backend/prisma/schema.prisma index 447154fa..31f749ee 100644 --- a/backend/prisma/schema.prisma +++ b/backend/prisma/schema.prisma @@ -4,7 +4,7 @@ generator client { datasource db { provider = "sqlite" - url = "file:./pingvin-share.db" + url = "file:../data/pingvin-share.db" } model User { diff --git a/backend/src/file/file.controller.ts b/backend/src/file/file.controller.ts index b5e2d4b2..b822223d 100644 --- a/backend/src/file/file.controller.ts +++ b/backend/src/file/file.controller.ts @@ -27,7 +27,7 @@ export class FileController { @UseGuards(JwtGuard, ShareOwnerGuard) @UseInterceptors( FileInterceptor("file", { - dest: "./uploads/_temp/", + dest: "./data/uploads/_temp/", }) ) async create( diff --git a/backend/src/file/file.service.ts b/backend/src/file/file.service.ts index da34b242..6388f6ce 100644 --- a/backend/src/file/file.service.ts +++ b/backend/src/file/file.service.ts @@ -8,7 +8,6 @@ import { JwtService } from "@nestjs/jwt"; import { randomUUID } from "crypto"; import * as fs from "fs"; import * as mime from "mime-types"; -import { join } from "path"; import { PrismaService } from "src/prisma/prisma.service"; @Injectable() @@ -29,10 +28,12 @@ export class FileService { const fileId = randomUUID(); - await fs.promises.mkdir(`./uploads/shares/${shareId}`, { recursive: true }); + await fs.promises.mkdir(`./data/uploads/shares/${shareId}`, { + recursive: true, + }); fs.promises.rename( - `./uploads/_temp/${file.filename}`, - `./uploads/shares/${shareId}/${fileId}` + `./data/uploads/_temp/${file.filename}`, + `./data/uploads/shares/${shareId}/${fileId}` ); return await this.prisma.file.create({ @@ -53,7 +54,7 @@ export class FileService { if (!fileMetaData) throw new NotFoundException("File not found"); const file = fs.createReadStream( - join(process.cwd(), `uploads/shares/${shareId}/${fileId}`) + `./data/uploads/shares/${shareId}/${fileId}` ); return { @@ -67,14 +68,14 @@ export class FileService { } async deleteAllFiles(shareId: string) { - await fs.promises.rm(`./uploads/shares/${shareId}`, { + await fs.promises.rm(`./data/uploads/shares/${shareId}`, { recursive: true, force: true, }); } getZip(shareId: string) { - return fs.createReadStream(`./uploads/shares/${shareId}/archive.zip`); + return fs.createReadStream(`./data/uploads/shares/${shareId}/archive.zip`); } getFileDownloadUrl(shareId: string, fileId: string) { diff --git a/backend/src/main.ts b/backend/src/main.ts index aee6a33e..e1666df6 100644 --- a/backend/src/main.ts +++ b/backend/src/main.ts @@ -7,7 +7,7 @@ async function bootstrap() { app.useGlobalPipes(new ValidationPipe()); app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector))); - await fs.promises.mkdir("./uploads/_temp", { recursive: true }); + await fs.promises.mkdir("./data/uploads/_temp", { recursive: true }); app.setGlobalPrefix("api"); await app.listen(8080); diff --git a/backend/src/prisma/prisma.service.ts b/backend/src/prisma/prisma.service.ts index ab18ebcb..364ece7f 100644 --- a/backend/src/prisma/prisma.service.ts +++ b/backend/src/prisma/prisma.service.ts @@ -8,7 +8,7 @@ export class PrismaService extends PrismaClient { super({ datasources: { db: { - url: "file:./pingvin-share.db", + url: "file:../data/pingvin-share.db", }, }, }); diff --git a/backend/src/share/share.service.ts b/backend/src/share/share.service.ts index d15dc520..a8c4c4b4 100644 --- a/backend/src/share/share.service.ts +++ b/backend/src/share/share.service.ts @@ -57,7 +57,7 @@ export class ShareService { } async createZip(shareId: string) { - const path = `./uploads/shares/${shareId}`; + const path = `./data/uploads/shares/${shareId}`; const files = await this.prisma.file.findMany({ where: { shareId } }); const archive = archiver("zip", { diff --git a/docker-compose.yml b/docker-compose.yml index 683ec5d2..8c98edb5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -12,5 +12,4 @@ services: - MAX_FILE_SIZE=${MAX_FILE_SIZE} - JWT_SECRET=${JWT_SECRET} volumes: - - "${PWD}/data/uploads:/opt/app/backend/uploads" - - "${PWD}/data/pingvin-share.db:/opt/app/backend/prisma/pingvin-share.db" + - "${PWD}/data:/opt/app/backend/data" From 0ed921148cbebfe5eb00c898cb6a33049085ae1f Mon Sep 17 00:00:00 2001 From: Elias Schneider Date: Wed, 12 Oct 2022 00:44:22 +0200 Subject: [PATCH 5/5] chore: remove step in setup --- README.md | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 412ddbd4..54fb1749 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,7 @@ Demo: https://pingvin-share.dev.eliasschneider.com 1. Download the `docker-compose.yml` and `.env.example` file. 2. Rename the `.env.example` file to `.env` and change the environment variables so that they fit to your environment. If you need help with the environment variables take a look [here](#environment-variables) -3. Create a folder in the same folder as your `docker-compose.yml` file named `data` and create a file named `pingvin-share.db` in it. -4. Run `docker-compose up -d` +3. Run `docker-compose up -d` The website is now listening available on `http://localhost:3000`, have fun with Pingvin Share 🐧! @@ -31,16 +30,16 @@ The website is now listening available on `http://localhost:3000`, have fun with | Variable | Description | Possible values | | -------------------- | ------------------------------------------------------------------------------------------- | --------------- | | `APP_URL` | On which URL Pingvin Share is available. E.g http://localhost or https://pingvin-share.com. | URL | -| `SHOW_HOME_PAGE` | Whether the Pingvin Share home page should be shown. | true/false | -| `ALLOW_REGISTRATION` | Whether a new user can create a new account. | true/false | +| `SHOW_HOME_PAGE` | Whether the Pingvin Share home page should be shown. | true/false | +| `ALLOW_REGISTRATION` | Whether a new user can create a new account. | true/false | | `MAX_FILE_SIZE` | Maximum allowed size per file in bytes. | Number | -| `JWT_SECRET` | Long random string to sign the JWT's. | Random string | +| `JWT_SECRET` | Long random string to sign the JWT's. | Random string | ### Upgrade to a new version Just updated the docker container by running `docker-compose pull && docker-compose up -d` ->Note: If you installed Pingvin Share before it used Sqlite, you unfortunately have to set up the project from scratch again, sorry for that. +> Note: If you installed Pingvin Share before it used Sqlite, you unfortunately have to set up the project from scratch again, sorry for that. ## 🖤 Contribute