提交 0f854169 authored 作者: yangli's avatar yangli

.

上级 b67312f9
......@@ -54,6 +54,8 @@ public class ProgramController {
private static List<Map<String, String>> programList;
private static final double MIN_MATCH = 0.5;
@GetMapping(value = "{type}/list")
public R<Page<Map<String, String>>> list(@PathVariable @Pattern(regexp = "install|upgrade") String type,
@RequestParam(required = false, defaultValue = "1") Integer current,
......@@ -83,7 +85,7 @@ public class ProgramController {
.entrySet()
.stream()
.max(Map.Entry.comparingByKey())
.filter(e -> e.getKey() >= 0.5)
.filter(e -> e.getKey() >= MIN_MATCH)
.ifPresent(e -> m.put("localVersion", e.getValue())))
.collect(Collectors.toList());
return R.success(page.setRecords(list));
......@@ -124,6 +126,21 @@ public class ProgramController {
}
}
@GetMapping(value = "get_version")
public R<String> getVersion(@RequestParam @NotBlank String name) throws IOException {
if (programList == null) loadProgramListJob();
return programList.stream()
.collect(Collectors.toMap(p -> StrUtil.similar(p.get("name").toLowerCase(), name.toLowerCase()),
p -> p.get("version"), (l, r) -> r))
.entrySet()
.stream()
.max(Map.Entry.comparingByKey())
.filter(e -> e.getKey() >= MIN_MATCH)
.map(Map.Entry::getValue)
.map(R::success)
.orElseGet(R::success);
}
@Scheduled(fixedDelay = 3000)
protected void loadProgramListJob() throws IOException {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论