gitscope
← marzneshin / v0.1.3 / app/marznode/database.py
https://dev.kronoz.win/r/marzneshin.git
app/marznode/database.py · Python
Blame Raw
 1from app.db import crud, GetDB
 2from app.models.node import NodeStatus
 3from app.models.user import UserStatus
 4
 5
 6class MarzNodeDB:
 7    def list_users(self):
 8        with GetDB() as db:
 9            relations = crud.get_node_users(db, self.id, [UserStatus.active, UserStatus.on_hold])
10            users = dict()
11            for rel in relations:
12                if not users.get(rel[0]):
13                    users[rel[0]] = dict(username=rel[1], id=rel[0], key=rel[2], inbounds=[])
14                users[rel[0]]["inbounds"].append(rel[3].tag)
15        return list(users.values())
16
17    def store_inbounds(self, inbounds):
18        with GetDB() as db:
19            crud.assure_node_inbounds(db, inbounds, self.id)
20
21    def set_status(self, status: NodeStatus, message: str | None = None):
22        with GetDB() as db:
23            crud.update_node_status(db, self.id, status, message)