mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-06-01 13:49:49 +08:00
主要变更:
1. **数据库集成**:
* 引入 MySQL 数据库支持,使用 SQLAlchemy 和 `databases` 库持久化存储应用程序设置。
* 添加了 `app/database` 目录,包含数据库连接、模型和初始化逻辑。
* 更新 `requirements.txt` 添加数据库相关依赖 (`pymysql`, `sqlalchemy`, `aiomysql`, `databases`, `python-dotenv`)。
2. **配置管理重构**:
* 重构 `ConfigService` (`app/service/config/config_service.py`),使其从数据库加载和保存设置,并支持从 `.env` 文件同步初始配置到数据库。
* 修改 `Settings` 模型 (`app/config/config.py`) 以包含数据库连接信息,并添加了从数据库加载/同步配置的逻辑。
* 配置相关的路由 (`app/router/config_routes.py`) 更新为异步,并调用新的 `ConfigService` 方法。
* `KeyManager` (`app/service/key/key_manager.py`) 现在可以在配置更新后重置和重新初始化。
3. **错误日志查看器**:
* 新增 `/logs` 页面 (`app/templates/error_logs.html`) 用于展示应用程序错误日志。
* 添加了相应的路由 (`app/router/log_routes.py`)、静态资源 (`app/static/css/error_logs.css`, `app/static/js/error_logs.js`) 和日志记录器 (`app/log/logger.py`)。
* 在配置页面和密钥管理页面的导航栏中添加了指向日志页面的链接。
4. **异步操作**:
* 将配置服务和相关路由转换为异步 (`async def`) 以支持异步数据库操作。
5. **其他**:
* 更新了应用程序初始化逻辑 (`app/core/application.py`, `app/core/initialization.py`) 以包含数据库连接的建立和关闭。
157 lines
7.6 KiB
HTML
157 lines
7.6 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="zh-CN">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>错误日志管理</title>
|
|
<link rel="manifest" href="/static/manifest.json">
|
|
<meta name="theme-color" content="#764ba2">
|
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|
<meta name="apple-mobile-web-app-title" content="GBalance">
|
|
<link rel="icon" href="/static/icons/icon-192x192.png">
|
|
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;700&display=swap" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css">
|
|
<link rel="stylesheet" href="{{ url_for('static', path='/css/error_logs.css') }}">
|
|
</head>
|
|
<body>
|
|
<div class="container">
|
|
<button class="refresh-btn" onclick="refreshPage(this)">
|
|
<i class="fas fa-sync-alt"></i>
|
|
</button>
|
|
<div class="row">
|
|
<div class="col-12">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1>Gemini Balance</h1>
|
|
<div class="nav-tabs">
|
|
<a href="/config" class="tab-link">
|
|
<i class="fas fa-cog"></i> 配置编辑
|
|
</a>
|
|
<a href="/keys" class="tab-link">
|
|
<i class="fas fa-key"></i> 密钥管理
|
|
</a>
|
|
<a href="/logs" class="tab-link active">
|
|
<i class="fas fa-exclamation-triangle"></i> 错误日志
|
|
</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header d-flex justify-content-between align-items-center">
|
|
<h5 class="mb-0">错误日志列表</h5>
|
|
<div class="d-flex">
|
|
<div class="input-group me-2">
|
|
<span class="input-group-text">每页显示</span>
|
|
<select id="pageSize" class="form-select">
|
|
<option value="10">10</option>
|
|
<option value="20" selected>20</option>
|
|
<option value="50">50</option>
|
|
<option value="100">100</option>
|
|
</select>
|
|
<span class="input-group-text">条</span>
|
|
</div>
|
|
<button id="refreshBtn" class="btn btn-primary">
|
|
<i class="bi bi-arrow-clockwise"></i> 刷新
|
|
</button>
|
|
</div>
|
|
</div>
|
|
<div class="card-body">
|
|
<div class="table-responsive">
|
|
<table class="table table-striped table-hover">
|
|
<thead>
|
|
<tr>
|
|
<th>ID</th>
|
|
<th>Gemini密钥</th>
|
|
<th>错误日志</th>
|
|
<th>请求时间</th>
|
|
<th>操作</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody id="errorLogsTable">
|
|
<!-- 错误日志数据将通过JavaScript动态加载 -->
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
|
|
<div id="loadingIndicator" class="text-center my-4 d-none">
|
|
<div class="spinner-border text-primary" role="status">
|
|
<span class="visually-hidden">加载中...</span>
|
|
</div>
|
|
<p class="mt-2">加载中,请稍候...</p>
|
|
</div>
|
|
|
|
<div id="noDataMessage" class="text-center my-4 d-none">
|
|
<p class="text-muted">暂无错误日志数据</p>
|
|
</div>
|
|
|
|
<div id="errorMessage" class="alert alert-danger my-4 d-none">
|
|
加载错误日志失败,请稍后重试。
|
|
</div>
|
|
</div>
|
|
<div class="card-footer">
|
|
<nav aria-label="错误日志分页">
|
|
<ul class="pagination justify-content-center mb-0" id="pagination">
|
|
<!-- 分页控件将通过JavaScript动态加载 -->
|
|
</ul>
|
|
</nav>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="scroll-buttons">
|
|
<button class="scroll-btn" onclick="scrollToTop()" title="回到顶部">
|
|
<i class="fas fa-chevron-up"></i>
|
|
</button>
|
|
<button class="scroll-btn" onclick="scrollToBottom()" title="滚动到底部">
|
|
<i class="fas fa-chevron-down"></i>
|
|
</button>
|
|
</div>
|
|
|
|
<div id="copyStatus"></div>
|
|
|
|
<div class="copyright">
|
|
© <script>document.write(new Date().getFullYear())</script> by <a href="https://linux.do/u/snaily" target="_blank"><img src="https://linux.do/user_avatar/linux.do/snaily/288/306510_2.gif" alt="snaily">snaily</a> |
|
|
<a href="https://github.com/snailyp/gemini-balance" target="_blank"><i class="fab fa-github"></i> GitHub</a>
|
|
</div>
|
|
|
|
<!-- 错误日志详情模态框 -->
|
|
<div class="modal fade" id="logDetailModal" tabindex="-1" aria-labelledby="logDetailModalLabel" aria-hidden="true">
|
|
<div class="modal-dialog modal-lg modal-dialog-scrollable">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title" id="logDetailModalLabel">错误日志详情</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="关闭"></button>
|
|
</div>
|
|
<div class="modal-body">
|
|
<div class="mb-3">
|
|
<h6>Gemini密钥:</h6>
|
|
<pre id="modalGeminiKey" class="bg-light p-2 rounded"></pre>
|
|
</div>
|
|
<div class="mb-3">
|
|
<h6>错误日志:</h6>
|
|
<pre id="modalErrorLog" class="bg-light p-2 rounded"></pre>
|
|
</div>
|
|
<div class="mb-3">
|
|
<h6>请求消息:</h6>
|
|
<pre id="modalRequestMsg" class="bg-light p-2 rounded"></pre>
|
|
</div>
|
|
<div>
|
|
<h6>请求时间:</h6>
|
|
<p id="modalRequestTime"></p>
|
|
</div>
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
|
<script src="{{ url_for('static', path='/js/error_logs.js') }}"></script>
|
|
</body>
|
|
</html>
|