allow -1 for the paste limit to disable it

This commit is contained in:
Lee 2024-04-23 21:18:02 +01:00
parent 5a0286412f
commit 2ca9b6ce5f
2 changed files with 6 additions and 3 deletions

@ -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();
}

@ -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