|
|
@ -1,8 +1,8 @@
|
|
|
|
package cc.fascinated.backend.service;
|
|
|
|
package cc.fascinated.backend.service;
|
|
|
|
|
|
|
|
|
|
|
|
import cc.fascinated.backend.exception.impl.BadRequestException;
|
|
|
|
import cc.fascinated.backend.exception.impl.BadRequestException;
|
|
|
|
import cc.fascinated.backend.model.Paste;
|
|
|
|
|
|
|
|
import cc.fascinated.backend.exception.impl.ResourceNotFoundException;
|
|
|
|
import cc.fascinated.backend.exception.impl.ResourceNotFoundException;
|
|
|
|
|
|
|
|
import cc.fascinated.backend.model.Paste;
|
|
|
|
import cc.fascinated.backend.repository.PasteRepository;
|
|
|
|
import cc.fascinated.backend.repository.PasteRepository;
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
@ -44,10 +44,13 @@ public class PasteService {
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public String createPaste(String content) {
|
|
|
|
public String createPaste(String content) {
|
|
|
|
int length = content.length();
|
|
|
|
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");
|
|
|
|
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(
|
|
|
|
return pasteRepository.save(new Paste(
|
|
|
|
RandomStringUtils.randomAlphabetic(idLength),
|
|
|
|
RandomStringUtils.randomAlphabetic(idLength),
|
|
|
|
System.currentTimeMillis(),
|
|
|
|
System.currentTimeMillis(),
|
|
|
@ -66,7 +69,7 @@ public class PasteService {
|
|
|
|
|
|
|
|
|
|
|
|
// The paste does not exist.
|
|
|
|
// The paste does not exist.
|
|
|
|
if (paste.isEmpty()) {
|
|
|
|
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();
|
|
|
|
return paste.get();
|
|
|
|
}
|
|
|
|
}
|
|
|
|