Skip to content
Snippets Groups Projects
Commit 0d17230c authored by Tobias Ullerich's avatar Tobias Ullerich
Browse files

Download plugin

parent f4e14c34
No related branches found
No related tags found
No related merge requests found
package de.tobias.playwall.controller; package de.tobias.playwall.controller;
import de.tobias.playwall.model.Plugin; import de.tobias.playwall.model.Plugin;
import de.tobias.playwall.service.ArtifactoryClient;
import de.tobias.playwall.service.PluginService; import de.tobias.playwall.service.PluginService;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import org.springframework.core.io.Resource;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.server.ResponseStatusException; import org.springframework.web.server.ResponseStatusException;
import reactor.core.publisher.Mono;
import java.util.List; import java.util.List;
...@@ -18,6 +21,7 @@ import java.util.List; ...@@ -18,6 +21,7 @@ import java.util.List;
public class PluginController public class PluginController
{ {
private final PluginService service; private final PluginService service;
private final ArtifactoryClient artifactoryClient;
@GetMapping @GetMapping
List<Plugin> getAllPlugins() List<Plugin> getAllPlugins()
...@@ -30,4 +34,11 @@ public class PluginController ...@@ -30,4 +34,11 @@ public class PluginController
{ {
return service.getPlugin(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND)); return service.getPlugin(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
} }
@GetMapping("/raw/{id}")
Mono<byte[]> getPluginExecutable(@PathVariable Integer id)
{
final Plugin plugin = service.getPlugin(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND));
return artifactoryClient.downloadArtifact(plugin);
}
} }
...@@ -3,6 +3,7 @@ package de.tobias.playwall.service; ...@@ -3,6 +3,7 @@ package de.tobias.playwall.service;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import de.tobias.playwall.infrastructure.ArtifactoryConfigurationProperties; import de.tobias.playwall.infrastructure.ArtifactoryConfigurationProperties;
import de.tobias.playwall.model.Plugin;
import de.tobias.playwall.model.PluginDescription; import de.tobias.playwall.model.PluginDescription;
import de.tobias.playwall.model.PluginManifest; import de.tobias.playwall.model.PluginManifest;
import de.tobias.playwall.model.artifactory.Folder; import de.tobias.playwall.model.artifactory.Folder;
...@@ -13,6 +14,7 @@ import lombok.SneakyThrows; ...@@ -13,6 +14,7 @@ import lombok.SneakyThrows;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.client.WebClient; import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Mono;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
...@@ -89,4 +91,19 @@ public class ArtifactoryClient ...@@ -89,4 +91,19 @@ public class ArtifactoryClient
} }
return mapper.readValue(response.getBody().source(), PluginManifest.class); return mapper.readValue(response.getBody().source(), PluginManifest.class);
} }
public Mono<byte[]> downloadArtifact(Plugin plugin)
{
return webClient.get()
.uri("/artifactory/%s/%s/%s/%s/%s-%s.jar".formatted(
configurationProperties.getRepository(),
configurationProperties.getGroupId().replace(".", "/"),
plugin.getName(),
plugin.getVersion(),
plugin.getName(),
plugin.getVersion()
))
.retrieve()
.bodyToMono(byte[].class);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment