Use JSON for joining channels and don't shadow auth variable when getting network info

This commit is contained in:
Mark Veidemanis 2022-08-14 09:25:01 +01:00
parent 713e03b66e
commit 128e005611
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
1 changed files with 22 additions and 5 deletions

View File

@ -325,15 +325,14 @@ class API(object):
to_append["nick"] = main.IRCPool[name].nickname to_append["nick"] = main.IRCPool[name].nickname
to_append["conn"] = main.IRCPool[name].isconnected to_append["conn"] = main.IRCPool[name].isconnected
to_append["limit"] = main.IRCPool[name].chanlimit to_append["limit"] = main.IRCPool[name].chanlimit
to_append["auth"] = main.IRCPool[name].authenticated to_append["authed"] = main.IRCPool[name].authenticated
else: else:
to_append["chans"] = 0 to_append["chans"] = 0
to_append["nick"] = None to_append["nick"] = None
to_append["conn"] = False to_append["conn"] = False
to_append["limit"] = None to_append["limit"] = None
to_append["auth"] = None to_append["authed"] = None
relays.append(to_append) relays.append(to_append)
return dumps({"relays": relays}) return dumps({"relays": relays})
@app.route("/irc/network/<net>/<num>/", methods=["POST"]) @app.route("/irc/network/<net>/<num>/", methods=["POST"])
@ -435,9 +434,10 @@ class API(object):
return dumps({"channels": channels}) return dumps({"channels": channels})
# API version
@app.route("/irc/network/<net>/channel/", methods=["DELETE"]) @app.route("/irc/network/<net>/channel/", methods=["DELETE"])
@login_required @login_required
def irc_network_channel_part(self, request, net): def irc_network_channel_part_api(self, request, net):
try: try:
data = loads(request.content.read()) data = loads(request.content.read())
except JSONDecodeError: except JSONDecodeError:
@ -447,12 +447,29 @@ class API(object):
channel = data["channel"] channel = data["channel"]
if net not in main.network.keys(): if net not in main.network.keys():
return dumps({"success": False, "reason": "no such net."}) return dumps({"success": False, "reason": "no such net."})
print("ABOUT TO PART", channel)
parted = chankeep.partSingle(net, channel) parted = chankeep.partSingle(net, channel)
if not parted: if not parted:
dumps({"success": False, "reason": "no channels matched."}) dumps({"success": False, "reason": "no channels matched."})
return dumps({"success": True, "relays": parted}) return dumps({"success": True, "relays": parted})
# API version
@app.route("/irc/network/<net>/channel/", methods=["PUT"])
@login_required
def irc_network_channel_join_api(self, request, net):
try:
data = loads(request.content.read())
except JSONDecodeError:
return "Invalid JSON"
if "channel" not in data:
return dumps({"success": False, "reason": "no channel specified."})
channel = data["channel"]
if net not in main.network.keys():
return dumps({"success": False, "reason": "no such net."})
joined = chankeep.joinSingle(net, channel)
if not joined:
return dumps({"success": False, "reason": "could not allocate channel to relay."})
return dumps({"success": True, "relays": joined})
@app.route("/irc/network/<net>/channel/<channel>/", methods=["PUT"]) @app.route("/irc/network/<net>/channel/<channel>/", methods=["PUT"])
@login_required @login_required
def irc_network_channel_join(self, request, net, channel): def irc_network_channel_join(self, request, net, channel):