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