remove pointless methods

This commit is contained in:
Anthony Stirling 2025-07-02 10:39:08 +01:00
parent 0b045bc23a
commit 63acd27492
5 changed files with 17 additions and 45 deletions

View File

@ -156,21 +156,6 @@ public class ExceptionUtils {
"error.fileFormatRequired", "File must be in {0} format", "HTML or ZIP"); "error.fileFormatRequired", "File must be in {0} format", "HTML or ZIP");
} }
public static IllegalArgumentException createMarkdownFileRequiredException() {
return createIllegalArgumentException(
"error.fileFormatRequired", "File must be in {0} format", "Markdown");
}
public static IllegalArgumentException createMarkdownFormatException() {
return createIllegalArgumentException(
"error.fileFormatRequired", "File must be in {0} format", ".md");
}
public static IllegalArgumentException createHtmlZipFormatException() {
return createIllegalArgumentException(
"error.fileFormatRequired", "File must be in {0} format", ".html or .zip");
}
public static IllegalArgumentException createPdfFileRequiredException() { public static IllegalArgumentException createPdfFileRequiredException() {
return createIllegalArgumentException( return createIllegalArgumentException(
"error.fileFormatRequired", "File must be in {0} format", "PDF"); "error.fileFormatRequired", "File must be in {0} format", "PDF");
@ -201,30 +186,7 @@ public class ExceptionUtils {
"error.toolNotInstalled", "{0} is not installed", null, "OCR tools"); "error.toolNotInstalled", "{0} is not installed", null, "OCR tools");
} }
/** Create URL/website conversion exceptions. */
public static IllegalArgumentException createInvalidUrlFormatException() {
return createIllegalArgumentException(
"error.invalidFormat",
"Invalid {0} format: {1}",
"URL",
"provided format is invalid");
}
public static IllegalArgumentException createUrlNotReachableException() {
return createIllegalArgumentException(
"error.urlNotReachable", "URL is not reachable, please provide a valid URL");
}
public static IllegalArgumentException createEndpointDisabledException() {
return createIllegalArgumentException(
"error.endpointDisabled", "This endpoint has been disabled by the admin");
}
/** Create system requirement exceptions. */ /** Create system requirement exceptions. */
public static IOException createPythonNotInstalledException() {
return createIOException("error.toolNotInstalled", "{0} is not installed", null, "Python");
}
public static IOException createPythonRequiredForWebpException() { public static IOException createPythonRequiredForWebpException() {
return createIOException( return createIOException(
"error.toolRequired", "{0} is required for {1}", null, "Python", "WebP conversion"); "error.toolRequired", "{0} is required for {1}", null, "Python", "WebP conversion");

View File

@ -53,7 +53,8 @@ public class ConvertHtmlToPDF {
String originalFilename = Filenames.toSimpleFileName(fileInput.getOriginalFilename()); String originalFilename = Filenames.toSimpleFileName(fileInput.getOriginalFilename());
if (originalFilename == null if (originalFilename == null
|| (!originalFilename.endsWith(".html") && !originalFilename.endsWith(".zip"))) { || (!originalFilename.endsWith(".html") && !originalFilename.endsWith(".zip"))) {
throw ExceptionUtils.createHtmlZipFormatException(); throw ExceptionUtils.createIllegalArgumentException(
"error.fileFormatRequired", "File must be in {0} format", ".html or .zip");
} }
boolean disableSanitize = boolean disableSanitize =

View File

@ -56,12 +56,14 @@ public class ConvertMarkdownToPdf {
MultipartFile fileInput = generalFile.getFileInput(); MultipartFile fileInput = generalFile.getFileInput();
if (fileInput == null) { if (fileInput == null) {
throw ExceptionUtils.createMarkdownFileRequiredException(); throw ExceptionUtils.createIllegalArgumentException(
"error.fileFormatRequired", "File must be in {0} format", "Markdown");
} }
String originalFilename = Filenames.toSimpleFileName(fileInput.getOriginalFilename()); String originalFilename = Filenames.toSimpleFileName(fileInput.getOriginalFilename());
if (originalFilename == null || !originalFilename.endsWith(".md")) { if (originalFilename == null || !originalFilename.endsWith(".md")) {
throw ExceptionUtils.createMarkdownFormatException(); throw ExceptionUtils.createIllegalArgumentException(
"error.fileFormatRequired", "File must be in {0} format", ".md");
} }
// Convert Markdown to HTML using CommonMark // Convert Markdown to HTML using CommonMark

View File

@ -51,16 +51,22 @@ public class ConvertWebsiteToPDF {
String URL = request.getUrlInput(); String URL = request.getUrlInput();
if (!applicationProperties.getSystem().getEnableUrlToPDF()) { if (!applicationProperties.getSystem().getEnableUrlToPDF()) {
throw ExceptionUtils.createEndpointDisabledException(); throw ExceptionUtils.createIllegalArgumentException(
"error.endpointDisabled", "This endpoint has been disabled by the admin");
} }
// Validate the URL format // Validate the URL format
if (!URL.matches("^https?://.*") || !GeneralUtils.isValidURL(URL)) { if (!URL.matches("^https?://.*") || !GeneralUtils.isValidURL(URL)) {
throw ExceptionUtils.createInvalidUrlFormatException(); throw ExceptionUtils.createIllegalArgumentException(
"error.invalidFormat",
"Invalid {0} format: {1}",
"URL",
"provided format is invalid");
} }
// validate the URL is reachable // validate the URL is reachable
if (!GeneralUtils.isURLReachable(URL)) { if (!GeneralUtils.isURLReachable(URL)) {
throw ExceptionUtils.createUrlNotReachableException(); throw ExceptionUtils.createIllegalArgumentException(
"error.urlNotReachable", "URL is not reachable, please provide a valid URL");
} }
Path tempOutputFile = null; Path tempOutputFile = null;

View File

@ -73,7 +73,8 @@ public class ExtractImageScansController {
List<Path> tempDirs = new ArrayList<>(); List<Path> tempDirs = new ArrayList<>();
if (!CheckProgramInstall.isPythonAvailable()) { if (!CheckProgramInstall.isPythonAvailable()) {
throw ExceptionUtils.createPythonNotInstalledException(); throw ExceptionUtils.createIOException(
"error.toolNotInstalled", "{0} is not installed", null, "Python");
} }
String pythonVersion = CheckProgramInstall.getAvailablePythonCommand(); String pythonVersion = CheckProgramInstall.getAvailablePythonCommand();