Update GeneralUtils.java

This commit is contained in:
Ludy87 2025-07-19 02:15:46 +02:00
parent 768f695f6b
commit d395ce6a4f
No known key found for this signature in database
GPG Key ID: 92696155E0220F94

View File

@ -444,14 +444,24 @@ public class GeneralUtils {
}
/**
* Extracts a file from classpath:/static/python to a temporary directory and returns the
* path.
*/
* Extracts a file from classpath:/static/python to a temporary directory and returns the path.
*/
public static Path extractScript(String scriptName) throws IOException {
// Validate input
if (scriptName == null || scriptName.trim().isEmpty()) {
throw new IllegalArgumentException("scriptName must not be null or empty");
}
if (scriptName.contains("..") || scriptName.contains("/")) {
throw new IllegalArgumentException(
"scriptName must not contain path traversal characters");
}
List<String> validScripts = Arrays.asList("png_to_webp.py", "split_photos.py");
if (!validScripts.contains(scriptName)) {
throw new IllegalArgumentException(
"scriptName must be either 'png_to_webp.py' or 'split_photos.py'");
}
// 1. load the script from classpath
ClassPathResource resource = new ClassPathResource("static/python/" + scriptName);