feat: 添加后台管理功能
功能: - 概览统计 - 模型/GPU/CPU管理(增删改查) - 侧边栏导航 - 表单验证
This commit is contained in:
85
app.py
85
app.py
@@ -68,6 +68,11 @@ def knowledge_page():
|
||||
"""知识库页面"""
|
||||
return render_template('knowledge.html')
|
||||
|
||||
@app.route('/admin')
|
||||
def admin_page():
|
||||
"""后台管理页面"""
|
||||
return render_template('admin.html')
|
||||
|
||||
# ============ API路由 ============
|
||||
|
||||
@app.route('/api/models')
|
||||
@@ -188,6 +193,86 @@ def api_cpu_detail(cpu_id):
|
||||
|
||||
return jsonify(cpu)
|
||||
|
||||
@app.route('/api/gpus', methods=['POST'])
|
||||
def api_create_gpu():
|
||||
"""创建新GPU"""
|
||||
data = request.get_json()
|
||||
gpus = load_data(GPUS_FILE)
|
||||
|
||||
import uuid
|
||||
data['id'] = uuid.uuid4().hex[:12]
|
||||
data['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
gpus.append(data)
|
||||
save_data(GPUS_FILE, gpus)
|
||||
|
||||
return jsonify(data)
|
||||
|
||||
@app.route('/api/gpus/<gpu_id>', methods=['PUT'])
|
||||
def api_update_gpu(gpu_id):
|
||||
"""更新GPU"""
|
||||
data = request.get_json()
|
||||
gpus = load_data(GPUS_FILE)
|
||||
|
||||
gpu = next((g for g in gpus if g['id'] == gpu_id), None)
|
||||
if not gpu:
|
||||
return jsonify({'error': 'GPU not found'}), 404
|
||||
|
||||
gpu.update(data)
|
||||
gpu['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
save_data(GPUS_FILE, gpus)
|
||||
|
||||
return jsonify(gpu)
|
||||
|
||||
@app.route('/api/gpus/<gpu_id>', methods=['DELETE'])
|
||||
def api_delete_gpu(gpu_id):
|
||||
"""删除GPU"""
|
||||
gpus = load_data(GPUS_FILE)
|
||||
gpus = [g for g in gpus if g['id'] != gpu_id]
|
||||
save_data(GPUS_FILE, gpus)
|
||||
|
||||
return jsonify({'success': True})
|
||||
|
||||
@app.route('/api/cpus', methods=['POST'])
|
||||
def api_create_cpu():
|
||||
"""创建新CPU"""
|
||||
data = request.get_json()
|
||||
cpus = load_data(CPUS_FILE)
|
||||
|
||||
import uuid
|
||||
data['id'] = uuid.uuid4().hex[:12]
|
||||
data['created_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
||||
cpus.append(data)
|
||||
save_data(CPUS_FILE, cpus)
|
||||
|
||||
return jsonify(data)
|
||||
|
||||
@app.route('/api/cpus/<cpu_id>', methods=['PUT'])
|
||||
def api_update_cpu(cpu_id):
|
||||
"""更新CPU"""
|
||||
data = request.get_json()
|
||||
cpus = load_data(CPUS_FILE)
|
||||
|
||||
cpu = next((c for c in cpus if c['id'] == cpu_id), None)
|
||||
if not cpu:
|
||||
return jsonify({'error': 'CPU not found'}), 404
|
||||
|
||||
cpu.update(data)
|
||||
cpu['updated_at'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
save_data(CPUS_FILE, cpus)
|
||||
|
||||
return jsonify(cpu)
|
||||
|
||||
@app.route('/api/cpus/<cpu_id>', methods=['DELETE'])
|
||||
def api_delete_cpu(cpu_id):
|
||||
"""删除CPU"""
|
||||
cpus = load_data(CPUS_FILE)
|
||||
cpus = [c for c in cpus if c['id'] != cpu_id]
|
||||
save_data(CPUS_FILE, cpus)
|
||||
|
||||
return jsonify({'success': True})
|
||||
|
||||
@app.route('/api/search')
|
||||
def api_search():
|
||||
"""全局搜索"""
|
||||
|
||||
Reference in New Issue
Block a user