From 3edc3ccd01cc6c6d66b134706c60346914b25344 Mon Sep 17 00:00:00 2001 From: Loudbook Date: Mon, 2 Dec 2024 22:33:21 -0500 Subject: [PATCH 01/30] Refactor --- .gitignore | 43 +- .idea/workspace.xml | 411 ++++++++++++++++++ backend/.gitignore | 43 ++ build.gradle.kts => backend/build.gradle.kts | 0 .../gradle}/wrapper/gradle-wrapper.jar | Bin gradlew => backend/gradlew | 0 gradlew.bat => backend/gradlew.bat | 0 .../settings.gradle.kts | 0 .../dev/loudbook/pastebook/BucketUtils.kt | 0 .../dev/loudbook/pastebook/ContentScanner.kt | 0 .../dev/loudbook/pastebook/DeleteHandler.kt | 0 .../kotlin/dev/loudbook/pastebook/IPUtils.kt | 0 .../pastebook/PasteBookApplication.kt | 0 .../pastebook/config/Configuration.kt | 0 .../loudbook/pastebook/config/WebConfig.kt | 0 .../pastebook/controllers/GetController.kt | 0 .../pastebook/controllers/ListController.kt | 0 .../pastebook/controllers/UploadController.kt | 0 .../dev/loudbook/pastebook/data/Paste.kt | 0 .../dev/loudbook/pastebook/data/PasteDTO.kt | 0 .../pastebook/data/PastePrivateDTO.kt | 0 .../dev/loudbook/pastebook/data/R2Service.kt | 0 .../dev/loudbook/pastebook/data/User.kt | 0 .../dev/loudbook/pastebook/data/UserDTO.kt | 0 .../pastebook/mongo/PasteRepository.kt | 0 .../loudbook/pastebook/mongo/UserService.kt | 0 .../pastebook/mongo/UsersRepository.kt | 0 .../pastebook/PasteBookApplicationTests.kt | 0 config.properties | 4 - {website/pastebook => frontend}/.gitignore | 0 {website/pastebook => frontend}/.npmrc | 0 {website/pastebook => frontend}/.prettierrc | 0 .../pastebook => frontend}/package-lock.json | 9 +- {website/pastebook => frontend}/package.json | 3 +- {website/pastebook => frontend}/src/app.d.ts | 0 {website/pastebook => frontend}/src/app.html | 0 .../src/components/Beta.svelte | 0 .../src/components/Content.svelte | 0 .../src/components/Header.svelte | 0 .../src/components/Highlight.svelte | 0 .../src/components/Mode.svelte | 0 .../src/components/PotentialIssues.svelte | 0 .../src/components/Toolbar.svelte | 0 .../src/components/new/Submit.svelte | 0 .../src/components/panel/ListedPaste.svelte | 0 .../src/components/pulltab/Pulltab.svelte | 0 .../src/components/settings/DropDown.svelte | 0 .../src/components/settings/Setting.svelte | 0 .../src/components/settings/Switch.svelte | 0 .../src/components/svg/SVGPasteBook.svelte | 0 .../src/lib/assets/arrow-white.svg | 0 .../src/lib/assets/arrow.svg | 0 .../src/lib/assets/favicon.png | Bin .../src/lib/detections.json | 0 .../pastebook => frontend}/src/lib/issue.ts | 0 .../pastebook => frontend}/src/lib/paste.ts | 0 .../pastebook => frontend}/src/lib/stores.ts | 0 .../src/lib/timehandler.ts | 0 .../src/params/paste.ts | 0 .../src/routes/+error.svelte | 0 .../src/routes/+layout.svelte | 0 .../src/routes/+page.svelte | 0 .../[pastes=paste]/[slug]/+page.server.ts | 2 +- .../routes/[pastes=paste]/[slug]/+page.svelte | 0 .../src/routes/new/+page.svelte | 0 .../src/routes/panel/+page.server.ts | 0 .../src/routes/panel/+page.svelte | 0 .../src/routes/privacy/+page.svelte | 0 .../src/routes/settings/+page.svelte | 0 .../pastebook => frontend}/static/favicon.png | Bin .../pastebook => frontend}/static/robots.txt | 0 .../pastebook => frontend}/svelte.config.js | 0 {website/pastebook => frontend}/tsconfig.json | 0 .../pastebook => frontend}/vite.config.ts | 0 gradle/wrapper/gradle-wrapper.properties | 7 - src/main/.DS_Store | Bin 6148 -> 0 bytes website/package-lock.json | 6 - 77 files changed, 466 insertions(+), 62 deletions(-) create mode 100644 .idea/workspace.xml create mode 100644 backend/.gitignore rename build.gradle.kts => backend/build.gradle.kts (100%) rename {gradle => backend/gradle}/wrapper/gradle-wrapper.jar (100%) rename gradlew => backend/gradlew (100%) rename gradlew.bat => backend/gradlew.bat (100%) rename settings.gradle.kts => backend/settings.gradle.kts (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/BucketUtils.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/ContentScanner.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/DeleteHandler.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/IPUtils.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/PasteBookApplication.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/config/Configuration.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/config/WebConfig.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/controllers/GetController.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/controllers/UploadController.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/data/Paste.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/data/PasteDTO.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/data/PastePrivateDTO.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/data/R2Service.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/data/User.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/data/UserDTO.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/mongo/PasteRepository.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/mongo/UserService.kt (100%) rename {src => backend/src}/main/kotlin/dev/loudbook/pastebook/mongo/UsersRepository.kt (100%) rename {src => backend/src}/test/kotlin/dev/loudbook/pastebook/pastebook/PasteBookApplicationTests.kt (100%) delete mode 100644 config.properties rename {website/pastebook => frontend}/.gitignore (100%) rename {website/pastebook => frontend}/.npmrc (100%) rename {website/pastebook => frontend}/.prettierrc (100%) rename {website/pastebook => frontend}/package-lock.json (99%) rename {website/pastebook => frontend}/package.json (95%) rename {website/pastebook => frontend}/src/app.d.ts (100%) rename {website/pastebook => frontend}/src/app.html (100%) rename {website/pastebook => frontend}/src/components/Beta.svelte (100%) rename {website/pastebook => frontend}/src/components/Content.svelte (100%) rename {website/pastebook => frontend}/src/components/Header.svelte (100%) rename {website/pastebook => frontend}/src/components/Highlight.svelte (100%) rename {website/pastebook => frontend}/src/components/Mode.svelte (100%) rename {website/pastebook => frontend}/src/components/PotentialIssues.svelte (100%) rename {website/pastebook => frontend}/src/components/Toolbar.svelte (100%) rename {website/pastebook => frontend}/src/components/new/Submit.svelte (100%) rename {website/pastebook => frontend}/src/components/panel/ListedPaste.svelte (100%) rename {website/pastebook => frontend}/src/components/pulltab/Pulltab.svelte (100%) rename {website/pastebook => frontend}/src/components/settings/DropDown.svelte (100%) rename {website/pastebook => frontend}/src/components/settings/Setting.svelte (100%) rename {website/pastebook => frontend}/src/components/settings/Switch.svelte (100%) rename {website/pastebook => frontend}/src/components/svg/SVGPasteBook.svelte (100%) rename {website/pastebook => frontend}/src/lib/assets/arrow-white.svg (100%) rename {website/pastebook => frontend}/src/lib/assets/arrow.svg (100%) rename {website/pastebook => frontend}/src/lib/assets/favicon.png (100%) rename {website/pastebook => frontend}/src/lib/detections.json (100%) rename {website/pastebook => frontend}/src/lib/issue.ts (100%) rename {website/pastebook => frontend}/src/lib/paste.ts (100%) rename {website/pastebook => frontend}/src/lib/stores.ts (100%) rename {website/pastebook => frontend}/src/lib/timehandler.ts (100%) rename {website/pastebook => frontend}/src/params/paste.ts (100%) rename {website/pastebook => frontend}/src/routes/+error.svelte (100%) rename {website/pastebook => frontend}/src/routes/+layout.svelte (100%) rename {website/pastebook => frontend}/src/routes/+page.svelte (100%) rename {website/pastebook => frontend}/src/routes/[pastes=paste]/[slug]/+page.server.ts (92%) rename {website/pastebook => frontend}/src/routes/[pastes=paste]/[slug]/+page.svelte (100%) rename {website/pastebook => frontend}/src/routes/new/+page.svelte (100%) rename {website/pastebook => frontend}/src/routes/panel/+page.server.ts (100%) rename {website/pastebook => frontend}/src/routes/panel/+page.svelte (100%) rename {website/pastebook => frontend}/src/routes/privacy/+page.svelte (100%) rename {website/pastebook => frontend}/src/routes/settings/+page.svelte (100%) rename {website/pastebook => frontend}/static/favicon.png (100%) rename {website/pastebook => frontend}/static/robots.txt (100%) rename {website/pastebook => frontend}/svelte.config.js (100%) rename {website/pastebook => frontend}/tsconfig.json (100%) rename {website/pastebook => frontend}/vite.config.ts (100%) delete mode 100644 gradle/wrapper/gradle-wrapper.properties delete mode 100644 src/main/.DS_Store delete mode 100644 website/package-lock.json diff --git a/.gitignore b/.gitignore index a816a61..b7ff13a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,42 +1 @@ -HELP.md -.gradle -build/ -!gradle/wrapper/gradle-wrapper.jar -!**/src/main/**/build/ -!**/src/test/**/build/ - -### STS ### -.apt_generated -.classpath -.factorypath -.project -.settings -.springBeans -.sts4-cache -bin/ -!**/src/main/**/bin/ -!**/src/test/**/bin/ - -### IntelliJ IDEA ### -.idea -*.iws -*.iml -*.ipr -out/ -!**/src/main/**/out/ -!**/src/test/**/out/ - -### NetBeans ### -/nbproject/private/ -/nbbuild/ -/dist/ -/nbdist/ -/.nb-gradle/ - -### VS Code ### -.vscode/ - -### Kotlin ### -.kotlin -src/main/resources/application.properties -src/main/resources/application.yml \ No newline at end of file +.DS_STORE \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..d3f48ae --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,411 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/backend/.gitignore b/backend/.gitignore new file mode 100644 index 0000000..7826039 --- /dev/null +++ b/backend/.gitignore @@ -0,0 +1,43 @@ +HELP.md +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ +*.properties + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Kotlin ### +.kotlin +src/main/resources/application.properties +src/main/resources/application.yml \ No newline at end of file diff --git a/build.gradle.kts b/backend/build.gradle.kts similarity index 100% rename from build.gradle.kts rename to backend/build.gradle.kts diff --git a/gradle/wrapper/gradle-wrapper.jar b/backend/gradle/wrapper/gradle-wrapper.jar similarity index 100% rename from gradle/wrapper/gradle-wrapper.jar rename to backend/gradle/wrapper/gradle-wrapper.jar diff --git a/gradlew b/backend/gradlew similarity index 100% rename from gradlew rename to backend/gradlew diff --git a/gradlew.bat b/backend/gradlew.bat similarity index 100% rename from gradlew.bat rename to backend/gradlew.bat diff --git a/settings.gradle.kts b/backend/settings.gradle.kts similarity index 100% rename from settings.gradle.kts rename to backend/settings.gradle.kts diff --git a/src/main/kotlin/dev/loudbook/pastebook/BucketUtils.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/BucketUtils.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/BucketUtils.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/BucketUtils.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/ContentScanner.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/ContentScanner.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/ContentScanner.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/ContentScanner.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/DeleteHandler.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/DeleteHandler.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/DeleteHandler.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/DeleteHandler.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/IPUtils.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/IPUtils.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/IPUtils.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/IPUtils.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/PasteBookApplication.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/PasteBookApplication.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/PasteBookApplication.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/PasteBookApplication.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/config/Configuration.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/config/Configuration.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/config/Configuration.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/config/Configuration.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/config/WebConfig.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/config/WebConfig.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/config/WebConfig.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/config/WebConfig.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/controllers/GetController.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/GetController.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/controllers/GetController.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/controllers/GetController.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/controllers/UploadController.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/UploadController.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/controllers/UploadController.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/controllers/UploadController.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/data/Paste.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/data/Paste.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/data/Paste.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/data/Paste.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/data/PasteDTO.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/data/PasteDTO.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/data/PasteDTO.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/data/PasteDTO.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/data/PastePrivateDTO.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/data/PastePrivateDTO.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/data/PastePrivateDTO.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/data/PastePrivateDTO.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/data/R2Service.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/data/R2Service.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/data/R2Service.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/data/R2Service.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/data/User.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/data/User.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/data/User.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/data/User.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/data/UserDTO.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/data/UserDTO.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/data/UserDTO.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/data/UserDTO.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/mongo/PasteRepository.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/mongo/PasteRepository.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/mongo/PasteRepository.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/mongo/PasteRepository.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/mongo/UserService.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/mongo/UserService.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/mongo/UserService.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/mongo/UserService.kt diff --git a/src/main/kotlin/dev/loudbook/pastebook/mongo/UsersRepository.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/mongo/UsersRepository.kt similarity index 100% rename from src/main/kotlin/dev/loudbook/pastebook/mongo/UsersRepository.kt rename to backend/src/main/kotlin/dev/loudbook/pastebook/mongo/UsersRepository.kt diff --git a/src/test/kotlin/dev/loudbook/pastebook/pastebook/PasteBookApplicationTests.kt b/backend/src/test/kotlin/dev/loudbook/pastebook/pastebook/PasteBookApplicationTests.kt similarity index 100% rename from src/test/kotlin/dev/loudbook/pastebook/pastebook/PasteBookApplicationTests.kt rename to backend/src/test/kotlin/dev/loudbook/pastebook/pastebook/PasteBookApplicationTests.kt diff --git a/config.properties b/config.properties deleted file mode 100644 index 47a47f3..0000000 --- a/config.properties +++ /dev/null @@ -1,4 +0,0 @@ -url=https://ptb.discord.com/api/webhooks/1231325355839852564/zgIJhmd-_-8OxWC5Ra> -aws-endpoint="https://3364c2b7baa43c93ad91daf56989f1d0.r2.cloudflarestorage.com/pastebook" -aws-access-key=c811d8f01abd565921106aa8909c31e1 -aws-secret-key=bbc3213dcd984a70fb792f5f9738df833c1d51c9fc79e69e6e8da81bbb1dd9de \ No newline at end of file diff --git a/website/pastebook/.gitignore b/frontend/.gitignore similarity index 100% rename from website/pastebook/.gitignore rename to frontend/.gitignore diff --git a/website/pastebook/.npmrc b/frontend/.npmrc similarity index 100% rename from website/pastebook/.npmrc rename to frontend/.npmrc diff --git a/website/pastebook/.prettierrc b/frontend/.prettierrc similarity index 100% rename from website/pastebook/.prettierrc rename to frontend/.prettierrc diff --git a/website/pastebook/package-lock.json b/frontend/package-lock.json similarity index 99% rename from website/pastebook/package-lock.json rename to frontend/package-lock.json index 4c7d193..99f1c5d 100644 --- a/website/pastebook/package-lock.json +++ b/frontend/package-lock.json @@ -8,7 +8,8 @@ "name": "pastebook", "version": "0.0.1", "dependencies": { - "just-extend": "^6.2.0" + "just-extend": "^6.2.0", + "pako": "^2.1.0" }, "devDependencies": { "@fontsource/fira-mono": "^4.5.10", @@ -1730,6 +1731,12 @@ "wrappy": "1" } }, + "node_modules/pako": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/pako/-/pako-2.1.0.tgz", + "integrity": "sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==", + "license": "(MIT AND Zlib)" + }, "node_modules/parent-module": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/parent-module/-/parent-module-1.0.1.tgz", diff --git a/website/pastebook/package.json b/frontend/package.json similarity index 95% rename from website/pastebook/package.json rename to frontend/package.json index b9ca98f..cd66e10 100644 --- a/website/pastebook/package.json +++ b/frontend/package.json @@ -31,6 +31,7 @@ }, "type": "module", "dependencies": { - "just-extend": "^6.2.0" + "just-extend": "^6.2.0", + "pako": "^2.1.0" } } diff --git a/website/pastebook/src/app.d.ts b/frontend/src/app.d.ts similarity index 100% rename from website/pastebook/src/app.d.ts rename to frontend/src/app.d.ts diff --git a/website/pastebook/src/app.html b/frontend/src/app.html similarity index 100% rename from website/pastebook/src/app.html rename to frontend/src/app.html diff --git a/website/pastebook/src/components/Beta.svelte b/frontend/src/components/Beta.svelte similarity index 100% rename from website/pastebook/src/components/Beta.svelte rename to frontend/src/components/Beta.svelte diff --git a/website/pastebook/src/components/Content.svelte b/frontend/src/components/Content.svelte similarity index 100% rename from website/pastebook/src/components/Content.svelte rename to frontend/src/components/Content.svelte diff --git a/website/pastebook/src/components/Header.svelte b/frontend/src/components/Header.svelte similarity index 100% rename from website/pastebook/src/components/Header.svelte rename to frontend/src/components/Header.svelte diff --git a/website/pastebook/src/components/Highlight.svelte b/frontend/src/components/Highlight.svelte similarity index 100% rename from website/pastebook/src/components/Highlight.svelte rename to frontend/src/components/Highlight.svelte diff --git a/website/pastebook/src/components/Mode.svelte b/frontend/src/components/Mode.svelte similarity index 100% rename from website/pastebook/src/components/Mode.svelte rename to frontend/src/components/Mode.svelte diff --git a/website/pastebook/src/components/PotentialIssues.svelte b/frontend/src/components/PotentialIssues.svelte similarity index 100% rename from website/pastebook/src/components/PotentialIssues.svelte rename to frontend/src/components/PotentialIssues.svelte diff --git a/website/pastebook/src/components/Toolbar.svelte b/frontend/src/components/Toolbar.svelte similarity index 100% rename from website/pastebook/src/components/Toolbar.svelte rename to frontend/src/components/Toolbar.svelte diff --git a/website/pastebook/src/components/new/Submit.svelte b/frontend/src/components/new/Submit.svelte similarity index 100% rename from website/pastebook/src/components/new/Submit.svelte rename to frontend/src/components/new/Submit.svelte diff --git a/website/pastebook/src/components/panel/ListedPaste.svelte b/frontend/src/components/panel/ListedPaste.svelte similarity index 100% rename from website/pastebook/src/components/panel/ListedPaste.svelte rename to frontend/src/components/panel/ListedPaste.svelte diff --git a/website/pastebook/src/components/pulltab/Pulltab.svelte b/frontend/src/components/pulltab/Pulltab.svelte similarity index 100% rename from website/pastebook/src/components/pulltab/Pulltab.svelte rename to frontend/src/components/pulltab/Pulltab.svelte diff --git a/website/pastebook/src/components/settings/DropDown.svelte b/frontend/src/components/settings/DropDown.svelte similarity index 100% rename from website/pastebook/src/components/settings/DropDown.svelte rename to frontend/src/components/settings/DropDown.svelte diff --git a/website/pastebook/src/components/settings/Setting.svelte b/frontend/src/components/settings/Setting.svelte similarity index 100% rename from website/pastebook/src/components/settings/Setting.svelte rename to frontend/src/components/settings/Setting.svelte diff --git a/website/pastebook/src/components/settings/Switch.svelte b/frontend/src/components/settings/Switch.svelte similarity index 100% rename from website/pastebook/src/components/settings/Switch.svelte rename to frontend/src/components/settings/Switch.svelte diff --git a/website/pastebook/src/components/svg/SVGPasteBook.svelte b/frontend/src/components/svg/SVGPasteBook.svelte similarity index 100% rename from website/pastebook/src/components/svg/SVGPasteBook.svelte rename to frontend/src/components/svg/SVGPasteBook.svelte diff --git a/website/pastebook/src/lib/assets/arrow-white.svg b/frontend/src/lib/assets/arrow-white.svg similarity index 100% rename from website/pastebook/src/lib/assets/arrow-white.svg rename to frontend/src/lib/assets/arrow-white.svg diff --git a/website/pastebook/src/lib/assets/arrow.svg b/frontend/src/lib/assets/arrow.svg similarity index 100% rename from website/pastebook/src/lib/assets/arrow.svg rename to frontend/src/lib/assets/arrow.svg diff --git a/website/pastebook/src/lib/assets/favicon.png b/frontend/src/lib/assets/favicon.png similarity index 100% rename from website/pastebook/src/lib/assets/favicon.png rename to frontend/src/lib/assets/favicon.png diff --git a/website/pastebook/src/lib/detections.json b/frontend/src/lib/detections.json similarity index 100% rename from website/pastebook/src/lib/detections.json rename to frontend/src/lib/detections.json diff --git a/website/pastebook/src/lib/issue.ts b/frontend/src/lib/issue.ts similarity index 100% rename from website/pastebook/src/lib/issue.ts rename to frontend/src/lib/issue.ts diff --git a/website/pastebook/src/lib/paste.ts b/frontend/src/lib/paste.ts similarity index 100% rename from website/pastebook/src/lib/paste.ts rename to frontend/src/lib/paste.ts diff --git a/website/pastebook/src/lib/stores.ts b/frontend/src/lib/stores.ts similarity index 100% rename from website/pastebook/src/lib/stores.ts rename to frontend/src/lib/stores.ts diff --git a/website/pastebook/src/lib/timehandler.ts b/frontend/src/lib/timehandler.ts similarity index 100% rename from website/pastebook/src/lib/timehandler.ts rename to frontend/src/lib/timehandler.ts diff --git a/website/pastebook/src/params/paste.ts b/frontend/src/params/paste.ts similarity index 100% rename from website/pastebook/src/params/paste.ts rename to frontend/src/params/paste.ts diff --git a/website/pastebook/src/routes/+error.svelte b/frontend/src/routes/+error.svelte similarity index 100% rename from website/pastebook/src/routes/+error.svelte rename to frontend/src/routes/+error.svelte diff --git a/website/pastebook/src/routes/+layout.svelte b/frontend/src/routes/+layout.svelte similarity index 100% rename from website/pastebook/src/routes/+layout.svelte rename to frontend/src/routes/+layout.svelte diff --git a/website/pastebook/src/routes/+page.svelte b/frontend/src/routes/+page.svelte similarity index 100% rename from website/pastebook/src/routes/+page.svelte rename to frontend/src/routes/+page.svelte diff --git a/website/pastebook/src/routes/[pastes=paste]/[slug]/+page.server.ts b/frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts similarity index 92% rename from website/pastebook/src/routes/[pastes=paste]/[slug]/+page.server.ts rename to frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts index ac38dfc..43b0cf5 100755 --- a/website/pastebook/src/routes/[pastes=paste]/[slug]/+page.server.ts +++ b/frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts @@ -38,7 +38,7 @@ export async function load({ params, cookies }) { return { metadata: metadataPromise, - url: "https://pastebook.dev/api/get/" + path + "/content", + url: "http://localhost:25658/api/get/" + path + "/content", inspect: cookies.get("inspect") === "true", }; } diff --git a/website/pastebook/src/routes/[pastes=paste]/[slug]/+page.svelte b/frontend/src/routes/[pastes=paste]/[slug]/+page.svelte similarity index 100% rename from website/pastebook/src/routes/[pastes=paste]/[slug]/+page.svelte rename to frontend/src/routes/[pastes=paste]/[slug]/+page.svelte diff --git a/website/pastebook/src/routes/new/+page.svelte b/frontend/src/routes/new/+page.svelte similarity index 100% rename from website/pastebook/src/routes/new/+page.svelte rename to frontend/src/routes/new/+page.svelte diff --git a/website/pastebook/src/routes/panel/+page.server.ts b/frontend/src/routes/panel/+page.server.ts similarity index 100% rename from website/pastebook/src/routes/panel/+page.server.ts rename to frontend/src/routes/panel/+page.server.ts diff --git a/website/pastebook/src/routes/panel/+page.svelte b/frontend/src/routes/panel/+page.svelte similarity index 100% rename from website/pastebook/src/routes/panel/+page.svelte rename to frontend/src/routes/panel/+page.svelte diff --git a/website/pastebook/src/routes/privacy/+page.svelte b/frontend/src/routes/privacy/+page.svelte similarity index 100% rename from website/pastebook/src/routes/privacy/+page.svelte rename to frontend/src/routes/privacy/+page.svelte diff --git a/website/pastebook/src/routes/settings/+page.svelte b/frontend/src/routes/settings/+page.svelte similarity index 100% rename from website/pastebook/src/routes/settings/+page.svelte rename to frontend/src/routes/settings/+page.svelte diff --git a/website/pastebook/static/favicon.png b/frontend/static/favicon.png similarity index 100% rename from website/pastebook/static/favicon.png rename to frontend/static/favicon.png diff --git a/website/pastebook/static/robots.txt b/frontend/static/robots.txt similarity index 100% rename from website/pastebook/static/robots.txt rename to frontend/static/robots.txt diff --git a/website/pastebook/svelte.config.js b/frontend/svelte.config.js similarity index 100% rename from website/pastebook/svelte.config.js rename to frontend/svelte.config.js diff --git a/website/pastebook/tsconfig.json b/frontend/tsconfig.json similarity index 100% rename from website/pastebook/tsconfig.json rename to frontend/tsconfig.json diff --git a/website/pastebook/vite.config.ts b/frontend/vite.config.ts similarity index 100% rename from website/pastebook/vite.config.ts rename to frontend/vite.config.ts diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index b82aa23..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,7 +0,0 @@ -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip -networkTimeout=10000 -validateDistributionUrl=true -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/src/main/.DS_Store b/src/main/.DS_Store deleted file mode 100644 index 0e98056ead8b2b4ddd22a5b0719be234dbd12c0a..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6148 zcmeHKI|>3p3{BKRv9YwAD|mxJ^aNf&P_YpOMeD6Rmq+vEgD9(wU?VS(yqQeiEc=Sh zMnrUaUQa|uBGQK&%GE;K?A*L%oy;f@jyukBl$C7cbXl~j-zSVa01F&BJoAtH-C@6t zo8MEJr2a0lP&G#k4Lb5A>uO>X7ausK8$-puO2*HpMGtZ*9Gt_1Xeo!mZ{8H^bT~2;Po?-j1=cc0Bf? bs4KR{c};8rosPWIf&3XTU1(I`*9zPLYRVP2 diff --git a/website/package-lock.json b/website/package-lock.json deleted file mode 100644 index 4ff32e6..0000000 --- a/website/package-lock.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "website", - "lockfileVersion": 3, - "requires": true, - "packages": {} -} From ccff72e7d488000b8f5f071d41110e2129ef9a40 Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 13:51:47 -0500 Subject: [PATCH 02/30] Change Endpoint --- .gitignore | 3 +- .../pastebook/controllers/GetController.kt | 2 - .../pastebook/controllers/ListController.kt | 1 - .../pastebook/controllers/UploadController.kt | 12 ++--- frontend/src/app.html | 1 - frontend/src/components/new/Submit.svelte | 5 +- .../[pastes=paste]/[slug]/+page.server.ts | 13 +++-- .../routes/[pastes=paste]/[slug]/+page.svelte | 49 ++++--------------- frontend/src/routes/panel/+page.server.ts | 2 +- 9 files changed, 27 insertions(+), 61 deletions(-) diff --git a/.gitignore b/.gitignore index b7ff13a..a40f1fd 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ -.DS_STORE \ No newline at end of file +.* +!.gitignore \ No newline at end of file diff --git a/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/GetController.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/GetController.kt index 87afd49..6239b0c 100644 --- a/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/GetController.kt +++ b/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/GetController.kt @@ -17,7 +17,6 @@ import java.io.ByteArrayOutputStream import java.util.zip.GZIPOutputStream @RestController -@RequestMapping("/api") class GetController { @Autowired lateinit var r2Service: R2Service @@ -95,5 +94,4 @@ class GetController { return byteArrayOutputStream.toByteArray() } - } \ No newline at end of file diff --git a/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt index ffe8364..bf80b37 100644 --- a/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt +++ b/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt @@ -14,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestMapping import org.springframework.web.bind.annotation.RestController @RestController -@RequestMapping("/api") class ListController { @Autowired lateinit var pasteRepository: PasteRepository diff --git a/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/UploadController.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/UploadController.kt index 2562a06..89c906c 100644 --- a/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/UploadController.kt +++ b/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/UploadController.kt @@ -29,7 +29,7 @@ class UploadController { private val bucket: Bucket = BucketUtils.getBucketPerMinutes(4) - @PostMapping(value = ["/api/upload", "/upload"]) + @PostMapping(value = ["/upload"]) fun upload(request: HttpServletRequest, @RequestBody body: String): ResponseEntity { if (!userService.processRequest(request)) { return ResponseEntity.status(403).body("Prohibited") @@ -41,7 +41,7 @@ class UploadController { val header = HttpHeaders() - var fileID = generateRandomString() + val fileID = generateRandomString() val sinceTheEpoch = System.currentTimeMillis() @@ -68,17 +68,11 @@ class UploadController { val ip = IPUtils.getIPFromRequest(request) ?: return ResponseEntity.badRequest().body("Failed to get IP") val paste = PastePrivateDTO(fileID, title, sinceTheEpoch, reportBook, unlisted, wrap, ip, expire) - val pastebookURL = uploadPastebook(paste) ?: return ResponseEntity.badRequest().body("Failed to upload pastebook") r2Service.uploadFile(fileID, filteredBody) pasteRepository.save(paste) - return ResponseEntity.ok().headers(header).body(pastebookURL) - } - - fun uploadPastebook(paste: PastePrivateDTO): String? { - val url = "https://pastebook.dev/p/${paste.id}" - return url + return ResponseEntity.ok().headers(header).body(fileID) } fun generateRandomString(length: Int = 5): String { diff --git a/frontend/src/app.html b/frontend/src/app.html index 9a8ca3c..e839466 100755 --- a/frontend/src/app.html +++ b/frontend/src/app.html @@ -2,7 +2,6 @@ - { writableTitle.subscribe(() => { allFieldsFilled(); @@ -48,9 +50,8 @@ alreadyUploading = true; submit.classList.add("loading"); const xhr = new XMLHttpRequest(); - xhr.open("POST", "https://pastebook.dev/api/upload"); + xhr.open("POST", `${backendUrl}/upload`); xhr.setRequestHeader("Content-Type", "plain/text"); - xhr.setRequestHeader("onlyPastebook", "true"); xhr.setRequestHeader("access-control-allow-methods", "POST"); xhr.setRequestHeader("title", $writableTitle); xhr.setRequestHeader("wrap", String($wrap)); diff --git a/frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts b/frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts index 43b0cf5..637367a 100755 --- a/frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts +++ b/frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts @@ -1,11 +1,10 @@ import { error } from "@sveltejs/kit"; -import { pasteURL } from "$lib/stores"; export async function load({ params, cookies }) { let path = params.slug; let response = await fetch( - "http://localhost:25658/api/get/" + path + "/metadata", + "http://localhost:25658/get/" + path + "/metadata", ); if (response.status === 404) { @@ -32,13 +31,17 @@ export async function load({ params, cookies }) { }); } - pasteURL.set("https://pastebook.dev/p/" + path); - let metadataPromise = response.json(); return { metadata: metadataPromise, - url: "http://localhost:25658/api/get/" + path + "/content", + content: metadataPromise.then(async () => { + return fetch("http://localhost:25658/get/" + path + "/content").then( + (response) => { + return response.text(); + }, + ); + }), inspect: cookies.get("inspect") === "true", }; } diff --git a/frontend/src/routes/[pastes=paste]/[slug]/+page.svelte b/frontend/src/routes/[pastes=paste]/[slug]/+page.svelte index be67d64..8c748d1 100755 --- a/frontend/src/routes/[pastes=paste]/[slug]/+page.svelte +++ b/frontend/src/routes/[pastes=paste]/[slug]/+page.svelte @@ -5,47 +5,13 @@ import PotentialIssues from "../../../components/PotentialIssues.svelte"; import { loadProgress, severes, warnings } from "$lib/stores"; import { formatTimeSince, formatTimeUntil } from "$lib/timehandler"; - import { error } from "@sveltejs/kit"; import { onMount, tick } from "svelte"; import SVGPasteBook from "../../../components/svg/SVGPasteBook.svelte"; import Highlight from "../../../components/Highlight.svelte"; export let data; - const { metadata, url } = data; - - let percent = 0; - - let promise = new Promise((resolve) => { - const xhr = new XMLHttpRequest(); - xhr.open("GET", url, true); - xhr.responseType = "text"; - - xhr.addEventListener("progress", (e) => { - if (e.lengthComputable) { - percent = (e.loaded / e.total) * 100; - } - - loadProgress.set(percent); - }); - - xhr.onload = async () => { - if (xhr.status === 200) { - loadProgress.set(99.9); - - resolve(xhr.response); - await tick(); - loadProgress.set(100); - } else { - error(xhr.status, xhr.statusText); - } - }; - xhr.onerror = () => { - error(xhr.status, xhr.statusText); - }; - - xhr.send(); - }); + const { metadata, content } = data; let timeSinceStr = ""; let created = new Date(); @@ -62,11 +28,11 @@ reportBook = data.reportBook; wrap = data.wrap; hashedIP = data.user.hashedIP; - expires = new Date(data.expiresAt); + expires = new Date(data.expiresAt) const reloadTime = () => { - timeSinceStr = formatTimeSince(created); - untilExpire = formatTimeUntil(expires); + timeSinceStr = formatTimeSince(created as unknown as number); + untilExpire = formatTimeUntil(expires as unknown as number); }; reloadTime(); @@ -75,6 +41,11 @@ clear = setInterval(reloadTime, 1000); }); + content.then((data) => { + loadProgress.set(100); + tick(); + }); + let x = null; let y = null; @@ -159,7 +130,7 @@

{hashedIP}

- {#await promise then response} + {#await content then response} Date: Tue, 3 Dec 2024 14:35:25 -0500 Subject: [PATCH 03/30] Dockerize Backend --- backend/Dockerfile | 10 ++++++++++ backend/build.gradle.kts | 6 ++++++ 2 files changed, 16 insertions(+) create mode 100644 backend/Dockerfile diff --git a/backend/Dockerfile b/backend/Dockerfile new file mode 100644 index 0000000..660518c --- /dev/null +++ b/backend/Dockerfile @@ -0,0 +1,10 @@ + +FROM openjdk:21-jdk-slim + +WORKDIR /pastebook-backend + +COPY build/libs/pastebook.jar pastebook.jar + +EXPOSE 8080 + +ENTRYPOINT ["java", "-jar", "pastebook.jar"] \ No newline at end of file diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 24ad5a4..f846cc5 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -46,6 +46,12 @@ tasks.withType { } } +tasks.bootJar { + archiveBaseName.set("pastebook") + archiveVersion.set("") + archiveClassifier.set("") +} + tasks.withType { useJUnitPlatform() } From a68719291036c543a74ada5d623f2e311d52b105 Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 15:50:09 -0500 Subject: [PATCH 04/30] Dockerize Frontend --- frontend/Dockerfile | 24 +++++++++++++++++++ frontend/src/app.html | 2 +- frontend/src/components/Content.svelte | 6 ++--- .../src/components/PotentialIssues.svelte | 2 +- frontend/src/components/new/Submit.svelte | 6 +++-- .../[pastes=paste]/[slug]/+page.server.ts | 4 ++-- frontend/src/routes/panel/+page.server.ts | 2 +- 7 files changed, 36 insertions(+), 10 deletions(-) create mode 100644 frontend/Dockerfile diff --git a/frontend/Dockerfile b/frontend/Dockerfile new file mode 100644 index 0000000..47b0e08 --- /dev/null +++ b/frontend/Dockerfile @@ -0,0 +1,24 @@ +FROM node:23-alpine AS build + +WORKDIR /pastebook-frontend + +ARG VITE_API_URL + +ENV VITE_API_URL=${VITE_API_URL} + +COPY package*.json ./ +RUN npm install +COPY . . +RUN npm run build + +FROM node:23-alpine + +WORKDIR /pastebook-frontend + +COPY --from=build /pastebook-frontend /pastebook-frontend + +RUN npm install --production + +EXPOSE 3000 + +CMD ["node", "build"] \ No newline at end of file diff --git a/frontend/src/app.html b/frontend/src/app.html index e839466..a643053 100755 --- a/frontend/src/app.html +++ b/frontend/src/app.html @@ -9,7 +9,7 @@ rel="stylesheet" /> diff --git a/frontend/src/components/Content.svelte b/frontend/src/components/Content.svelte index ccae2c2..70e9947 100755 --- a/frontend/src/components/Content.svelte +++ b/frontend/src/components/Content.svelte @@ -294,7 +294,7 @@ background-color: transparent; color: inherit; font-size: 13px; - font-family: "JetBrains Mono NL", monospace; + font-family: "JetBrains Mono", monospace; outline: none; resize: none; margin: 30px; @@ -330,7 +330,7 @@ text-align: right; padding-right: 20px; color: #9999; - font-family: "JetBrains Mono NL", monospace; + font-family: "JetBrains Mono", monospace; font-size: 13px; margin: 0; opacity: 1; @@ -363,7 +363,7 @@ font-size: 13px; white-space: pre; - font-family: "JetBrains Mono NL", monospace; + font-family: "JetBrains Mono ", monospace; margin: 0; padding-left: 51px; text-indent: -26px; diff --git a/frontend/src/components/PotentialIssues.svelte b/frontend/src/components/PotentialIssues.svelte index c4b82a8..90b2d53 100755 --- a/frontend/src/components/PotentialIssues.svelte +++ b/frontend/src/components/PotentialIssues.svelte @@ -69,7 +69,7 @@ padding-left: 10px; padding-right: 10px; font-family: - JetBrains Mono NL, + "JetBrains Mono", monospace; @media (max-width: 800px) { diff --git a/frontend/src/components/new/Submit.svelte b/frontend/src/components/new/Submit.svelte index 7ece045..0860d7a 100755 --- a/frontend/src/components/new/Submit.svelte +++ b/frontend/src/components/new/Submit.svelte @@ -3,7 +3,7 @@ import { writableContent } from "$lib/stores.ts"; import { onMount } from "svelte"; - const backendUrl = import.meta.env.VITE_BACKEND_URL; + const backendUrl = import.meta.env.VITE_API_URL; onMount(() => { writableTitle.subscribe(() => { @@ -47,6 +47,8 @@ let submit = document.getElementsByClassName("submit")[0] as HTMLElement; + console.log(backendUrl) + alreadyUploading = true; submit.classList.add("loading"); const xhr = new XMLHttpRequest(); @@ -72,7 +74,7 @@ return; } - window.location.replace(xhr.response); + window.location.replace("/p/" + xhr.response); }; } diff --git a/frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts b/frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts index 637367a..86d4e3f 100755 --- a/frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts +++ b/frontend/src/routes/[pastes=paste]/[slug]/+page.server.ts @@ -4,7 +4,7 @@ export async function load({ params, cookies }) { let path = params.slug; let response = await fetch( - "http://localhost:25658/get/" + path + "/metadata", + "http://pastebook-backend:8080/get/" + path + "/metadata", ); if (response.status === 404) { @@ -36,7 +36,7 @@ export async function load({ params, cookies }) { return { metadata: metadataPromise, content: metadataPromise.then(async () => { - return fetch("http://localhost:25658/get/" + path + "/content").then( + return fetch("http://pastebook-backend:8080/get/" + path + "/content").then( (response) => { return response.text(); }, diff --git a/frontend/src/routes/panel/+page.server.ts b/frontend/src/routes/panel/+page.server.ts index e1616e6..65098cc 100755 --- a/frontend/src/routes/panel/+page.server.ts +++ b/frontend/src/routes/panel/+page.server.ts @@ -1,7 +1,7 @@ import { error } from "@sveltejs/kit"; export async function load({ params }) { - const response = await fetch("http://localhost:25658/list"); + const response = await fetch("http://pastebook-backend:8080/list"); if (response.status === 429) { error(429, { From 9d580daa82d6d9ea67235e3a61e09d7ebe387e71 Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 15:55:08 -0500 Subject: [PATCH 05/30] Remove Panel --- .../pastebook/controllers/ListController.kt | 56 ----- frontend/src/app.html | 1 + frontend/src/components/Toolbar.svelte | 5 - frontend/src/routes/+page.svelte | 6 +- frontend/src/routes/panel/+page.server.ts | 23 -- frontend/src/routes/panel/+page.svelte | 201 ------------------ 6 files changed, 2 insertions(+), 290 deletions(-) delete mode 100644 backend/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt delete mode 100755 frontend/src/routes/panel/+page.server.ts delete mode 100755 frontend/src/routes/panel/+page.svelte diff --git a/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt b/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt deleted file mode 100644 index bf80b37..0000000 --- a/backend/src/main/kotlin/dev/loudbook/pastebook/controllers/ListController.kt +++ /dev/null @@ -1,56 +0,0 @@ -package dev.loudbook.pastebook.controllers - -import com.google.gson.Gson -import dev.loudbook.pastebook.BucketUtils -import dev.loudbook.pastebook.data.UserDTO -import dev.loudbook.pastebook.mongo.PasteRepository -import dev.loudbook.pastebook.mongo.UserService -import io.github.bucket4j.Bucket -import jakarta.servlet.http.HttpServletRequest -import org.springframework.beans.factory.annotation.Autowired -import org.springframework.http.ResponseEntity -import org.springframework.web.bind.annotation.GetMapping -import org.springframework.web.bind.annotation.RequestMapping -import org.springframework.web.bind.annotation.RestController - -@RestController -class ListController { - @Autowired - lateinit var pasteRepository: PasteRepository - - @Autowired - lateinit var userService: UserService - - private val bucket: Bucket = BucketUtils.getBucketPerSeconds(4) - - @GetMapping("/list") - fun list(request: HttpServletRequest): ResponseEntity { - if (!userService.processRequest(request)) { - return ResponseEntity.status(403).body("Prohibited") - } - - if (!bucket.tryConsume(1)) { - return ResponseEntity.status(429).body("Rate limit exceeded") - } - - val users = pasteRepository.findAllDTO().map { it.creatorIP }.toMutableList() - val ipToUsers: Map = users - .filter { userService.getUser(it) != null } - .associateWith { userService.getUser(it)!!.toDTO() } - - val userPastes = pasteRepository.findAllDTO() - .asSequence() - .filter { it.creatorIP in users && ipToUsers.containsKey(it.creatorIP) && it.created < System.currentTimeMillis() && !it.unlisted } - .map { it.toPublicDTO(ipToUsers[it.creatorIP]!!) } - .take(80) - .toList() - - val json = Gson().toJsonTree(userPastes).asJsonArray - - json.mapIndexed { _, element -> - element.asJsonObject.remove("content") - } - - return ResponseEntity.ok(json.toString()) - } -} \ No newline at end of file diff --git a/frontend/src/app.html b/frontend/src/app.html index a643053..cfb48cc 100755 --- a/frontend/src/app.html +++ b/frontend/src/app.html @@ -2,6 +2,7 @@ + - diff --git a/frontend/src/routes/+page.svelte b/frontend/src/routes/+page.svelte index 54a76c0..5b56a41 100755 --- a/frontend/src/routes/+page.svelte +++ b/frontend/src/routes/+page.svelte @@ -24,8 +24,6 @@ {#if width > 768} ⎯ - - ⎯ GITHUB ⎯ @@ -35,8 +33,6 @@ {:else}
- ⎯ -
- import Header from "../../components/Header.svelte"; - import ListedPaste from "../../components/panel/ListedPaste.svelte"; - import Mode from "../../components/Mode.svelte"; - import { onMount } from "svelte"; - import type { Paste } from "$lib/paste"; - import SVGPasteBook from "../../components/svg/SVGPasteBook.svelte"; - import { loadProgress } from "$lib/stores"; - - export let data; - - let { promise } = data; - - let pastes: Paste[] = []; - - promise.then((data) => { - loadProgress.set(100); - - data.forEach((paste: Paste) => { - pastes.push({ - id: paste.id, - title: paste.title, - created: paste.created, - reportBook: paste.reportBook, - wrap: paste.wrap, - user: { - hashedIP: paste.user.hashedIP, - }, - expiresAt: paste.expiresAt, - }); - }); - let current = Date.now(); - - pastes = pastes.filter((paste) => { - return (paste.created as unknown as number) < current; - }); - - pastes.sort((a, b) => { - return ( - (b.created as unknown as number) - (a.created as unknown as number) - ); - }); - }); - - onMount(async () => { - await promise; - setTimeout(() => { - let fades = document.getElementsByClassName("fade"); - - for (let i = 0; i < fades.length; i++) { - let fade = fades[i] as HTMLElement; - - setTimeout(() => { - fade.style.opacity = "1"; - fade.style.transform = "translateY(0)"; - }, i * 60); - } - }, 100); - }); - - - -
- - {#await promise then data} - {#if pastes.length === 0} -
-
-

No Pastes Found

- - - -
- {:else} -
- {#each pastes as paste} -
- -
- {/each} - {/if} - {/await} - - - - - - - - - - - - From 02c9ae584101b315de27f7be84089b7b3b1593ea Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 15:57:43 -0500 Subject: [PATCH 06/30] Cleanup --- .gitignore | 3 +- .idea/workspace.xml | 78 +---------- .../pastebook/controllers/UploadController.kt | 3 +- .../dev/loudbook/pastebook/data/Paste.kt | 2 +- .../dev/loudbook/pastebook/data/PasteDTO.kt | 2 +- .../pastebook/data/PastePrivateDTO.kt | 4 +- frontend/package-lock.json | 121 +++++++----------- frontend/package.json | 2 +- frontend/src/components/new/Submit.svelte | 3 +- frontend/src/lib/stores.ts | 1 - frontend/src/routes/new/+page.svelte | 14 +- frontend/src/routes/settings/+page.svelte | 17 --- 12 files changed, 56 insertions(+), 194 deletions(-) diff --git a/.gitignore b/.gitignore index a40f1fd..fdce34f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .* -!.gitignore \ No newline at end of file +!.gitignore +docker-compose.yml \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml index d3f48ae..15ad1fd 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,81 +4,7 @@
+ +# Installation +The following is a guide to get PasteBook running on your system under your domain with SSL. All of this was tested on Ubuntu Linux. + +## Prerequisites +- An S3 bucket. In testing, CloudFlare R2 was used. CloudFlare R2 is free. You can learn more [here](https://www.cloudflare.com/developer-platform/products/r2/). +- Docker. Both the frontend and backend are to be installed with Docker. You can learn more [here](https://www.docker.com). + +## Preparation +Start by creating a file named `docker-compose.yml`. Add the content below. +```yml +services: + pastebook-backend: + build: + context: ./backend + dockerfile: Dockerfile + ports: + - "8080:8080" + environment: + - SPRING_DATA_MONGODB_URI=mongodb://mongo:27017/pastebook + - SPRING_DATA_MONGODB_DATABASE=pastebook + - S3_ACCESS_KEY_ID= + - S3_SECRET_ACCESS_KEY= + - S3_ENDPOINT= + - S3_BUCKET=pastebook + depends_on: + - mongo + networks: + - pastebook-network + + frontend: + build: + context: ./frontend + dockerfile: Dockerfile + args: + VITE_API_URL: "" + ports: + - "80:3000" + depends_on: + - pastebook-backend + networks: + - pastebook-network + + mongo: + image: mongo:6.0 + container_name: mongo + ports: + - "27017:27017" + environment: + MONGO_INITDB_DATABASE: pastebook + volumes: + - mongo-data:/data/db + networks: + - pastebook-network + +volumes: + mongo-data: + +networks: + pastebook-network: + driver: bridge +``` +## Configuration +All of the following values must be changed. +
+ +`S3_ACCESS_KEY_ID` - The access key associated with your R2 bucket, S3 bucket, etc. + +`S3_SECRET_ACCESS_KEY` - The secret access key associated with your R2 bucket, S3 bucket, etc. + +`S3_ENDPOINT` - The endpoint associated with your R2 bucket, S3 bucket, etc. + +`VITE_API_URL` - The full endpoint of the API. When locally testing this is `http://localhost:8080`. In my case, when in production, it would be `https://api.pastebook.dev/`. + +## Creation +Run the following. +``` +docker-compose up +``` + +Awesome! PasteBook is now running. + +# Nginx Configuration +In order to run PasteBook under a domain, you will need to use a reverse proxy. The following will serve as a guide to setting up Nginx. + +## Prerequisites +- PasteBook is fully installed with the instructions above. +- A working Nginx installation. Learn more [here](https://nginx.org/en/linux_packages.html#instructions). +- A working Certbot installation. Learn more [here](https://certbot.eff.org/instructions?ws=nginx&os=snap). +## Preparation +Navigate to `/etc/nginx/sites-enabled`. +Create a file under the name `pastebook.conf` and add the following content: +```conf +server { + listen 80; + server_name + + # Redirect HTTP to HTTPS + location / { + return 301 https://$host$request_uri; + } +} + +server { + listen 443 ssl; + server_name + + location / { + proxy_buffering off; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + proxy_pass http://localhost:3000/; + } +} + +server { + listen 80; + server_name api. + + location / { + return 301 https://$host$request_uri; + } +} + +server { + listen 443 ssl; + server_name api + + location / { + proxy_buffering off; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-Host $host; + proxy_set_header X-Forwarded-Port $server_port; + proxy_pass http://localhost:8080/; + } +} +``` + +## Configuration +`` - Change this to your domain name. For example, mine is `pastebook.dev`. + +## SSL Configuration +Run the following, with `` changed to your domain. +``` +sudo certbot --nginx -d -d api. +``` + +## Committing Changes +Run the following. +``` +systemctl restart nginx +``` + +# Final Notes +Wow. There was a lot that can go wrong there. I'm not an expert. If you need help, you can email me at contact@loudbook.dev or find me elsewhere. +💜 From 20ade9b06b9b42e7ebf1704b9a7d37d4d840c5e3 Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 18:08:37 -0500 Subject: [PATCH 22/30] Update README.md --- README.md | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 6dd823d..0201ce1 100644 --- a/README.md +++ b/README.md @@ -1,19 +1,14 @@ -
-

PasteBook

-

PasteBook is an aesthetic, effortless way to share your blocks of text. - - [![Static Badge](https://img.shields.io/badge/Website-brightgreen?style=for-the-badge)](https://pastebook.dev) - -

- -# Installation +# PasteBook +An easy on the eyes, portable, fun paste bin written in Svelte and Kotlin. + +## Installation The following is a guide to get PasteBook running on your system under your domain with SSL. All of this was tested on Ubuntu Linux. -## Prerequisites +### Prerequisites - An S3 bucket. In testing, CloudFlare R2 was used. CloudFlare R2 is free. You can learn more [here](https://www.cloudflare.com/developer-platform/products/r2/). - Docker. Both the frontend and backend are to be installed with Docker. You can learn more [here](https://www.docker.com). -## Preparation +### Preparation Start by creating a file named `docker-compose.yml`. Add the content below. ```yml services: @@ -67,7 +62,7 @@ networks: pastebook-network: driver: bridge ``` -## Configuration +### Configuration All of the following values must be changed.
@@ -79,7 +74,7 @@ All of the following values must be changed. `VITE_API_URL` - The full endpoint of the API. When locally testing this is `http://localhost:8080`. In my case, when in production, it would be `https://api.pastebook.dev/`. -## Creation +### Creation Run the following. ``` docker-compose up @@ -87,22 +82,21 @@ docker-compose up Awesome! PasteBook is now running. -# Nginx Configuration +## Nginx Configuration In order to run PasteBook under a domain, you will need to use a reverse proxy. The following will serve as a guide to setting up Nginx. -## Prerequisites +### Prerequisites - PasteBook is fully installed with the instructions above. - A working Nginx installation. Learn more [here](https://nginx.org/en/linux_packages.html#instructions). - A working Certbot installation. Learn more [here](https://certbot.eff.org/instructions?ws=nginx&os=snap). ## Preparation Navigate to `/etc/nginx/sites-enabled`. Create a file under the name `pastebook.conf` and add the following content: -```conf +```nginx server { listen 80; server_name - # Redirect HTTP to HTTPS location / { return 301 https://$host$request_uri; } @@ -144,16 +138,16 @@ server { } ``` -## Configuration +### Configuration `` - Change this to your domain name. For example, mine is `pastebook.dev`. -## SSL Configuration +### SSL Configuration Run the following, with `` changed to your domain. ``` sudo certbot --nginx -d -d api. ``` -## Committing Changes +### Committing Changes Run the following. ``` systemctl restart nginx From 97f65c27fcdce0b8247fef8430893d55513485fb Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 18:17:58 -0500 Subject: [PATCH 23/30] Change to S3 --- backend/src/main/resources/application.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/backend/src/main/resources/application.yml b/backend/src/main/resources/application.yml index 0cce761..95edac5 100644 --- a/backend/src/main/resources/application.yml +++ b/backend/src/main/resources/application.yml @@ -9,7 +9,7 @@ spring: uri: ${SPRING_DATA_MONGODB_URI} s3: - url: ${R2_ENDPOINT} - accessKey: ${AWS_ACCESS_KEY_ID} - secretKey: ${AWS_SECRET_ACCESS_KEY} - bucket: ${R2_BUCKET} \ No newline at end of file + url: ${S3_ENDPOINT} + accessKey: ${S3_ACCESS_KEY_ID} + secretKey: ${S3_SECRET_ACCESS_KEY} + bucket: ${S3_BUCKET} \ No newline at end of file From 109a56094e1a5da38d5282e37d9301d65a1050ba Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 18:24:22 -0500 Subject: [PATCH 24/30] Update README.md --- README.md | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 0201ce1..05d2f1c 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,7 @@ Start by creating a file named `docker-compose.yml`. Add the content below. ```yml services: pastebook-backend: - build: - context: ./backend - dockerfile: Dockerfile + image: loudbook/pastebook-backend:latest ports: - "8080:8080" environment: @@ -31,9 +29,8 @@ services: - pastebook-network frontend: + image: loudbook/pastebook-frontend:latest build: - context: ./frontend - dockerfile: Dockerfile args: VITE_API_URL: "" ports: From 5391a2f2b081de2e970a07eb4e7e482a2e42b310 Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 18:40:26 -0500 Subject: [PATCH 25/30] Remove environmental variable --- frontend/Dockerfile | 4 - frontend/src/components/new/Submit.svelte | 8 +- .../src/components/panel/ListedPaste.svelte | 146 ------------------ 3 files changed, 4 insertions(+), 154 deletions(-) delete mode 100755 frontend/src/components/panel/ListedPaste.svelte diff --git a/frontend/Dockerfile b/frontend/Dockerfile index 47b0e08..7e7636c 100644 --- a/frontend/Dockerfile +++ b/frontend/Dockerfile @@ -2,10 +2,6 @@ FROM node:23-alpine AS build WORKDIR /pastebook-frontend -ARG VITE_API_URL - -ENV VITE_API_URL=${VITE_API_URL} - COPY package*.json ./ RUN npm install COPY . . diff --git a/frontend/src/components/new/Submit.svelte b/frontend/src/components/new/Submit.svelte index de0080b..f4dc7bc 100755 --- a/frontend/src/components/new/Submit.svelte +++ b/frontend/src/components/new/Submit.svelte @@ -3,8 +3,6 @@ import { writableContent } from "$lib/stores.ts"; import { onMount } from "svelte"; - const backendUrl = import.meta.env.VITE_API_URL; - onMount(() => { writableTitle.subscribe(() => { allFieldsFilled(); @@ -50,9 +48,11 @@ console.log(backendUrl) alreadyUploading = true; - submit.classList.add("loading"); const xhr = new XMLHttpRequest(); - xhr.open("POST", `${backendUrl}/upload`); + + let domain = window.location.host; + + xhr.open("POST", `https://api.${domain}/upload`); xhr.setRequestHeader("Content-Type", "plain/text"); xhr.setRequestHeader("access-control-allow-methods", "POST"); xhr.setRequestHeader("title", $writableTitle); diff --git a/frontend/src/components/panel/ListedPaste.svelte b/frontend/src/components/panel/ListedPaste.svelte deleted file mode 100755 index a4fa3c9..0000000 --- a/frontend/src/components/panel/ListedPaste.svelte +++ /dev/null @@ -1,146 +0,0 @@ - - - - - - - From 019f03d35afd81792229f8fc6e45928dd529a9bf Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 18:44:56 -0500 Subject: [PATCH 26/30] Fix error --- frontend/src/components/new/Submit.svelte | 2 -- 1 file changed, 2 deletions(-) diff --git a/frontend/src/components/new/Submit.svelte b/frontend/src/components/new/Submit.svelte index f4dc7bc..0a255c3 100755 --- a/frontend/src/components/new/Submit.svelte +++ b/frontend/src/components/new/Submit.svelte @@ -45,8 +45,6 @@ let submit = document.getElementsByClassName("submit")[0] as HTMLElement; - console.log(backendUrl) - alreadyUploading = true; const xhr = new XMLHttpRequest(); From 382e5b03e26e754665332e48d39e30f5bd261519 Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 18:48:52 -0500 Subject: [PATCH 27/30] Re-Add Submit Class --- frontend/src/components/new/Submit.svelte | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/src/components/new/Submit.svelte b/frontend/src/components/new/Submit.svelte index 0a255c3..48ecf6f 100755 --- a/frontend/src/components/new/Submit.svelte +++ b/frontend/src/components/new/Submit.svelte @@ -44,6 +44,7 @@ } let submit = document.getElementsByClassName("submit")[0] as HTMLElement; + submit.classList.add("loading"); alreadyUploading = true; const xhr = new XMLHttpRequest(); From dbd332771ce79c6b449bf95e1842fa52cd1d43c3 Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 18:50:29 -0500 Subject: [PATCH 28/30] Update README.md --- README.md | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 05d2f1c..69fc0e9 100644 --- a/README.md +++ b/README.md @@ -30,15 +30,13 @@ services: frontend: image: loudbook/pastebook-frontend:latest - build: - args: - VITE_API_URL: "" ports: - "80:3000" depends_on: - pastebook-backend networks: - pastebook-network + pull_policy: always mongo: image: mongo:6.0 @@ -51,6 +49,7 @@ services: - mongo-data:/data/db networks: - pastebook-network + pull_policy: always volumes: mongo-data: @@ -69,8 +68,6 @@ All of the following values must be changed. `S3_ENDPOINT` - The endpoint associated with your R2 bucket, S3 bucket, etc. -`VITE_API_URL` - The full endpoint of the API. When locally testing this is `http://localhost:8080`. In my case, when in production, it would be `https://api.pastebook.dev/`. - ### Creation Run the following. ``` @@ -123,7 +120,7 @@ server { server { listen 443 ssl; - server_name api + server_name api. location / { proxy_buffering off; @@ -150,6 +147,14 @@ Run the following. systemctl restart nginx ``` +# Updating PasteBook +Run the following commands in succession. +```bash +docker compose stop +docker compose pull +docker compose up -d +``` + # Final Notes Wow. There was a lot that can go wrong there. I'm not an expert. If you need help, you can email me at contact@loudbook.dev or find me elsewhere. 💜 From a426ffb31c0930e3c1735cec09165e1bb45c5e9e Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 19:25:18 -0500 Subject: [PATCH 29/30] Fixes --- README.md | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 69fc0e9..e67c62a 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ Create a file under the name `pastebook.conf` and add the following content: ```nginx server { listen 80; - server_name + server_name ; location / { return 301 https://$host$request_uri; @@ -98,7 +98,7 @@ server { server { listen 443 ssl; - server_name + server_name ; location / { proxy_buffering off; @@ -111,7 +111,7 @@ server { server { listen 80; - server_name api. + server_name api.; location / { return 301 https://$host$request_uri; @@ -120,7 +120,9 @@ server { server { listen 443 ssl; - server_name api. + server_name api.; + + client_max_body_size 6M; location / { proxy_buffering off; From 719f7d17ea9620ffe1c6041e2280c207bd3f2052 Mon Sep 17 00:00:00 2001 From: Loudbook Date: Tue, 3 Dec 2024 19:27:56 -0500 Subject: [PATCH 30/30] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e67c62a..1bfcaed 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ services: frontend: image: loudbook/pastebook-frontend:latest ports: - - "80:3000" + - "3000:3000" depends_on: - pastebook-backend networks: