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