Skip to content

Commit

Permalink
合并接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Dec 1, 2024
1 parent 517b1d3 commit 75863fa
Showing 1 changed file with 3 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public void onEnable() {
.put("/api/push", this::handlePushProviderPut, Role.USER_WRITE)
.patch("/api/push/{pushName}", ctx -> handlePushProviderPatch(ctx, ctx.pathParam("pushName")), Role.USER_WRITE)
.post("/api/push/test", this::handlePushProviderTest, Role.USER_WRITE)
.delete("/api/push/{pushName}", ctx -> handlePushProviderDelete(ctx, ctx.pathParam("pushName")), Role.USER_WRITE)
.get("/api/push/{pushName}/status", ctx -> handlePushProviderStatus(ctx, ctx.pathParam("pushName")), Role.USER_READ);
.delete("/api/push/{pushName}", ctx -> handlePushProviderDelete(ctx, ctx.pathParam("pushName")), Role.USER_WRITE);
}


Expand Down Expand Up @@ -164,23 +163,9 @@ private void handlePushProviderDelete(Context ctx, String pushProviderName) {
}
}

private void handlePushProviderStatus(@NotNull Context ctx, String pushProviderName) {
Optional<PushProvider> selected = pushManager.getProviderList().stream()
.filter(d -> d.getName().equals(pushProviderName))
.findFirst();
if (selected.isEmpty()) {
ctx.status(HttpStatus.NOT_FOUND);
ctx.json(new StdResp(false, tl(locale(ctx), Lang.PUSH_PROVIDER_API_PROVIDER_NOT_EXISTS), null));
return;
}
PushProvider pushProvider = selected.get();
JsonObject config = pushProvider.saveJson();
ctx.json(new StdResp(true, null, new PushStatusWrapper(config)));
}

private void handlePushProviderList(@NotNull Context ctx) {
List<PushWrapper> pushProviders = pushManager.getProviderList()
.stream().map(d -> new PushWrapper(d.getName(), d.getConfigType()))
.stream().map(d -> new PushWrapper(d.getName(), d.getConfigType(), d.saveJson()))
.toList();
ctx.json(new StdResp(true, null, pushProviders));
}
Expand All @@ -191,8 +176,6 @@ public void onDisable() {

}

record PushWrapper(String name, String type) {
}
record PushStatusWrapper(JsonObject config) {
record PushWrapper(String name, String type, JsonObject config) {
}
}

0 comments on commit 75863fa

Please sign in to comment.