Skip to content

Commit 1456f71

Browse files
author
TechsCode
committed
Improved logging of WebRequestsHandler
1 parent 1e66b75 commit 1456f71

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/main/java/me/TechsCode/ReleaseServer/WebRequestsHandler.java

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010
import java.io.File;
1111
import java.net.MalformedURLException;
12+
import java.util.List;
1213
import java.util.Optional;
14+
import java.util.stream.Collectors;
1315

1416
@RestController
1517
public class WebRequestsHandler {
@@ -20,7 +22,7 @@ public String index() {
2022
}
2123

2224
@GetMapping("/download/{project}/{tag}")
23-
public Object download(@RequestParam(value = "token") String token, @PathVariable(value = "project") String project, @PathVariable(value = "tag") String tag){
25+
public Object download(@RequestParam(value = "token", required = false) String token, @PathVariable(value = "project") String project, @PathVariable(value = "tag") String tag){
2426
if(token == null){
2527
return "You dont have any token provided!";
2628
}
@@ -29,10 +31,16 @@ public Object download(@RequestParam(value = "token") String token, @PathVariabl
2931
return "The token you have provided is invalid!";
3032
}
3133

32-
Optional<Artifact> artifact = ReleaseServer.getArtifacts().stream()
34+
List<Artifact> artifactsOfProject = ReleaseServer.getArtifacts().stream()
3335
.filter(x -> x.getRelease().getProject().getName().equalsIgnoreCase(project))
34-
.filter(x -> x.getRelease().getUniqueTag().equals(tag))
35-
.findFirst();
36+
.collect(Collectors.toList());
37+
38+
if(artifactsOfProject.size() == 0){
39+
return "Could not find any artifact for project '"+project+"'";
40+
}
41+
42+
Optional<Artifact> artifact = artifactsOfProject.stream()
43+
.filter(x -> x.getReleaseTag().equals(tag)).findFirst();
3644

3745
if(artifact.isPresent()){
3846
if(artifact.get().getAssets().length == 0){
@@ -55,7 +63,7 @@ public Object download(@RequestParam(value = "token") String token, @PathVariabl
5563
return "Error: "+e.getMessage();
5664
}
5765
} else {
58-
return "Could not find any artifact";
66+
return "Could not find any artifact with the tag '"+tag+"'";
5967
}
6068
}
6169
}

0 commit comments

Comments
 (0)