Spaces:
Paused
Paused
Update admin_routes.py
Browse files- admin_routes.py +106 -54
admin_routes.py
CHANGED
|
@@ -421,6 +421,34 @@ async def change_password(
|
|
| 421 |
log(f"✅ Password changed for user '{username}'")
|
| 422 |
return {"success": True}
|
| 423 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
# ===================== Environment Endpoints =====================
|
| 425 |
@router.get("/environment")
|
| 426 |
async def get_environment(username: str = Depends(verify_token)):
|
|
@@ -587,74 +615,98 @@ async def get_project(
|
|
| 587 |
# POST /api/projects
|
| 588 |
@router.post("/projects")
|
| 589 |
async def create_project(
|
| 590 |
-
|
| 591 |
username: str = Depends(verify_token)
|
| 592 |
):
|
| 593 |
-
|
|
|
|
| 594 |
|
| 595 |
-
#
|
| 596 |
-
|
| 597 |
-
|
|
|
|
| 598 |
|
| 599 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 600 |
new_project = {
|
| 601 |
"id": project_id,
|
| 602 |
-
"name":
|
| 603 |
-
"caption":
|
| 604 |
-
"icon":
|
| 605 |
-
"description":
|
| 606 |
-
"default_language":
|
| 607 |
-
"supported_languages":
|
| 608 |
-
"timezone":
|
| 609 |
-
"region":
|
| 610 |
-
"enabled":
|
| 611 |
"deleted": False,
|
| 612 |
-
"
|
|
|
|
|
|
|
| 613 |
"created_by": username,
|
| 614 |
-
"last_update_date":
|
| 615 |
"last_update_user": username,
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
|
|
|
|
|
|
| 635 |
},
|
| 636 |
-
"
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
"intents": [],
|
| 640 |
-
"parameters": [],
|
| 641 |
-
"created_date": datetime.utcnow().isoformat(),
|
| 642 |
-
"created_by": username,
|
| 643 |
-
"last_update_date": datetime.utcnow().isoformat(),
|
| 644 |
-
"last_update_user": username,
|
| 645 |
-
"deleted": False,
|
| 646 |
-
"publish_date": None,
|
| 647 |
-
"published_by": None
|
| 648 |
-
}]
|
| 649 |
}
|
| 650 |
|
| 651 |
-
|
| 652 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 653 |
|
| 654 |
-
|
| 655 |
-
|
| 656 |
-
save_config(cfg)
|
| 657 |
|
|
|
|
| 658 |
return new_project
|
| 659 |
|
| 660 |
@router.put("/projects/{project_id}")
|
|
|
|
| 421 |
log(f"✅ Password changed for user '{username}'")
|
| 422 |
return {"success": True}
|
| 423 |
|
| 424 |
+
# ===================== Locales Endpoints =====================
|
| 425 |
+
@router.get("/locales")
|
| 426 |
+
async def get_available_locales(username: str = Depends(verify_token)):
|
| 427 |
+
"""Get all system-supported locales"""
|
| 428 |
+
from locale_manager import LocaleManager
|
| 429 |
+
|
| 430 |
+
locales = LocaleManager.get_available_locales_with_names()
|
| 431 |
+
|
| 432 |
+
return {
|
| 433 |
+
"locales": locales,
|
| 434 |
+
"default": LocaleManager.get_default_locale()
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
@router.get("/locales/{locale_code}")
|
| 438 |
+
async def get_locale_details(
|
| 439 |
+
locale_code: str,
|
| 440 |
+
username: str = Depends(verify_token)
|
| 441 |
+
):
|
| 442 |
+
"""Get detailed information for a specific locale"""
|
| 443 |
+
from locale_manager import LocaleManager
|
| 444 |
+
|
| 445 |
+
locale_info = LocaleManager.get_locale_details(locale_code)
|
| 446 |
+
|
| 447 |
+
if not locale_info:
|
| 448 |
+
raise HTTPException(status_code=404, detail=f"Locale '{locale_code}' not found")
|
| 449 |
+
|
| 450 |
+
return locale_info
|
| 451 |
+
|
| 452 |
# ===================== Environment Endpoints =====================
|
| 453 |
@router.get("/environment")
|
| 454 |
async def get_environment(username: str = Depends(verify_token)):
|
|
|
|
| 615 |
# POST /api/projects
|
| 616 |
@router.post("/projects")
|
| 617 |
async def create_project(
|
| 618 |
+
project: ProjectCreate,
|
| 619 |
username: str = Depends(verify_token)
|
| 620 |
):
|
| 621 |
+
"""Create new project with initial version"""
|
| 622 |
+
config = load_config()
|
| 623 |
|
| 624 |
+
# Validate project name
|
| 625 |
+
existing_names = [p["name"].lower() for p in config.get("projects", []) if not p.get("deleted", False)]
|
| 626 |
+
if project.name.lower() in existing_names:
|
| 627 |
+
raise HTTPException(status_code=400, detail="Project name already exists")
|
| 628 |
|
| 629 |
+
# Validate supported languages
|
| 630 |
+
from locale_manager import LocaleManager
|
| 631 |
+
|
| 632 |
+
invalid_languages = LocaleManager.validate_project_languages(project.supported_languages)
|
| 633 |
+
if invalid_languages:
|
| 634 |
+
available_locales = LocaleManager.get_available_locales_with_names()
|
| 635 |
+
available_codes = [locale['code'] for locale in available_locales]
|
| 636 |
+
raise HTTPException(
|
| 637 |
+
status_code=400,
|
| 638 |
+
detail=f"Unsupported languages: {', '.join(invalid_languages)}. Available languages: {', '.join(available_codes)}"
|
| 639 |
+
)
|
| 640 |
+
|
| 641 |
+
# Check if default language is in supported languages
|
| 642 |
+
if project.default_language not in project.supported_languages:
|
| 643 |
+
raise HTTPException(
|
| 644 |
+
status_code=400,
|
| 645 |
+
detail="Default language must be one of the supported languages"
|
| 646 |
+
)
|
| 647 |
+
|
| 648 |
+
# Get new project ID
|
| 649 |
+
project_id = config.get("project_id_counter", 1)
|
| 650 |
+
config["project_id_counter"] = project_id + 1
|
| 651 |
+
|
| 652 |
+
# Create project with version
|
| 653 |
new_project = {
|
| 654 |
"id": project_id,
|
| 655 |
+
"name": project.name,
|
| 656 |
+
"caption": project.caption,
|
| 657 |
+
"icon": project.icon,
|
| 658 |
+
"description": project.description,
|
| 659 |
+
"default_language": project.default_language,
|
| 660 |
+
"supported_languages": project.supported_languages,
|
| 661 |
+
"timezone": project.timezone,
|
| 662 |
+
"region": project.region,
|
| 663 |
+
"enabled": True,
|
| 664 |
"deleted": False,
|
| 665 |
+
"version_id_counter": 2, # Start from 2 since we create version 1
|
| 666 |
+
"last_version_number": 1,
|
| 667 |
+
"created_date": get_timestamp(),
|
| 668 |
"created_by": username,
|
| 669 |
+
"last_update_date": get_timestamp(),
|
| 670 |
"last_update_user": username,
|
| 671 |
+
"versions": [
|
| 672 |
+
{
|
| 673 |
+
"id": 1,
|
| 674 |
+
"no": 1,
|
| 675 |
+
"caption": "Version 1",
|
| 676 |
+
"published": False,
|
| 677 |
+
"created_date": get_timestamp(),
|
| 678 |
+
"created_by": username,
|
| 679 |
+
"last_update_date": get_timestamp(),
|
| 680 |
+
"last_update_user": username,
|
| 681 |
+
"general_prompt": "",
|
| 682 |
+
"llm": {
|
| 683 |
+
"repo_id": "Qwen/Qwen2.5-72B-Instruct",
|
| 684 |
+
"generation_config": {
|
| 685 |
+
"temperature": 0.5,
|
| 686 |
+
"max_tokens": 2048,
|
| 687 |
+
"top_p": 0.7,
|
| 688 |
+
"repetition_penalty": 1.1
|
| 689 |
+
},
|
| 690 |
+
"use_fine_tune": False,
|
| 691 |
+
"fine_tune_zip": ""
|
| 692 |
},
|
| 693 |
+
"intents": []
|
| 694 |
+
}
|
| 695 |
+
]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 696 |
}
|
| 697 |
|
| 698 |
+
# Add to config
|
| 699 |
+
if "projects" not in config:
|
| 700 |
+
config["projects"] = []
|
| 701 |
+
config["projects"].append(new_project)
|
| 702 |
+
|
| 703 |
+
# Add activity log
|
| 704 |
+
add_activity_log(config, username, "CREATE_PROJECT", "project", project_id, project.name)
|
| 705 |
|
| 706 |
+
# Save
|
| 707 |
+
save_config(config)
|
|
|
|
| 708 |
|
| 709 |
+
log(f"✅ Project '{project.name}' created by {username}")
|
| 710 |
return new_project
|
| 711 |
|
| 712 |
@router.put("/projects/{project_id}")
|