Skip to content

Commit

Permalink
editable 接口
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghost-chu committed Nov 21, 2024
1 parent df8f0d2 commit ad3cff4
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,20 @@ public void onEnable() {
}
javalinWebContainer.javalin()
.get("/api/" + getConfigName() + "/scripts", this::listScripts, Role.USER_READ)
.get("/api/"+getConfigName()+"/editable", this::editable, Role.USER_READ)
.get("/api/" + getConfigName() + "/{scriptId}", this::readScript, Role.USER_READ)
.put("/api/" + getConfigName() + "/{scriptId}", this::writeScript, Role.USER_WRITE)
.delete("/api/" + getConfigName() + "/{scriptId}", this::deleteScript, Role.USER_WRITE);
}

private void editable(Context context) {
Map<String, Object> map = new HashMap<>();
var editable = isSafeNetworkEnvironment(context);
map.put("editable", editable);
map.put("reason", editable ? null : tl(locale(context), Lang.EXPRESS_RULE_ENGINE_DISALLOW_UNSAFE_SOURCE_ACCESS, context.ip()));
context.json(new StdResp(true, null, map));
}

private void deleteScript(Context context) throws IOException {
if (!isSafeNetworkEnvironment(context)) {
context.status(HttpStatus.FORBIDDEN);
Expand Down

0 comments on commit ad3cff4

Please sign in to comment.