diff --git a/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java b/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java index 34202cff9..ed6b247ce 100644 --- a/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java +++ b/src/main/java/stirling/software/SPDF/controller/web/GeneralWebController.java @@ -13,7 +13,6 @@ import java.util.stream.Stream; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.core.io.Resource; import org.springframework.core.io.ResourceLoader; -import org.springframework.core.io.support.ResourcePatternUtils; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @@ -31,6 +30,7 @@ import stirling.software.SPDF.config.RuntimePathConfig; import stirling.software.SPDF.controller.api.pipeline.UserServiceInterface; import stirling.software.SPDF.model.SignatureFile; import stirling.software.SPDF.service.SignatureService; +import stirling.software.SPDF.utils.GeneralUtils; @Controller @Tag(name = "General", description = "General APIs") @@ -241,8 +241,7 @@ public class GeneralWebController { private List getFontNamesFromLocation(String locationPattern) { try { Resource[] resources = - ResourcePatternUtils.getResourcePatternResolver(resourceLoader) - .getResources(locationPattern); + GeneralUtils.getResourcesFromLocationPattern(locationPattern, resourceLoader); return Arrays.stream(resources) .map( resource -> { diff --git a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java index d2615935f..9172b5151 100644 --- a/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java +++ b/src/main/java/stirling/software/SPDF/utils/GeneralUtils.java @@ -15,6 +15,9 @@ import java.util.Enumeration; import java.util.List; import java.util.UUID; +import org.springframework.core.io.Resource; +import org.springframework.core.io.ResourceLoader; +import org.springframework.core.io.support.ResourcePatternUtils; import org.springframework.web.multipart.MultipartFile; import com.fathzer.soft.javaluator.DoubleEvaluator; @@ -73,6 +76,19 @@ public class GeneralUtils { return safeName; } + // Get resources from a location pattern + public static Resource[] getResourcesFromLocationPattern( + String locationPattern, ResourceLoader resourceLoader) throws Exception { + // Normalize the path for file resources + if (locationPattern.startsWith("file:")) { + String rawPath = locationPattern.substring(5).replace("\\*", "").replace("/*", ""); + Path normalizePath = Paths.get(rawPath).normalize(); + locationPattern = "file:" + normalizePath.toString().replace("\\", "/") + "/*"; + } + return ResourcePatternUtils.getResourcePatternResolver(resourceLoader) + .getResources(locationPattern); + } + public static boolean isValidURL(String urlStr) { try { Urls.create(