| 1495 | |
| 1496 | |
| 1497 | class ConfigService: |
| 1498 | INT_FIELDS = { |
| 1499 | "enableChunk", |
| 1500 | "errorCount", |
| 1501 | "errorMinute", |
| 1502 | "max_save_seconds", |
| 1503 | "onedrive_proxy", |
| 1504 | "openUpload", |
| 1505 | "port", |
| 1506 | "s3_proxy", |
| 1507 | "serverPort", |
| 1508 | "serverWorkers", |
| 1509 | "showAdminAddr", |
| 1510 | "uploadCount", |
| 1511 | "uploadMinute", |
| 1512 | "uploadSize", |
| 1513 | "webdav_proxy", |
| 1514 | } |
| 1515 | FLOAT_FIELDS = {"opacity"} |
| 1516 | |
| 1517 | def get_config(self): |
| 1518 | config = dict(settings.items()) |
| 1519 | config["admin_token"] = "" |
| 1520 | for key in INTERNAL_CONFIG_KEYS: |
| 1521 | config.pop(key, None) |
| 1522 | return config |
| 1523 | |
| 1524 | async def update_config(self, data: dict): |
| 1525 | current_config = dict(settings.items()) |
| 1526 | next_config = dict(current_config) |
| 1527 | update_data = { |
| 1528 | key: value |
| 1529 | for key, value in data.items() |
| 1530 | if key in settings.default_config and key not in INTERNAL_CONFIG_KEYS |
| 1531 | } |
| 1532 | |
| 1533 | admin_token = update_data.get("admin_token") |
| 1534 | admin_password_changed = False |
| 1535 | if admin_token is None or admin_token == "": |
| 1536 | update_data.pop("admin_token", None) |
| 1537 | elif not is_password_hashed(admin_token): |
| 1538 | update_data["admin_token"] = hash_password(admin_token) |
| 1539 | admin_password_changed = True |
| 1540 | else: |
| 1541 | admin_password_changed = True |
| 1542 | |
| 1543 | for key, value in update_data.items(): |
| 1544 | if value == "" and key in self.INT_FIELDS | self.FLOAT_FIELDS: |
| 1545 | continue |
| 1546 | |
| 1547 | try: |
| 1548 | if key in self.INT_FIELDS: |
| 1549 | next_config[key] = int(value) |
| 1550 | elif key in self.FLOAT_FIELDS: |
| 1551 | next_config[key] = float(value) |
| 1552 | else: |
| 1553 | next_config[key] = value |
| 1554 | except (TypeError, ValueError): |
no outgoing calls