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

View File

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