Implement creating relays via the API

This commit is contained in:
Mark Veidemanis 2022-07-29 17:27:40 +01:00
parent 33466b90ba
commit 1ca6d79868
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 16 additions and 1 deletions

View File

@ -294,6 +294,21 @@ class API(object):
main.saveConf("network") main.saveConf("network")
return dumps({"success": True}) return dumps({"success": True})
@app.route("/irc/network/<net>/<num>/", methods=["PUT"])
@login_required
def irc_network_relay_add(self, request, net, num):
if net not in main.network.keys():
return dumps({"success": False, "reason": "no such net."})
if not num.isdigit():
return dumps({"success": False, "reason": "invalid num: not a number."})
num = int(num)
net_inst = main.network[net]
if num in net_inst.relays:
return dumps({"success": False, "reason": "network already has this relay."})
id, alias = net_inst.add_relay()
main.saveConf("network")
return dumps({"success": True, "id": id, "alias": alias})
@app.route("/irc/network/<net>/channels/", methods=["POST"]) @app.route("/irc/network/<net>/channels/", methods=["POST"])
@login_required @login_required
def irc_network_channels(self, request, net): def irc_network_channels(self, request, net):
@ -328,7 +343,7 @@ class API(object):
return dumps({"success": False, "reason": "no such net."}) return dumps({"success": False, "reason": "no such net."})
joined = chankeep.joinSingle(net, channel) joined = chankeep.joinSingle(net, channel)
if not joined: if not joined:
dumps({"success": False, "reason": "no channels joined."}) return dumps({"success": False, "reason": "could not allocate channel to relay."})
return dumps({"success": True, "relays": joined}) return dumps({"success": True, "relays": joined})
@app.route("/aliases/", methods=["GET"]) @app.route("/aliases/", methods=["GET"])