From cd228317c6e9ba236ba7b83c355b6be70857218c Mon Sep 17 00:00:00 2001 From: vsevel Date: Tue, 5 Nov 2024 09:59:40 +0100 Subject: [PATCH] Additional Presets --- .../io/quarkus/code/config/CodeQuarkusConfig.java | 3 +++ .../java/io/quarkus/code/config/PresetConfig.java | 14 ++++++++++++++ .../io/quarkus/code/rest/CodeQuarkusResource.java | 10 +++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 base/src/main/java/io/quarkus/code/config/PresetConfig.java diff --git a/base/src/main/java/io/quarkus/code/config/CodeQuarkusConfig.java b/base/src/main/java/io/quarkus/code/config/CodeQuarkusConfig.java index 5b751db36..8a2fecccf 100644 --- a/base/src/main/java/io/quarkus/code/config/CodeQuarkusConfig.java +++ b/base/src/main/java/io/quarkus/code/config/CodeQuarkusConfig.java @@ -1,5 +1,6 @@ package io.quarkus.code.config; +import java.util.List; import java.util.Optional; import io.smallrye.config.ConfigMapping; @@ -20,4 +21,6 @@ public interface CodeQuarkusConfig { Optional hostname(); UIConfig ui(); + + List presets(); } diff --git a/base/src/main/java/io/quarkus/code/config/PresetConfig.java b/base/src/main/java/io/quarkus/code/config/PresetConfig.java new file mode 100644 index 000000000..1dd1bd332 --- /dev/null +++ b/base/src/main/java/io/quarkus/code/config/PresetConfig.java @@ -0,0 +1,14 @@ +package io.quarkus.code.config; + +import java.util.List; + +public interface PresetConfig { + + String key(); + + String title(); + + String icon(); + + List extensions(); +} diff --git a/base/src/main/java/io/quarkus/code/rest/CodeQuarkusResource.java b/base/src/main/java/io/quarkus/code/rest/CodeQuarkusResource.java index e9e0beb9c..4dab870e2 100644 --- a/base/src/main/java/io/quarkus/code/rest/CodeQuarkusResource.java +++ b/base/src/main/java/io/quarkus/code/rest/CodeQuarkusResource.java @@ -174,7 +174,8 @@ public Uni presetsForStream( private Uni presets(Map extensionsById) { String lastUpdated = platformService.cacheLastUpdated().format(FORMATTER); - final List presets = PRESETS.stream().filter(p -> p.extensions().stream().allMatch(extensionsById::containsKey)) + final List presets = getAllPresets().stream() + .filter(p -> p.extensions().stream().allMatch(extensionsById::containsKey)) .toList(); Response response = Response.ok(presets) .header(LAST_MODIFIED_HEADER, lastUpdated) @@ -182,6 +183,13 @@ private Uni presets(Map extensionsById) { return Uni.createFrom().item(response); } + List getAllPresets() { + List presets = new ArrayList<>(PRESETS); + config.presets().stream().map(presetConfig -> new Preset(presetConfig.key(), presetConfig.title(), presetConfig.icon(), + presetConfig.extensions())).forEach(presets::add); + return presets; + } + private Uni extensions( boolean platformOnly, List extensions,