mirror of
https://github.com/chenyme/grok2api.git
synced 2026-12-05 08:01:07 +00:00
Merge remote-tracking branch 'origin/main' into pr/319
This commit is contained in:
commit
5fb7db3e78
17 files changed
+105
-63
No files matched your search
@@ -544,8 +544,8 @@ function openEditModal(index) {
|
||||
|
||||
// 根据配置决定是否禁用 quota 编辑
|
||||
const quotaInput = byId('edit-quota');
|
||||
const quotaInputParent = quotaInput?.closest('div');
|
||||
const quotaLabel = quotaInputParent?.previousElementSibling;
|
||||
const quotaField = quotaInput?.closest('div');
|
||||
const quotaLabel = quotaField?.querySelector('label');
|
||||
if (consumedModeEnabled) {
|
||||
quotaInput.value = item.consumed || 0;
|
||||
quotaInput.disabled = true;
|
||||
@@ -576,8 +576,8 @@ function openEditModal(index) {
|
||||
|
||||
// 新建 Token 时启用 quota 编辑
|
||||
const newQuotaInput = byId('edit-quota');
|
||||
const newQuotaInputParent = newQuotaInput?.closest('div');
|
||||
const newQuotaLabel = newQuotaInputParent?.previousElementSibling;
|
||||
const newQuotaField = newQuotaInput?.closest('div');
|
||||
const newQuotaLabel = newQuotaField?.querySelector('label');
|
||||
newQuotaInput.disabled = false;
|
||||
newQuotaInput.classList.remove('bg-gray-100', 'text-gray-400');
|
||||
if (newQuotaLabel) newQuotaLabel.textContent = t('token.editQuota');
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-sans/style.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-mono/style.css" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/admin/css/cache.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/admin/css/cache.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/toast.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
@@ -257,12 +257,12 @@
|
||||
</dialog>
|
||||
|
||||
<script src="/static/i18n/i18n.js"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/batch-sse.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/header.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/batch-sse.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/header.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/toast.js"></script>
|
||||
<script src="/static/admin/js/cache.js?v=1.6.1"></script>
|
||||
<script src="/static/admin/js/cache.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/draggable.js"></script>
|
||||
</body>
|
||||
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-sans/style.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-mono/style.css" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/admin/css/config.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/admin/css/config.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/toast.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
@@ -47,11 +47,11 @@
|
||||
<div id="app-footer"></div>
|
||||
|
||||
<script src="/static/i18n/i18n.js"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/header.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/header.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/toast.js"></script>
|
||||
<script src="/static/admin/js/config.js?v=1.6.1"></script>
|
||||
<script src="/static/admin/js/config.js?v=1.6.2"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -24,8 +24,8 @@
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<link href="/static/common/css/common.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/login.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/login.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/toast.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
@@ -56,10 +56,10 @@
|
||||
<div id="app-footer"></div>
|
||||
|
||||
<script src="/static/i18n/i18n.js"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/toast.js"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.1"></script>
|
||||
<script src="/static/admin/js/login.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.2"></script>
|
||||
<script src="/static/admin/js/login.js?v=1.6.2"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -9,8 +9,8 @@
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-sans/style.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-mono/style.css" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/admin/css/token.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/admin/css/token.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/toast.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
@@ -323,12 +323,12 @@
|
||||
|
||||
<script src="/static/common/js/draggable.js"></script>
|
||||
<script src="/static/i18n/i18n.js"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/batch-sse.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/header.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/batch-sse.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/header.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/toast.js"></script>
|
||||
<script src="/static/admin/js/token.js?v=1.6.1"></script>
|
||||
<script src="/static/admin/js/token.js?v=1.6.2"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -2,7 +2,7 @@ async function loadAdminFooter() {
|
||||
const container = document.getElementById('app-footer');
|
||||
if (!container) return;
|
||||
try {
|
||||
const res = await fetch('/static/common/html/footer.html?v=1.6.1');
|
||||
const res = await fetch('/static/common/html/footer.html?v=1.6.2');
|
||||
if (!res.ok) return;
|
||||
container.innerHTML = await res.text();
|
||||
} catch (e) {
|
||||
|
||||
@@ -2,7 +2,7 @@ async function loadFunctionHeader() {
|
||||
const container = document.getElementById('app-header');
|
||||
if (!container) return;
|
||||
try {
|
||||
const res = await fetch('/static/common/html/function-header.html?v=1.6.1');
|
||||
const res = await fetch('/static/common/html/function-header.html?v=1.6.2');
|
||||
if (!res.ok) return;
|
||||
container.innerHTML = await res.text();
|
||||
const logoutBtn = container.querySelector('#function-logout-btn');
|
||||
|
||||
@@ -2,7 +2,7 @@ async function loadAdminHeader() {
|
||||
const container = document.getElementById('app-header');
|
||||
if (!container) return;
|
||||
try {
|
||||
const res = await fetch('/static/common/html/header.html?v=1.6.1');
|
||||
const res = await fetch('/static/common/html/header.html?v=1.6.2');
|
||||
if (!res.ok) return;
|
||||
container.innerHTML = await res.text();
|
||||
const path = window.location.pathname;
|
||||
|
||||
@@ -9,8 +9,8 @@
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-sans/style.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-mono/style.css" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/function/css/chat.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/function/css/chat.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/toast.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
@@ -148,11 +148,11 @@
|
||||
<div id="app-footer"></div>
|
||||
|
||||
<script src="/static/i18n/i18n.js"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/function-header.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/function-header.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/toast.js"></script>
|
||||
<script src="/static/function/js/chat.js?v=1.6.1"></script>
|
||||
<script src="/static/function/js/chat.js?v=1.6.2"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -9,8 +9,8 @@
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-sans/style.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-mono/style.css" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/function/css/imagine.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/function/css/imagine.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/toast.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
@@ -238,12 +238,12 @@
|
||||
<div id="app-footer"></div>
|
||||
|
||||
<script src="/static/i18n/i18n.js"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/function-header.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/function-header.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/toast.js"></script>
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.10.1/jszip.min.js"></script>
|
||||
<script src="/static/function/js/imagine.js?v=1.6.1"></script>
|
||||
<script src="/static/function/js/imagine.js?v=1.6.2"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -24,8 +24,8 @@
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<link href="/static/common/css/common.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/login.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/login.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/toast.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
@@ -60,10 +60,10 @@
|
||||
<div id="app-footer"></div>
|
||||
|
||||
<script src="/static/i18n/i18n.js"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/toast.js"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.1"></script>
|
||||
<script src="/static/function/js/login.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.2"></script>
|
||||
<script src="/static/function/js/login.js?v=1.6.2"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -9,8 +9,8 @@
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-sans/style.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-mono/style.css" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/function/css/video.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/function/css/video.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/toast.css" rel="stylesheet">
|
||||
</head>
|
||||
|
||||
@@ -155,11 +155,11 @@
|
||||
<div id="app-footer"></div>
|
||||
|
||||
<script src="/static/i18n/i18n.js"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/function-header.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/function-header.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/toast.js"></script>
|
||||
<script src="/static/function/js/video.js?v=1.6.1"></script>
|
||||
<script src="/static/function/js/video.js?v=1.6.2"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -9,8 +9,8 @@
|
||||
<script src="https://cdn.tailwindcss.com"></script>
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-sans/style.css" rel="stylesheet">
|
||||
<link href="https://cdn.jsdelivr.net/npm/geist@1.0.0/dist/fonts/geist-mono/style.css" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/function/css/voice.css?v=1.6.1" rel="stylesheet">
|
||||
<link href="/static/common/css/common.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/function/css/voice.css?v=1.6.2" rel="stylesheet">
|
||||
<link href="/static/common/css/toast.css" rel="stylesheet">
|
||||
<script src="https://cdn.jsdelivr.net/npm/livekit-client@2.7.3/dist/livekit-client.umd.min.js"></script>
|
||||
</head>
|
||||
@@ -148,11 +148,11 @@
|
||||
<div id="app-footer"></div>
|
||||
|
||||
<script src="/static/i18n/i18n.js"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/function-header.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.1"></script>
|
||||
<script src="/static/common/js/admin-auth.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/function-header.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/footer.js?v=1.6.2"></script>
|
||||
<script src="/static/common/js/toast.js"></script>
|
||||
<script src="/static/function/js/voice.js?v=1.6.1"></script>
|
||||
<script src="/static/function/js/voice.js?v=1.6.2"></script>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
@@ -46,6 +46,8 @@ def _sanitize_token_text(value) -> str:
|
||||
@router.get("/tokens", dependencies=[Depends(verify_app_key)])
|
||||
async def get_tokens():
|
||||
"""获取所有 Token"""
|
||||
# 获取消耗模式配置
|
||||
from app.core.config import get_config
|
||||
mgr = await get_token_manager()
|
||||
results = {}
|
||||
for pool_name, pool in mgr.pools.items():
|
||||
|
||||
@@ -52,6 +52,26 @@ def json_dumps_sorted(obj: Any) -> str:
|
||||
return orjson.dumps(obj, option=orjson.OPT_SORT_KEYS).decode("utf-8")
|
||||
|
||||
|
||||
def has_token_entries(data: Any) -> bool:
|
||||
"""Return True when the payload contains at least one non-empty token."""
|
||||
if not isinstance(data, dict):
|
||||
return False
|
||||
|
||||
for tokens in data.values():
|
||||
if not isinstance(tokens, list):
|
||||
continue
|
||||
for item in tokens:
|
||||
if isinstance(item, str):
|
||||
if item.strip():
|
||||
return True
|
||||
continue
|
||||
if isinstance(item, dict):
|
||||
token = item.get("token")
|
||||
if isinstance(token, str) and token.strip():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
class StorageError(Exception):
|
||||
"""存储服务基础异常"""
|
||||
|
||||
@@ -269,6 +289,13 @@ class LocalStorage(BaseStorage):
|
||||
|
||||
async def save_tokens(self, data: Dict[str, Any]):
|
||||
try:
|
||||
if not has_token_entries(data):
|
||||
existing = await self.load_tokens() or {}
|
||||
if has_token_entries(existing):
|
||||
logger.warning(
|
||||
"LocalStorage: 跳过空 Token 全量保存,避免覆盖已有数据"
|
||||
)
|
||||
return
|
||||
TOKEN_FILE.parent.mkdir(parents=True, exist_ok=True)
|
||||
temp_path = TOKEN_FILE.with_suffix(".tmp")
|
||||
|
||||
@@ -489,6 +516,13 @@ class RedisStorage(BaseStorage):
|
||||
for tokens in pool_tokens_res:
|
||||
existing_token_ids.update(list(tokens or []))
|
||||
|
||||
if not new_token_ids:
|
||||
if existing_token_ids:
|
||||
logger.warning(
|
||||
"RedisStorage: 跳过空 Token 全量保存,避免删除已有数据"
|
||||
)
|
||||
return
|
||||
|
||||
tokens_to_delete = existing_token_ids - new_token_ids
|
||||
all_pools = existing_pools.union(new_pools)
|
||||
|
||||
@@ -1082,6 +1116,12 @@ class SQLStorage(BaseStorage):
|
||||
res = await session.execute(text("SELECT token FROM tokens"))
|
||||
rows = res.fetchall()
|
||||
existing_tokens = {row[0] for row in rows}
|
||||
if not new_tokens:
|
||||
if existing_tokens:
|
||||
logger.warning(
|
||||
"SQLStorage: 跳过空 Token 全量保存,避免删除已有数据"
|
||||
)
|
||||
return
|
||||
tokens_to_delete = list(existing_tokens - new_tokens)
|
||||
await self.save_tokens_delta(updates, tokens_to_delete)
|
||||
except Exception as e:
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
[project]
|
||||
name = "grok2api"
|
||||
version = "1.6.1"
|
||||
version = "1.6.2"
|
||||
description = "Grok2API rebuilt with FastAPI, fully aligned with the latest web call format. Supports streaming and non-streaming chat, image generation/editing, deep thinking, token pool concurrency, and automatic load balancing."
|
||||
readme = "README.md"
|
||||
requires-python = ">=3.13"
|
||||
|
||||
Reference in new issue
Block a user