Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
08d326dc1f | ||
|
|
79400146ea | ||
|
|
503b3bf078 | ||
|
|
7f8947f070 | ||
|
|
6dca9b08cc | ||
|
|
06034cf46e | ||
|
|
24e59f18d0 | ||
|
|
f468fe270f | ||
|
|
4cc8b87de5 |
No files matched your search
+1
-1
@@ -9,7 +9,7 @@
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
/pnpm-lock.yaml
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {
|
||||
reactStrictMode: false,
|
||||
// Enable SSR
|
||||
output: "standalone",
|
||||
|
||||
// Optimize images
|
||||
images: {
|
||||
domains: [],
|
||||
unoptimized: false, // Enable image optimization for SSR
|
||||
},
|
||||
|
||||
// Webpack configuration
|
||||
webpack: (config) => {
|
||||
return config;
|
||||
},
|
||||
|
||||
// Redirect configuration
|
||||
async redirects() {
|
||||
return [];
|
||||
},
|
||||
async rewrites() {
|
||||
return [
|
||||
// {
|
||||
// source: "/api/:path*",
|
||||
// destination: `${process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"}/api/:path*`,
|
||||
// },
|
||||
{
|
||||
source: "/uploads/:path*",
|
||||
destination: `${
|
||||
process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"
|
||||
}/uploads/:path*`,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
// Headers for better performance
|
||||
async headers() {
|
||||
return [
|
||||
{
|
||||
source: "/(.*)",
|
||||
headers: [
|
||||
{
|
||||
key: "X-Content-Type-Options",
|
||||
value: "nosniff",
|
||||
},
|
||||
{
|
||||
key: "X-XSS-Protection",
|
||||
value: "1; mode=block",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = nextConfig;
|
||||
@@ -1,10 +1,15 @@
|
||||
import type { NextConfig } from "next";
|
||||
|
||||
const nextConfig: NextConfig = {
|
||||
reactStrictMode: false,
|
||||
output: "standalone",
|
||||
|
||||
experimental: {
|
||||
optimizePackageImports: ["@nextui-org/react"],
|
||||
},
|
||||
|
||||
transpilePackages: ["@nextui-org/react", "@nextui-org/theme"],
|
||||
|
||||
images: {
|
||||
remotePatterns: [
|
||||
{
|
||||
@@ -12,6 +17,42 @@ const nextConfig: NextConfig = {
|
||||
hostname: "**",
|
||||
},
|
||||
],
|
||||
unoptimized: false,
|
||||
},
|
||||
|
||||
// Redirect configuration
|
||||
async redirects() {
|
||||
return [];
|
||||
},
|
||||
|
||||
async rewrites() {
|
||||
return [
|
||||
{
|
||||
source: "/uploads/:path*",
|
||||
destination: `${
|
||||
process.env.NEXT_PUBLIC_API_URL || "http://127.0.0.1:8001"
|
||||
}/uploads/:path*`,
|
||||
},
|
||||
];
|
||||
},
|
||||
|
||||
// Headers for better performance
|
||||
async headers() {
|
||||
return [
|
||||
{
|
||||
source: "/(.*)",
|
||||
headers: [
|
||||
{
|
||||
key: "X-Content-Type-Options",
|
||||
value: "nosniff",
|
||||
},
|
||||
{
|
||||
key: "X-XSS-Protection",
|
||||
value: "1; mode=block",
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
"immer": "^10.0.3",
|
||||
"lottie-react": "^2.4.1",
|
||||
"lucide-react": "^0.475.0",
|
||||
"next": "^15.5.9",
|
||||
"next": "^16.1.5",
|
||||
"react": "^19.1.4",
|
||||
"react-dom": "^19.1.4",
|
||||
"react-hook-form": "^7.49.3",
|
||||
@@ -55,7 +55,7 @@
|
||||
"@types/three": "^0.177.0",
|
||||
"autoprefixer": "^10.4.17",
|
||||
"eslint": "^8.56.0",
|
||||
"eslint-config-next": "15.5.9",
|
||||
"eslint-config-next": "16.1.5",
|
||||
"postcss": "^8.4.33",
|
||||
"tailwindcss": "^3.4.17",
|
||||
"typescript": "^5.3.3"
|
||||
|
||||
Generated
-18565
File diff suppressed because it is too large.
Load diff
@@ -12,7 +12,7 @@ export async function revalidatePlatformConfig() {
|
||||
revalidatePath("/", "layout");
|
||||
|
||||
// Revalidate host-specific cache tag
|
||||
revalidateTag(`platform-config-${host}`);
|
||||
revalidateTag(`platform-config-${host}`, 'max');
|
||||
|
||||
console.info(
|
||||
`Platform config cache revalidated for host: platform-config-${host}`
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
input::placeholder,
|
||||
textarea::placeholder {
|
||||
--nextui-foreground-500: 240 5.03% 64.9%;
|
||||
}
|
||||
/* Import theme styles */
|
||||
@import "../styles/themes.css";
|
||||
|
||||
@tailwind base;
|
||||
@tailwind components;
|
||||
@tailwind utilities;
|
||||
|
||||
/* Import theme styles */
|
||||
@import "../styles/themes.css";
|
||||
input::placeholder,
|
||||
textarea::placeholder {
|
||||
--nextui-foreground-500: 240 5.03% 64.9%;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
|
||||
+19
-5
@@ -1,7 +1,11 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2017",
|
||||
"lib": ["dom", "dom.iterable", "esnext"],
|
||||
"lib": [
|
||||
"dom",
|
||||
"dom.iterable",
|
||||
"esnext"
|
||||
],
|
||||
"allowJs": true,
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
@@ -11,7 +15,7 @@
|
||||
"moduleResolution": "bundler",
|
||||
"resolveJsonModule": true,
|
||||
"isolatedModules": true,
|
||||
"jsx": "preserve",
|
||||
"jsx": "react-jsx",
|
||||
"incremental": true,
|
||||
"plugins": [
|
||||
{
|
||||
@@ -19,9 +23,19 @@
|
||||
}
|
||||
],
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
"@/*": [
|
||||
"./src/*"
|
||||
]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
"include": [
|
||||
"next-env.d.ts",
|
||||
"**/*.ts",
|
||||
"**/*.tsx",
|
||||
".next/types/**/*.ts",
|
||||
".next/dev/types/**/*.ts"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"version": "v1.2",
|
||||
"releaseDate": "2025-12-22",
|
||||
"version": "v1.4",
|
||||
"releaseDate": "2026-02-23",
|
||||
"description": "This is the latest release of the application.",
|
||||
"downloads": {
|
||||
"program": {
|
||||
"xpack_mcp_market": {
|
||||
"version": "v1.2.1",
|
||||
"version": "v1.4.1",
|
||||
"docker": "xpackai/xpack-mcp-market",
|
||||
"tar": "xpack-mcp-market.tar.gz",
|
||||
"url": "https://public.eolinker.com/xpack/images/xpack-mcp-market.${VERSION}.${ARCH}.tar.gz"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy import func
|
||||
from datetime import datetime, date
|
||||
@@ -7,6 +7,10 @@ from yarl import Query
|
||||
from services.common.database import get_db
|
||||
from services.common.utils.response_utils import ResponseUtils
|
||||
from services.admin_service.services.stats_service import StatsService
|
||||
from services.admin_service.utils.user_utils import UserUtils
|
||||
from services.common import error_msg
|
||||
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -15,10 +19,13 @@ def get_stats_service(db: Session = Depends(get_db)) -> StatsService:
|
||||
|
||||
@router.get("/stats/analytics")
|
||||
async def stats(
|
||||
request: Request,
|
||||
start: int= 0,
|
||||
end: int=0,
|
||||
stats_service: StatsService = Depends(get_stats_service)
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
if end == 0:
|
||||
end = int(datetime.now().timestamp())
|
||||
if start == 0:
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
# Read config from sys_config table, key is configured in services/admin_service/constants/sys_config_key.py
|
||||
|
||||
import logging
|
||||
from fastapi import APIRouter, Depends
|
||||
from fastapi import APIRouter, Depends, Request
|
||||
import json
|
||||
from sqlalchemy.orm import Session
|
||||
from services.common.database import get_db
|
||||
from services.common.utils.response_utils import ResponseUtils
|
||||
from services.admin_service.utils.user_utils import UserUtils
|
||||
from services.common import error_msg
|
||||
from services.admin_service.services.sys_config_service import SysConfigService
|
||||
from services.admin_service.constants.sys_config_key import *
|
||||
from services.admin_service.services.payment_channel_service import PaymentChannelService
|
||||
@@ -16,9 +18,12 @@ router = APIRouter()
|
||||
|
||||
@router.get("/config", summary="Get configuration (no login required)", tags=["common"])
|
||||
def get_config(
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Get platform configuration settings without authentication."""
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
try:
|
||||
# Create service instance
|
||||
sys_config_service = SysConfigService(db)
|
||||
@@ -81,8 +86,13 @@ def get_config(
|
||||
return ResponseUtils.error(message="Failed to get configuration")
|
||||
|
||||
@router.get("/homepage", summary="Get homepage configuration (no login required)", tags=["common"])
|
||||
def get_homepage_config(db: Session = Depends(get_db)):
|
||||
def get_homepage_config(
|
||||
request: Request,
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
"""Get homepage configuration settings without authentication."""
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
try:
|
||||
# Create service instance
|
||||
sys_config_service = SysConfigService(db)
|
||||
|
||||
@@ -90,7 +90,9 @@ def update_mcp_service_info(request: Request, body: dict = Body(...), mcp_manage
|
||||
|
||||
|
||||
@router.delete("/service", summary="Delete MCP service")
|
||||
def delete_mcp_service(body: dict = Body(...), mcp_manager_service: McpManagerService = Depends(get_mcp_manager)):
|
||||
def delete_mcp_service(request: Request, body: dict = Body(...), mcp_manager_service: McpManagerService = Depends(get_mcp_manager)):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
"""Delete MCP service by ID."""
|
||||
id = body.get("id")
|
||||
if not id:
|
||||
@@ -102,11 +104,14 @@ def delete_mcp_service(body: dict = Body(...), mcp_manager_service: McpManagerSe
|
||||
|
||||
@router.post("/openapi_parse", summary="openapi import", response_model=dict)
|
||||
async def openapi_parse(
|
||||
request: Request,
|
||||
url: Optional[HttpUrl] = Form(None, description="OpenAPI document URL (optional)"),
|
||||
file: Optional[UploadFile] = File(None, description="OpenAPI document file (JSON/YAML, optional)"),
|
||||
mcp_manager_service: McpManagerService = Depends(get_mcp_manager),
|
||||
):
|
||||
"""Parse and import OpenAPI document from URL or file upload."""
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
try:
|
||||
if url:
|
||||
url_str = str(url)
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
from os import stat
|
||||
from typing import Optional, List
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from services.common.models.user_wallet_history import TransactionType
|
||||
from fastapi import APIRouter, Depends, Query, Request
|
||||
from sqlalchemy import table
|
||||
from sqlalchemy.orm import Session
|
||||
from services.common.database import get_db
|
||||
from services.common.utils.response_utils import ResponseUtils
|
||||
from services.admin_service.services.user_service import UserService
|
||||
from services.admin_service.services.user_wallet_history_service import UserWalletHistoryService
|
||||
from services.admin_service.utils.user_utils import UserUtils
|
||||
from services.common import error_msg
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -22,6 +22,7 @@ def get_user_service(db: Session = Depends(get_db)) -> UserService:
|
||||
|
||||
@router.get("/list", summary="Get user order list")
|
||||
def get_user_order_list(
|
||||
request: Request,
|
||||
page: int = Query(1, description="Current page number"),
|
||||
page_size: int = Query(15, description="Number of items per page"),
|
||||
keyword: str = Query("", description="Search keyword for user email or name"),
|
||||
@@ -30,6 +31,8 @@ def get_user_order_list(
|
||||
user_service: UserService = Depends(get_user_service),
|
||||
user_wallet_history_service: UserWalletHistoryService = Depends(get_user_wallet_history_service),
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
"""Get paginated list of user order history."""
|
||||
offset = (page - 1) * page_size
|
||||
if filter_payment_type:
|
||||
@@ -65,6 +68,7 @@ def get_user_order_list(
|
||||
|
||||
@router.get("/list/by_user", summary="Get user order list by user id")
|
||||
def get_user_order_list_by_user_id(
|
||||
request: Request,
|
||||
user_id: str = Query(..., description="User ID"),
|
||||
page: int = Query(1, description="Current page number"),
|
||||
page_size: int = Query(15, description="Number of items per page"),
|
||||
@@ -73,6 +77,8 @@ def get_user_order_list_by_user_id(
|
||||
user_service: UserService = Depends(get_user_service),
|
||||
user_wallet_history_service: UserWalletHistoryService = Depends(get_user_wallet_history_service),
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
"""Get paginated list of user order history by user id."""
|
||||
user = user_service.get_by_id(user_id)
|
||||
if not user:
|
||||
|
||||
@@ -7,6 +7,8 @@ from services.common.utils.response_utils import ResponseUtils
|
||||
from services.admin_service.services.payment_service import PaymentService
|
||||
from services.admin_service.services.user_wallet_history_service import UserWalletHistoryService
|
||||
from services.admin_service.tasks.order_monitor_task import OrderMonitorTask
|
||||
from services.admin_service.utils.user_utils import UserUtils
|
||||
from services.common import error_msg
|
||||
router = APIRouter()
|
||||
|
||||
|
||||
@@ -32,6 +34,8 @@ def create_payment_link(
|
||||
payment: PaymentService = Depends(get_payment),
|
||||
):
|
||||
"""Create Stripe payment link for the user."""
|
||||
if not UserUtils.is_normal_user(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
user = request.scope.get("user")
|
||||
if not user:
|
||||
return ResponseUtils.error(message="User not found", code=404)
|
||||
@@ -86,10 +90,13 @@ async def callback_stripe(
|
||||
|
||||
@router.get("/order_status", response_model=dict)
|
||||
async def order_status(
|
||||
request: Request,
|
||||
payment_id: str,
|
||||
get_user_wallet_history: UserWalletHistoryService = Depends(get_user_wallet_history),
|
||||
):
|
||||
"""Check payment order completion status."""
|
||||
if not UserUtils.is_normal_user(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
if get_user_wallet_history.check_order_complete(payment_id):
|
||||
return ResponseUtils.success({"status": 1})
|
||||
return ResponseUtils.success({"status": 0})
|
||||
@@ -1,4 +1,4 @@
|
||||
from fastapi import APIRouter, Depends, Query, Body
|
||||
from fastapi import APIRouter, Depends, Query, Body, Request
|
||||
from sqlalchemy.orm import Session
|
||||
|
||||
from services.common.database import get_db
|
||||
@@ -6,7 +6,8 @@ from services.common.utils.response_utils import ResponseUtils
|
||||
from services.admin_service.services.payment_channel_service import PaymentChannelService
|
||||
from services.common.utils.secure_config import decrypt_config, encrypt_config
|
||||
from services.admin_service.tasks.order_monitor_task import OrderMonitorTask
|
||||
import json
|
||||
from services.admin_service.utils.user_utils import UserUtils
|
||||
from services.common import error_msg
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -17,10 +18,13 @@ def get_payment_channel(db: Session = Depends(get_db)) -> PaymentChannelService:
|
||||
|
||||
@router.get("/list")
|
||||
async def payment_channel_list(
|
||||
request: Request,
|
||||
page: int = Query(1, description="Current page number"),
|
||||
page_size: int = Query(15, description="Number of items per page"),
|
||||
payment_channel_service: PaymentChannelService = Depends(get_payment_channel),
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
"""Get paginated list of payment channels."""
|
||||
total, list = payment_channel_service.list()
|
||||
if total == 0:
|
||||
@@ -45,9 +49,12 @@ async def payment_channel_list(
|
||||
|
||||
@router.put("/enable")
|
||||
async def payment_channel_enable(
|
||||
request: Request,
|
||||
payment_channel_service: PaymentChannelService = Depends(get_payment_channel),
|
||||
body: dict = Body(..., description="Payment channel configuration"),
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
"""Enable a payment channel by ID."""
|
||||
id = body.get("id")
|
||||
if not id:
|
||||
@@ -103,9 +110,12 @@ async def payment_channel_disable(
|
||||
|
||||
@router.put("/info")
|
||||
async def payment_channel_config(
|
||||
request: Request,
|
||||
payment_channel_service: PaymentChannelService = Depends(get_payment_channel),
|
||||
body: dict = Body(..., description="Payment channel configuration"),
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
"""Update payment channel configuration."""
|
||||
id = body.get("id")
|
||||
if not id:
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
Provides endpoints to read and update platform configurations, homepage content,
|
||||
and to test email settings. All responses and comments are standardized in English.
|
||||
"""
|
||||
from fastapi import APIRouter, Depends, Body
|
||||
from fastapi import APIRouter, Depends, Body, Request
|
||||
import json
|
||||
from sqlalchemy.orm import Session
|
||||
from services.common.database import get_db
|
||||
@@ -11,6 +11,8 @@ from services.common.utils.response_utils import ResponseUtils
|
||||
from services.common.utils.email_utils import EmailUtils
|
||||
from services.admin_service.services.sys_config_service import SysConfigService
|
||||
from services.admin_service.services.user_service import UserService
|
||||
from services.admin_service.utils.user_utils import UserUtils
|
||||
from services.common import error_msg
|
||||
from services.admin_service.services.platform_report_service import PlatformReportService
|
||||
from services.admin_service.constants import sys_config_key
|
||||
from services.common.logging_config import get_logger
|
||||
@@ -91,9 +93,12 @@ def update_homepage(
|
||||
|
||||
@router.get("/info")
|
||||
def get_sysconfig(
|
||||
request: Request,
|
||||
sysconfig_service: SysConfigService = Depends(get_sysconfig_service),
|
||||
user_service: UserService = Depends(get_user_service),
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
"""Get all system configuration settings."""
|
||||
admin_user = user_service.get_admin_user()
|
||||
# Batch read configurations (small table)
|
||||
@@ -173,10 +178,13 @@ def get_sysconfig(
|
||||
|
||||
@router.put("/info")
|
||||
def set_sysconfig(
|
||||
request: Request,
|
||||
body: dict = Body(...),
|
||||
user_service: UserService = Depends(get_user_service),
|
||||
sysconfig_service: SysConfigService = Depends(get_sysconfig_service),
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
"""Update system configuration settings."""
|
||||
try:
|
||||
platform_name = ""
|
||||
@@ -334,7 +342,7 @@ def set_sysconfig(
|
||||
# Log error but continue with main operation - reporting failure should not affect configuration update
|
||||
logger.warning(f"Failed to initiate platform reporting: {e}")
|
||||
|
||||
return get_sysconfig(sysconfig_service, user_service)
|
||||
return get_sysconfig(request, sysconfig_service, user_service)
|
||||
|
||||
except Exception as e:
|
||||
return ResponseUtils.error(f"Failed to update system configuration: {str(e)}")
|
||||
|
||||
@@ -3,7 +3,10 @@ import hashlib
|
||||
import os
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from fastapi import Request
|
||||
from services.common.utils.response_utils import ResponseUtils
|
||||
from services.admin_service.utils.user_utils import UserUtils
|
||||
from services.common import error_msg
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -14,6 +17,7 @@ and store files under date-based directories.
|
||||
"""
|
||||
@router.post("/image")
|
||||
async def upload(
|
||||
request: Request,
|
||||
img: UploadFile = File(None),
|
||||
sha256: str = Form(None),
|
||||
):
|
||||
@@ -24,6 +28,8 @@ async def upload(
|
||||
- Saves the file under `uploads/images/<YYYYMMDD>/`
|
||||
- Returns the relative `file_path`
|
||||
"""
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
# 1. Get uploaded file name
|
||||
if not img:
|
||||
return ResponseUtils.error(message="No file provided", code=400)
|
||||
|
||||
@@ -11,6 +11,9 @@ from services.admin_service.services.user_task_service import UserTaskService
|
||||
from services.admin_service.services.auth_service import AuthService
|
||||
from services.admin_service.services.resource_group_service import ResourceGroupService
|
||||
from services.admin_service.services.user_wallet_history_service import UserWalletHistoryService
|
||||
from services.common import error_msg
|
||||
|
||||
|
||||
|
||||
from typing import Optional,List
|
||||
|
||||
@@ -37,6 +40,8 @@ def get_order_service(db: Session = Depends(get_db)) -> UserWalletHistoryService
|
||||
@router.get("/info", response_model=dict)
|
||||
def get_user(request: Request, user_wallet: UserWalletService = Depends(get_user_wallet), user_task: UserTaskService = Depends(get_user_task_service), resource_group_service: ResourceGroupService = Depends(get_resource_group_service)):
|
||||
"""Get current user information and wallet balance."""
|
||||
if not UserUtils.is_normal_user(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
user_response = UserResponse()
|
||||
user_wallet_resp = UserWalletResponse()
|
||||
user_wallet_resp.balance = 0.00
|
||||
|
||||
@@ -6,6 +6,9 @@ from services.common.response.apikey_response import ApikeyResponse
|
||||
from services.admin_service.services.user_apikey_service import UserApiKeyService
|
||||
from services.admin_service.utils.user_utils import UserUtils
|
||||
from services.common.models.user_apikey import UserApiKey
|
||||
from services.common import error_msg
|
||||
|
||||
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@@ -29,6 +32,8 @@ def convert_to_apikey_response(user_apikey: UserApiKey) -> ApikeyResponse:
|
||||
@router.post("/info", summary="add apikey")
|
||||
def add_apikey(request: Request, apikey_service: UserApiKeyService = Depends(get_apikey_service), body: dict = Body(...)):
|
||||
"""Create a new API key for the user."""
|
||||
if not UserUtils.is_normal_user(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
user_id = UserUtils.get_request_user_id(request)
|
||||
name = body.get("name")
|
||||
if name is None:
|
||||
@@ -46,6 +51,8 @@ def add_apikey(request: Request, apikey_service: UserApiKeyService = Depends(get
|
||||
@router.get("/list", summary="get user apikey list")
|
||||
def get_user_apikey_list(request: Request, apikey_service: UserApiKeyService = Depends(get_apikey_service)):
|
||||
"""Get list of API keys for the current user."""
|
||||
if not UserUtils.is_normal_user(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
user_id = UserUtils.get_request_user_id(request)
|
||||
apikey_list = apikey_service.get_by_user_id(user_id)
|
||||
data = [convert_to_apikey_response(item) for item in apikey_list]
|
||||
@@ -55,6 +62,8 @@ def get_user_apikey_list(request: Request, apikey_service: UserApiKeyService = D
|
||||
@router.delete("/info", summary="delete user apikey")
|
||||
def delete_apikey(request: Request, apikey_service: UserApiKeyService = Depends(get_apikey_service), body: dict = Body(...)):
|
||||
"""Delete an API key by ID for the current user."""
|
||||
if not UserUtils.is_normal_user(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
user_id = UserUtils.get_request_user_id(request)
|
||||
id = body.get("apikey_id")
|
||||
if id is None:
|
||||
@@ -68,6 +77,8 @@ def delete_apikey(request: Request, apikey_service: UserApiKeyService = Depends(
|
||||
@router.put("/info", summary="modify user apikey")
|
||||
def modify_apikey(request: Request, apikey_service: UserApiKeyService = Depends(get_apikey_service), body: dict = Body(...)):
|
||||
"""Update API key information for the current user."""
|
||||
if not UserUtils.is_normal_user(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
user_id = UserUtils.get_request_user_id(request)
|
||||
id = body.get("apikey_id")
|
||||
name = body.get("name")
|
||||
|
||||
@@ -63,11 +63,13 @@ async def update_user_resource_group(
|
||||
|
||||
@router.delete("/account", summary="Delete user account")
|
||||
async def delete_user(
|
||||
request: Request,
|
||||
id: str,
|
||||
user_service: UserService = Depends(get_user_service),
|
||||
):
|
||||
"""Delete user by ID."""
|
||||
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
# Validate user ID parameter
|
||||
ValidationUtils.require_non_empty_string(id, "id")
|
||||
|
||||
@@ -88,6 +90,7 @@ async def delete_user(
|
||||
|
||||
@router.get("/account/list", summary="Get user list with pagination")
|
||||
async def get_user_list(
|
||||
request: Request,
|
||||
page: int = Query(1, description="Page number (starts from 1)"),
|
||||
page_size: int = Query(15, description="Number of items per page"),
|
||||
keyword: str = Query(None, description="Search keyword for email or name"),
|
||||
@@ -95,7 +98,8 @@ async def get_user_list(
|
||||
user_wallet_service: UserWalletService = Depends(get_user_wallet_service),
|
||||
):
|
||||
"""Get paginated list of users with wallet information."""
|
||||
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
# Validate pagination parameters
|
||||
validated_page, validated_page_size = ValidationUtils.validate_pagination(page, page_size)
|
||||
|
||||
@@ -126,6 +130,8 @@ async def recharge_balance(
|
||||
request: Request,
|
||||
payment_service: PaymentService = Depends(get_payment_service),
|
||||
):
|
||||
if not UserUtils.is_admin(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
body = await request.body()
|
||||
body_str = body.decode('utf-8')
|
||||
timestamp=request.headers.get("x-xpack-timestamp")
|
||||
|
||||
@@ -2,12 +2,14 @@
|
||||
User statistics controller
|
||||
"""
|
||||
|
||||
from fastapi import APIRouter, Depends, Query
|
||||
from fastapi import APIRouter, Depends, Query, Request
|
||||
from sqlalchemy.orm import Session
|
||||
from services.common.database import get_db
|
||||
from services.common.utils.response_utils import ResponseUtils
|
||||
from services.admin_service.services.user_stats_service import UserStatsService
|
||||
from services.admin_service.utils.user_utils import UserUtils
|
||||
from services.common.logging_config import get_logger
|
||||
from services.common import error_msg
|
||||
|
||||
logger = get_logger(__name__)
|
||||
router = APIRouter()
|
||||
@@ -15,10 +17,13 @@ router = APIRouter()
|
||||
|
||||
@router.get("/key_call_tool")
|
||||
async def get_key_call_tool(
|
||||
request: Request,
|
||||
apikey_id: str = Query(..., description="apikey ID (not the apikey itself)"),
|
||||
last_day: int = Query(30, description="Days to query, default 30"),
|
||||
db: Session = Depends(get_db),
|
||||
):
|
||||
if not UserUtils.is_normal_user(request):
|
||||
return ResponseUtils.error(error_msg=error_msg.NO_PERMISSION)
|
||||
"""
|
||||
Get tool call statistics by apikey
|
||||
"""
|
||||
@@ -51,12 +56,12 @@ async def get_key_call_tool(
|
||||
|
||||
except ValueError as e:
|
||||
# Handle business logic errors (invalid apikey_id)
|
||||
error_msg = str(e)
|
||||
logger.error(f"Business logic error: {error_msg}")
|
||||
return ResponseUtils.error(error_msg, code=400)
|
||||
err_msg = str(e)
|
||||
logger.error(f"Business logic error: {err_msg}")
|
||||
return ResponseUtils.error(err_msg, code=400)
|
||||
|
||||
except Exception as e:
|
||||
# Handle unexpected errors
|
||||
error_msg = f"Failed to retrieve call tool statistics: {str(e)}"
|
||||
logger.error(f"Unexpected error in get_key_call_tool_count: {error_msg}", exc_info=True)
|
||||
err_msg = f"Failed to retrieve call tool statistics: {str(e)}"
|
||||
logger.error(f"Unexpected error in get_key_call_tool_count: {err_msg}", exc_info=True)
|
||||
return ResponseUtils.error("Internal server error occurred while retrieving statistics", code=500)
|
||||
@@ -15,8 +15,8 @@ class UserRepository:
|
||||
def get_by_email(self, email: str) -> Optional[User]:
|
||||
return self.db.query(User).filter(User.email == email).first()
|
||||
|
||||
def get_by_account(self, name: str) -> Optional[User]:
|
||||
return self.db.query(User).filter(User.name == name).first()
|
||||
def get_by_account(self, name: str, role_id: int = 1) -> Optional[User]:
|
||||
return self.db.query(User).filter(User.name == name, User.role_id == role_id).first()
|
||||
|
||||
def update_password(self,user_id:str, password:str) -> Optional[User]:
|
||||
user = self.get_by_id(user_id)
|
||||
|
||||
@@ -25,3 +25,9 @@ class UserUtils:
|
||||
"""Check if current user is admin"""
|
||||
user = UserUtils.get_request_user(request)
|
||||
return user and user.role_id == 1 if user else False
|
||||
|
||||
@staticmethod
|
||||
def is_normal_user(request) -> bool:
|
||||
"""Check if current user is normal user"""
|
||||
user = UserUtils.get_request_user(request)
|
||||
return user and user.role_id == 2 if user else False
|
||||
@@ -45,7 +45,9 @@ class RedisEventStore(EventStore):
|
||||
|
||||
async def store_event(self, stream_id: StreamId, message: JSONRPCMessage) -> EventId:
|
||||
key = self._key(stream_id)
|
||||
payload = json.dumps(message.model_dump(by_alias=True, exclude_none=True))
|
||||
payload = json.dumps(
|
||||
message.model_dump(by_alias=True, exclude_none=True) if message is not None else {}
|
||||
)
|
||||
# Append to Redis list via thread wrapper to avoid blocking
|
||||
seq: int = await asyncio.to_thread(self._rpush, key, payload)
|
||||
# rpush returns new length; sequence index is length-1
|
||||
|
||||
@@ -33,7 +33,7 @@ def verify_token(token: str, db: Session) -> Optional[User]:
|
||||
set_model_cache(token_cache_key, user_access_token, TOKEN_CACHE_EXPIRE_TIME)
|
||||
|
||||
logging.info(f"query token info")
|
||||
|
||||
print(f'user_access_token: {user_access_token}, expire_at: {user_access_token.expire_at},token_cache_key: {token_cache_key}')
|
||||
# Check if token is expired
|
||||
expire_at = user_access_token.expire_at
|
||||
try:
|
||||
|
||||
Reference in new issue
Block a user