Skip to content

Commit 5991af3

Browse files
Add default CDN handling for local storage URL generation
1 parent c3e3f77 commit 5991af3

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

extensions/entity-files/sources/core/src/main/java/tools/dynamia/modules/entityfile/local/LocalEntityFileStorage.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@
3737
import java.io.File;
3838
import java.io.IOException;
3939
import java.io.Serial;
40+
import java.net.URI;
4041

4142
@Service
4243
public class LocalEntityFileStorage implements EntityFileStorage {
4344

45+
public static final String LOCAL_STORAGE_DEFAULT_CDN = "LOCAL_STORAGE_DEFAULT_CDN";
4446
private final LoggingService logger = new SLF4JLoggingService(LocalEntityFileStorage.class, "Local: ");
4547

4648
public static final String ID = "LocalStorage";
@@ -106,6 +108,18 @@ public String generateURL(EntityFile entityFile) {
106108
serverPath = serverPath.replace("http:", "https:");
107109
}
108110

111+
if (serverPath == null || serverPath.isBlank()) {
112+
String cdn = environment.getProperty(LOCAL_STORAGE_DEFAULT_CDN);
113+
try {
114+
if (cdn != null && !cdn.isBlank()) {
115+
serverPath = URI.create(cdn).toURL().toString();
116+
}
117+
} catch (Exception e) {
118+
logger.warn("Error generating local storage url for default CDN: " + cdn, e);
119+
}
120+
}
121+
122+
109123
String context = getContextPath();
110124

111125

0 commit comments

Comments
 (0)