Compare commits

...

2 Commits

Author SHA1 Message Date
6ae8929d91 cleanup
All checks were successful
Deploy App / docker (ubuntu-latest, 2.44.0, 17, 3.8.5) (push) Successful in 1m17s
Publish Docker Image / docker (ubuntu-latest) (push) Successful in 54s
2024-04-23 21:18:15 +01:00
2ca9b6ce5f allow -1 for the paste limit to disable it 2024-04-23 21:18:02 +01:00
2 changed files with 7 additions and 4 deletions

View File

@ -1,8 +1,8 @@
package cc.fascinated.backend.service;
import cc.fascinated.backend.exception.impl.BadRequestException;
import cc.fascinated.backend.model.Paste;
import cc.fascinated.backend.exception.impl.ResourceNotFoundException;
import cc.fascinated.backend.model.Paste;
import cc.fascinated.backend.repository.PasteRepository;
import org.apache.commons.lang3.RandomStringUtils;
import org.springframework.beans.factory.annotation.Autowired;
@ -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();
}

View File

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