Added libs
This commit is contained in:
51
noSys/networksApiBlueprint.py
Normal file
51
noSys/networksApiBlueprint.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from flask import Blueprint, make_response, request, jsonify, abort
|
||||
from flask_socketio import SocketIO, emit, join_room, leave_room
|
||||
|
||||
import os, signal, json, time
|
||||
import logging
|
||||
from threading import Thread
|
||||
|
||||
from libs.api.apiBlueprint import ApiBlueprint
|
||||
|
||||
class Blueprint(ApiBlueprint):
|
||||
def routes(self):
|
||||
from .networks import Networks
|
||||
self.module:Networks = self.module
|
||||
|
||||
@self.blueprint.route('/')
|
||||
def show():
|
||||
return self.module.name
|
||||
|
||||
@self.blueprint.route('/networks')
|
||||
def networks():
|
||||
if request.method == "GET":
|
||||
networks = []
|
||||
for network_id, state in self.module.network_states.items():
|
||||
obj = {"data":self.module.nosys_core.data.get_network(network_id), "state":state}
|
||||
networks.append(obj)
|
||||
return jsonify(networks)
|
||||
|
||||
elif request.method == "POST":
|
||||
content:dict = request.json
|
||||
user_id = content["user_id"]
|
||||
network_id = content["network_id"]
|
||||
self.module.user_add_network(user_id, network_id)
|
||||
|
||||
return jsonify({"network_id":network_id})
|
||||
|
||||
@self.blueprint.route("/networks/<path:network_id>", methods=["GET", "PUT", "DELETE"])
|
||||
def network(network_id):
|
||||
state = self.module.network_states.get(network_id)
|
||||
if request.method == "GET":
|
||||
return jsonify(state)
|
||||
|
||||
elif request.method == "PUT":
|
||||
# TODO Edit network config
|
||||
return jsonify({"networkId":network_id})
|
||||
|
||||
elif request.method == "DELETE":
|
||||
content:dict = request.json
|
||||
user_id = content["user_id"]
|
||||
self.module.user_remove_network(user_id, network_id)
|
||||
return jsonify({"networkId":network_id})
|
||||
|
||||
Reference in New Issue
Block a user