Update GeneralUtils.java

This commit is contained in:
Ludy87 2025-07-19 19:04:16 +02:00
parent cf9ed0e8f9
commit 27f4beb66a
No known key found for this signature in database
GPG Key ID: 92696155E0220F94

View File

@ -34,6 +34,9 @@ import stirling.software.common.configuration.InstallationPathConfig;
@Slf4j @Slf4j
public class GeneralUtils { public class GeneralUtils {
private static final List<String> DEFAULT_VALID_SCRIPTS =
List.of("png_to_webp.py", "split_photos.py");
public static File convertMultipartFileToFile(MultipartFile multipartFile) throws IOException { public static File convertMultipartFileToFile(MultipartFile multipartFile) throws IOException {
String customTempDir = System.getenv("STIRLING_TEMPFILES_DIRECTORY"); String customTempDir = System.getenv("STIRLING_TEMPFILES_DIRECTORY");
if (customTempDir == null || customTempDir.isEmpty()) { if (customTempDir == null || customTempDir.isEmpty()) {
@ -456,14 +459,12 @@ public class GeneralUtils {
"scriptName must not contain path traversal characters"); "scriptName must not contain path traversal characters");
} }
List<String> validScripts = Arrays.asList("png_to_webp.py", "split_photos.py"); if (!DEFAULT_VALID_SCRIPTS.contains(scriptName)) {
if (!validScripts.contains(scriptName)) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"scriptName must be either 'png_to_webp.py' or 'split_photos.py'"); "scriptName must be either 'png_to_webp.py' or 'split_photos.py'");
} }
Path scriptsDir = Paths.get(InstallationPathConfig.getScriptsPath() + "python"); Path scriptsDir = Paths.get(InstallationPathConfig.getScriptsPath(), "python");
Files.createDirectories(scriptsDir); Files.createDirectories(scriptsDir);
Path scriptFile = scriptsDir.resolve(scriptName); Path scriptFile = scriptsDir.resolve(scriptName);