From 2ca9b6ce5f8e384d87ea6149bf7b7ad2a56f4bfc Mon Sep 17 00:00:00 2001 From: Liam Date: Tue, 23 Apr 2024 21:18:02 +0100 Subject: [PATCH] allow -1 for the paste limit to disable it --- .../java/cc/fascinated/backend/service/PasteService.java | 7 +++++-- src/main/resources/application.yml | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/cc/fascinated/backend/service/PasteService.java b/src/main/java/cc/fascinated/backend/service/PasteService.java index c8cb4c8..27ed14c 100644 --- a/src/main/java/cc/fascinated/backend/service/PasteService.java +++ b/src/main/java/cc/fascinated/backend/service/PasteService.java @@ -44,10 +44,13 @@ public class PasteService { */ public String createPaste(String content) { int length = content.length(); - if (length > uploadSizeLimit) { + + // Check if the content is too large. + if (length > uploadSizeLimit && uploadSizeLimit != -1) { throw new BadRequestException("The paste content is too large, the limit is " + uploadSizeLimit + " characters"); } + // Save the paste to the database. return pasteRepository.save(new Paste( RandomStringUtils.randomAlphabetic(idLength), System.currentTimeMillis(), @@ -66,7 +69,7 @@ public class PasteService { // The paste does not exist. if (paste.isEmpty()) { - throw new ResourceNotFoundException("Paste with id '%s' not found".formatted(id)); + throw new ResourceNotFoundException("Paste '%s' not found".formatted(id)); } return paste.get(); } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 5ff02a7..e952a7b 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -23,7 +23,7 @@ spring: paste: # The length of the ID for the paste id-length: 12 - # The limit of the paste size (in characters) + # The limit of the paste size (in characters) - You can set it to "-1" to disable the limit upload-size-limit: 400000 # Set the embedded MongoDB version