feat: fix video generation API and pagination controls, update configuration for upscale timing, and enhance UI for token management

This commit is contained in:
Chenyme committed 2026-03-07 13:12:29 +08:00
1 parent 7ab06be04a
commit 56bbd4ba96
27 files changed
+2154 -913

No files matched your search

+150
View File
@@ -73,6 +73,156 @@
border: 1px solid var(--border);
}
.cache-pagination {
margin: 0;
display: flex;
align-items: center;
justify-content: space-between;
gap: 10px;
padding: 10px 12px;
border-bottom: 1px solid var(--border);
background: linear-gradient(180deg, rgba(250, 250, 251, 0.9) 0%, rgba(255, 255, 255, 0.95) 100%);
}
.cache-table-shell {
border-radius: 10px;
overflow: hidden;
background: #fff;
}
.cache-pagination-left {
display: inline-flex;
align-items: center;
gap: 6px;
}
.cache-pagination-info {
font-size: 12px;
color: var(--accents-5);
white-space: nowrap;
}
.cache-pagination-right {
display: inline-flex;
align-items: center;
gap: 8px;
justify-content: flex-end;
}
.cache-pagination-icon-btn {
width: 24px;
height: 24px;
display: inline-flex;
align-items: center;
justify-content: center;
border: 0;
background: transparent;
color: var(--accents-5);
border-radius: 6px;
cursor: pointer;
transition: color 0.15s, background 0.15s;
}
.cache-pagination-icon-btn:hover:not(:disabled) {
color: var(--accents-7);
background: #f3f4f6;
}
.cache-pagination-icon-btn:disabled {
color: var(--accents-5);
opacity: 0.5;
cursor: not-allowed;
background: transparent;
}
.cache-select-menu-wrap {
position: relative;
}
.cache-pagination-action-btn {
height: 28px;
padding: 0 10px;
display: inline-flex;
align-items: center;
gap: 4px;
border: 1px solid var(--border);
border-radius: 8px;
background: #fff;
color: var(--accents-6);
font-size: 12px;
cursor: pointer;
transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.cache-pagination-action-btn:hover {
border-color: var(--accents-3);
color: var(--accents-7);
background: #fafafa;
}
.cache-pagination-action-btn.is-active {
border-color: #111827;
color: #111827;
}
.cache-select-all-popover {
position: absolute;
right: 0;
top: calc(100% + 6px);
min-width: 116px;
border: 1px solid var(--border);
border-radius: 10px;
background: #fff;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
padding: 4px;
z-index: 30;
}
.cache-select-all-popover.hidden {
display: none;
}
.cache-select-all-option {
width: 100%;
height: 30px;
border: 0;
border-radius: 7px;
background: transparent;
text-align: left;
padding: 0 8px;
font-size: 12px;
color: var(--accents-6);
cursor: pointer;
}
.cache-select-all-option:hover {
background: #f3f4f6;
color: var(--accents-7);
}
.cache-pagination-select {
min-width: 88px;
height: 28px;
border: 1px solid var(--border);
border-radius: 8px;
background: #fff;
font-size: 12px;
padding: 0 8px;
color: var(--accents-6);
}
@media (max-width: 900px) {
.cache-pagination {
flex-wrap: wrap;
row-gap: 8px;
}
.cache-pagination-right {
margin-left: auto;
flex-wrap: wrap;
}
}
#confirm-dialog.confirm-dialog {
border: none;
border-radius: 12px;
+136 -1
View File
@@ -71,7 +71,142 @@
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 8px 4px;
padding: 10px 12px;
border-bottom: 1px solid var(--border);
background: linear-gradient(180deg, rgba(250, 250, 251, 0.9) 0%, rgba(255, 255, 255, 0.95) 100%);
}
.pagination-left {
display: inline-flex;
align-items: center;
gap: 6px;
min-width: 0;
}
.pagination-right {
display: inline-flex;
align-items: center;
justify-content: flex-end;
gap: 8px;
}
.pagination-info {
font-size: 12px;
color: var(--accents-5);
white-space: nowrap;
}
.pagination-icon-btn {
width: 24px;
height: 24px;
display: inline-flex;
align-items: center;
justify-content: center;
border: 0;
background: transparent;
color: var(--accents-5);
border-radius: 6px;
cursor: pointer;
transition: color 0.15s, background 0.15s;
}
.pagination-icon-btn:hover:not(:disabled) {
color: var(--accents-7);
background: #f3f4f6;
}
.pagination-icon-btn:disabled {
color: var(--accents-3);
cursor: not-allowed;
background: transparent;
}
.select-menu-wrap {
position: relative;
}
.pagination-action-btn {
height: 28px;
padding: 0 10px;
display: inline-flex;
align-items: center;
gap: 4px;
border: 1px solid var(--border);
border-radius: 8px;
background: #fff;
color: var(--accents-6);
font-size: 12px;
cursor: pointer;
transition: border-color 0.15s, color 0.15s, background 0.15s;
}
.pagination-action-btn:hover {
border-color: var(--accents-3);
color: var(--accents-7);
background: #fafafa;
}
.pagination-action-btn.is-active {
border-color: #111827;
color: #111827;
}
.select-all-popover {
position: absolute;
right: 0;
top: calc(100% + 6px);
min-width: 116px;
border: 1px solid var(--border);
border-radius: 10px;
background: #fff;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
padding: 4px;
z-index: 30;
}
.select-all-popover.hidden {
display: none;
}
.select-all-option {
width: 100%;
height: 30px;
border: 0;
border-radius: 7px;
background: transparent;
text-align: left;
padding: 0 8px;
font-size: 12px;
color: var(--accents-6);
cursor: pointer;
}
.select-all-option:hover {
background: #f3f4f6;
color: var(--accents-7);
}
.pagination-size-select {
min-width: 88px;
height: 28px;
border: 1px solid var(--border);
border-radius: 8px;
background: #fff;
font-size: 12px;
padding: 0 8px;
color: var(--accents-6);
}
@media (max-width: 900px) {
.pagination-bar {
flex-wrap: wrap;
row-gap: 8px;
}
.pagination-right {
margin-left: auto;
flex-wrap: wrap;
}
}
/* Elegant Badges */
+410 -42
View File
@@ -8,6 +8,8 @@ const selectedLocal = {
image: new Set(),
video: new Set()
};
const LOCAL_PAGE_SIZE_OPTIONS = [50, 100, 200, 500];
const LOCAL_PAGE_SIZE_DEFAULT = 100;
const ui = {};
const byId = (id) => document.getElementById(id);
const loadFailed = new Map();
@@ -16,8 +18,24 @@ let currentBatchAction = null;
let lastBatchAction = null;
let isLocalDeleting = false;
const cacheListState = {
image: { loaded: false, visible: false, items: [] },
video: { loaded: false, visible: false, items: [] }
image: {
loaded: false,
visible: false,
items: [],
total: 0,
page: 1,
pageSize: LOCAL_PAGE_SIZE_DEFAULT,
loading: false
},
video: {
loaded: false,
visible: false,
items: [],
total: 0,
page: 1,
pageSize: LOCAL_PAGE_SIZE_DEFAULT,
loading: false
}
};
const UI_MAP = {
imgCount: 'img-count',
@@ -30,8 +48,6 @@ const UI_MAP = {
accountTableBody: 'account-table-body',
accountEmpty: 'account-empty',
selectAll: 'select-all',
localImageSelectAll: 'local-image-select-all',
localVideoSelectAll: 'local-video-select-all',
selectedCount: 'selected-count',
batchActions: 'batch-actions',
loadBtn: 'btn-load-stats',
@@ -41,6 +57,28 @@ const UI_MAP = {
localVideoList: 'local-video-list',
localImageBody: 'local-image-body',
localVideoBody: 'local-video-body',
localImagePrev: 'local-image-prev',
localImageNext: 'local-image-next',
localImagePageInfo: 'local-image-page-info',
localImagePageSize: 'local-image-page-size',
localImageSelectWrap: 'local-image-select-wrap',
localImageSelectTrigger: 'local-image-select-trigger',
localImageSelectLabel: 'local-image-select-label',
localImageSelectCaret: 'local-image-select-caret',
localImageSelectPopover: 'local-image-select-popover',
localImageSelectPage: 'local-image-select-page',
localImageSelectAllBtn: 'local-image-select-all',
localVideoPrev: 'local-video-prev',
localVideoNext: 'local-video-next',
localVideoPageInfo: 'local-video-page-info',
localVideoPageSize: 'local-video-page-size',
localVideoSelectWrap: 'local-video-select-wrap',
localVideoSelectTrigger: 'local-video-select-trigger',
localVideoSelectLabel: 'local-video-select-label',
localVideoSelectCaret: 'local-video-select-caret',
localVideoSelectPopover: 'local-video-select-popover',
localVideoSelectPage: 'local-video-select-page',
localVideoSelectAllBtn: 'local-video-select-all',
onlineAssetsTable: 'online-assets-table',
batchProgress: 'batch-progress',
batchProgressText: 'batch-progress-text',
@@ -87,6 +125,7 @@ async function init() {
apiKey = await ensureAdminKey();
if (apiKey === null) return;
cacheUI();
setupLocalPaginationControls();
setupCacheCards();
setupConfirmDialog();
setupFailureDialog();
@@ -112,6 +151,315 @@ function cacheUI() {
ui.cacheCards = document.querySelectorAll('.cache-card');
}
function getLocalState(type) {
return cacheListState[type] || null;
}
function getLocalPaginationRefs(type) {
if (type === 'image') {
return {
prev: ui.localImagePrev,
next: ui.localImageNext,
info: ui.localImagePageInfo,
size: ui.localImagePageSize,
wrap: ui.localImageSelectWrap,
trigger: ui.localImageSelectTrigger,
label: ui.localImageSelectLabel,
caret: ui.localImageSelectCaret,
popover: ui.localImageSelectPopover,
selectPage: ui.localImageSelectPage,
selectAll: ui.localImageSelectAllBtn
};
}
return {
prev: ui.localVideoPrev,
next: ui.localVideoNext,
info: ui.localVideoPageInfo,
size: ui.localVideoPageSize,
wrap: ui.localVideoSelectWrap,
trigger: ui.localVideoSelectTrigger,
label: ui.localVideoSelectLabel,
caret: ui.localVideoSelectCaret,
popover: ui.localVideoSelectPopover,
selectPage: ui.localVideoSelectPage,
selectAll: ui.localVideoSelectAllBtn
};
}
function setupPageSizeOptions(select, selectedValue) {
if (!select) return;
const value = Number(selectedValue) || LOCAL_PAGE_SIZE_DEFAULT;
select.innerHTML = '';
LOCAL_PAGE_SIZE_OPTIONS.forEach(size => {
const option = document.createElement('option');
option.value = String(size);
option.textContent = t('cache.perPage', { size });
option.selected = size === value;
select.appendChild(option);
});
}
function updateLocalPaginationUI(type) {
const state = getLocalState(type);
if (!state) return;
const refs = getLocalPaginationRefs(type);
const total = Math.max(0, Number(state.total) || 0);
const pageSize = Math.max(1, Number(state.pageSize) || LOCAL_PAGE_SIZE_DEFAULT);
const totalPages = Math.max(1, Math.ceil(total / pageSize));
const page = Math.min(Math.max(1, Number(state.page) || 1), totalPages);
state.page = page;
state.pageSize = pageSize;
if (refs.info) {
refs.info.textContent = t('cache.pagination', {
current: page,
total: totalPages,
count: total
});
}
if (refs.prev) refs.prev.disabled = state.loading || page <= 1;
if (refs.next) refs.next.disabled = state.loading || page >= totalPages;
if (refs.size && String(refs.size.value) !== String(pageSize)) {
setupPageSizeOptions(refs.size, pageSize);
}
}
function closeLocalSelectMenu(type) {
const refs = getLocalPaginationRefs(type);
if (refs.popover) refs.popover.classList.add('hidden');
}
function closeAllLocalSelectMenus() {
closeLocalSelectMenu('image');
closeLocalSelectMenu('video');
}
function isLocalSelectMenuOpen(type) {
const refs = getLocalPaginationRefs(type);
return !!(refs.popover && !refs.popover.classList.contains('hidden'));
}
function refreshLocalSelectControl(type) {
const refs = getLocalPaginationRefs(type);
const selectedCount = selectedLocal[type]?.size || 0;
if (refs.label) {
refs.label.textContent = selectedCount > 0
? t('cache.clearSelection')
: t('common.selectAll');
}
if (refs.trigger) {
refs.trigger.classList.toggle('is-active', selectedCount > 0);
}
if (refs.caret) {
refs.caret.style.display = selectedCount > 0 ? 'none' : 'inline';
}
}
function selectLocalPage(type) {
const set = selectedLocal[type];
if (!set) return;
const items = cacheListState[type]?.items || [];
items.forEach(item => {
if (item && item.name) set.add(item.name);
});
syncLocalRowCheckboxes(type);
updateSelectedCount();
closeLocalSelectMenu(type);
}
async function fetchAllLocalNames(type) {
const names = [];
let page = 1;
const pageSize = 1000;
let total = 0;
while (true) {
const params = new URLSearchParams({
type,
page: String(page),
page_size: String(pageSize)
});
const res = await fetch(`/v1/admin/cache/list?${params.toString()}`, {
headers: buildAuthHeaders(apiKey)
});
if (!res.ok) {
throw new Error(t('common.loadFailed'));
}
const data = await res.json();
const items = Array.isArray(data.items) ? data.items : [];
total = Math.max(total, Number(data.total) || 0);
items.forEach(item => {
if (item && item.name) names.push(item.name);
});
if (names.length >= total || items.length < pageSize) break;
page += 1;
}
return names;
}
async function selectLocalAll(type) {
try {
const names = await fetchAllLocalNames(type);
const set = selectedLocal[type];
if (!set) return;
set.clear();
names.forEach(name => set.add(name));
syncLocalRowCheckboxes(type);
updateSelectedCount();
} catch (e) {
showToast(t('common.requestFailed'), 'error');
} finally {
closeLocalSelectMenu(type);
}
}
function clearLocalSelection(type) {
const set = selectedLocal[type];
if (!set) return;
if (set.size === 0) {
closeLocalSelectMenu(type);
return;
}
set.clear();
syncLocalRowCheckboxes(type);
updateSelectedCount();
closeLocalSelectMenu(type);
}
function setupLocalPaginationControls() {
const imageState = getLocalState('image');
const videoState = getLocalState('video');
setupPageSizeOptions(ui.localImagePageSize, imageState?.pageSize);
setupPageSizeOptions(ui.localVideoPageSize, videoState?.pageSize);
if (ui.localImagePrev) {
ui.localImagePrev.addEventListener('click', () => {
const state = getLocalState('image');
if (!state || state.loading) return;
if (state.page <= 1) return;
closeAllLocalSelectMenus();
loadLocalCacheList('image', { page: state.page - 1 });
});
}
if (ui.localImageNext) {
ui.localImageNext.addEventListener('click', () => {
const state = getLocalState('image');
if (!state || state.loading) return;
const totalPages = Math.max(1, Math.ceil((state.total || 0) / state.pageSize));
if (state.page >= totalPages) return;
closeAllLocalSelectMenus();
loadLocalCacheList('image', { page: state.page + 1 });
});
}
if (ui.localVideoPrev) {
ui.localVideoPrev.addEventListener('click', () => {
const state = getLocalState('video');
if (!state || state.loading) return;
if (state.page <= 1) return;
closeAllLocalSelectMenus();
loadLocalCacheList('video', { page: state.page - 1 });
});
}
if (ui.localVideoNext) {
ui.localVideoNext.addEventListener('click', () => {
const state = getLocalState('video');
if (!state || state.loading) return;
const totalPages = Math.max(1, Math.ceil((state.total || 0) / state.pageSize));
if (state.page >= totalPages) return;
closeAllLocalSelectMenus();
loadLocalCacheList('video', { page: state.page + 1 });
});
}
if (ui.localImagePageSize) {
ui.localImagePageSize.addEventListener('change', (event) => {
const state = getLocalState('image');
if (!state) return;
const size = parseInt(event.target.value, 10);
if (!Number.isFinite(size) || size <= 0) return;
state.pageSize = size;
state.page = 1;
closeAllLocalSelectMenus();
loadLocalCacheList('image', { page: 1, pageSize: size });
});
}
if (ui.localVideoPageSize) {
ui.localVideoPageSize.addEventListener('change', (event) => {
const state = getLocalState('video');
if (!state) return;
const size = parseInt(event.target.value, 10);
if (!Number.isFinite(size) || size <= 0) return;
state.pageSize = size;
state.page = 1;
closeAllLocalSelectMenus();
loadLocalCacheList('video', { page: 1, pageSize: size });
});
}
if (ui.localImageSelectTrigger) {
ui.localImageSelectTrigger.addEventListener('click', (event) => {
event.stopPropagation();
if ((selectedLocal.image?.size || 0) > 0) {
clearLocalSelection('image');
return;
}
if (isLocalSelectMenuOpen('image')) closeLocalSelectMenu('image');
else {
closeLocalSelectMenu('video');
const refs = getLocalPaginationRefs('image');
if (refs.popover) refs.popover.classList.remove('hidden');
}
});
}
if (ui.localVideoSelectTrigger) {
ui.localVideoSelectTrigger.addEventListener('click', (event) => {
event.stopPropagation();
if ((selectedLocal.video?.size || 0) > 0) {
clearLocalSelection('video');
return;
}
if (isLocalSelectMenuOpen('video')) closeLocalSelectMenu('video');
else {
closeLocalSelectMenu('image');
const refs = getLocalPaginationRefs('video');
if (refs.popover) refs.popover.classList.remove('hidden');
}
});
}
if (ui.localImageSelectPage) {
ui.localImageSelectPage.addEventListener('click', () => selectLocalPage('image'));
}
if (ui.localImageSelectAllBtn) {
ui.localImageSelectAllBtn.addEventListener('click', () => selectLocalAll('image'));
}
if (ui.localVideoSelectPage) {
ui.localVideoSelectPage.addEventListener('click', () => selectLocalPage('video'));
}
if (ui.localVideoSelectAllBtn) {
ui.localVideoSelectAllBtn.addEventListener('click', () => selectLocalAll('video'));
}
document.addEventListener('click', (event) => {
const imageWrap = ui.localImageSelectWrap;
const videoWrap = ui.localVideoSelectWrap;
if (imageWrap && imageWrap.contains(event.target)) return;
if (videoWrap && videoWrap.contains(event.target)) return;
closeAllLocalSelectMenus();
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape') {
closeAllLocalSelectMenus();
}
});
updateLocalPaginationUI('image');
updateLocalPaginationUI('video');
refreshLocalSelectControl('image');
refreshLocalSelectControl('video');
}
function ensureUI() {
if (!ui.batchActions) cacheUI();
}
@@ -461,13 +809,17 @@ async function clearCache(type) {
const state = cacheListState[type];
if (state) {
state.items = [];
state.total = 0;
state.page = 1;
state.loaded = true;
state.loading = false;
}
if (selectedLocal[type]) selectedLocal[type].clear();
if (state && state.visible) {
renderLocalCacheList(type, []);
} else {
syncLocalSelectAllState(type);
updateLocalPaginationUI(type);
updateSelectedCount();
}
loadStats();
@@ -520,18 +872,11 @@ function toggleLocalSelect(type, name, checkbox) {
}
function toggleLocalSelectAll(type, checkbox) {
const set = selectedLocal[type];
if (!set) return;
const shouldSelect = checkbox && checkbox.checked;
set.clear();
if (shouldSelect) {
const items = cacheListState[type]?.items || [];
items.forEach(item => {
if (item && item.name) set.add(item.name);
});
if (checkbox && checkbox.checked) {
selectLocalPage(type);
} else {
clearLocalSelection(type);
}
syncLocalRowCheckboxes(type);
updateSelectedCount();
}
function syncLocalRowCheckboxes(type) {
@@ -550,12 +895,7 @@ function syncLocalRowCheckboxes(type) {
}
function syncLocalSelectAllState(type) {
const selectAll = type === 'image' ? ui.localImageSelectAll : ui.localVideoSelectAll;
if (!selectAll) return;
const total = cacheListState[type]?.items?.length || 0;
const selected = selectedLocal[type]?.size || 0;
selectAll.checked = total > 0 && selected === total;
selectAll.indeterminate = selected > 0 && selected < total;
refreshLocalSelectControl(type);
}
function syncRowCheckboxes() {
@@ -584,6 +924,8 @@ function updateSelectedCount() {
const el = ui.selectedCount;
const selected = getActiveSelectedSet().size;
if (el) el.textContent = String(selected);
refreshLocalSelectControl('image');
refreshLocalSelectControl('video');
setActionButtonsState();
updateBatchActionsVisibility();
}
@@ -764,31 +1106,56 @@ async function toggleCacheList(type) {
await showCacheSection(type);
}
async function loadLocalCacheList(type) {
async function loadLocalCacheList(type, options = {}) {
const body = type === 'image' ? ui.localImageBody : ui.localVideoBody;
if (!body) return;
const state = getLocalState(type);
if (!state) return;
const pageSize = Math.max(
1,
parseInt(options.pageSize ?? state.pageSize ?? LOCAL_PAGE_SIZE_DEFAULT, 10) || LOCAL_PAGE_SIZE_DEFAULT
);
const targetPage = Math.max(1, parseInt(options.page ?? state.page ?? 1, 10) || 1);
state.loading = true;
state.pageSize = pageSize;
state.page = targetPage;
updateLocalPaginationUI(type);
body.innerHTML = `<tr><td colspan="5">${t('common.loading')}</td></tr>`;
try {
const params = new URLSearchParams({ type, page: '1', page_size: '1000' });
const params = new URLSearchParams({
type,
page: String(targetPage),
page_size: String(pageSize)
});
const res = await fetch(`/v1/admin/cache/list?${params.toString()}`, {
headers: buildAuthHeaders(apiKey)
});
if (!res.ok) {
body.innerHTML = `<tr><td colspan="5">${t('common.loadFailed')}</td></tr>`;
state.loading = false;
updateLocalPaginationUI(type);
return;
}
const data = await res.json();
const items = Array.isArray(data.items) ? data.items : [];
cacheListState[type].items = items;
cacheListState[type].loaded = true;
const keep = new Set(items.map(item => item.name));
const selected = selectedLocal[type];
Array.from(selected).forEach(name => {
if (!keep.has(name)) selected.delete(name);
});
const total = Math.max(0, Number(data.total) || 0);
const totalPages = Math.max(1, Math.ceil(total / pageSize));
if (total > 0 && targetPage > totalPages) {
state.loading = false;
await loadLocalCacheList(type, { page: totalPages, pageSize });
return;
}
state.items = items;
state.total = total;
state.page = Math.min(targetPage, totalPages);
state.pageSize = pageSize;
state.loaded = true;
state.loading = false;
renderLocalCacheList(type, items);
} catch (e) {
body.innerHTML = `<tr><td colspan="5">${t('common.loadFailed')}</td></tr>`;
state.loading = false;
updateLocalPaginationUI(type);
}
}
@@ -798,6 +1165,8 @@ function renderLocalCacheList(type, items) {
if (!items || items.length === 0) {
body.innerHTML = `<tr><td colspan="5" class="table-empty">${t('cache.noFiles')}</td></tr>`;
syncLocalSelectAllState(type);
updateLocalPaginationUI(type);
updateSelectedCount();
return;
}
const selected = selectedLocal[type];
@@ -826,6 +1195,8 @@ function renderLocalCacheList(type, items) {
img.src = item.preview_url;
img.alt = '';
img.className = 'cache-preview';
img.loading = 'lazy';
img.decoding = 'async';
nameWrap.appendChild(img);
}
const nameText = document.createElement('span');
@@ -870,6 +1241,7 @@ function renderLocalCacheList(type, items) {
});
body.replaceChildren(fragment);
syncLocalSelectAllState(type);
updateLocalPaginationUI(type);
updateSelectedCount();
}
@@ -885,12 +1257,11 @@ async function deleteLocalFile(type, name) {
const okDelete = await requestDeleteLocalFile(type, name);
if (!okDelete) return;
showToast(t('common.deleteSuccess'), 'success');
const state = cacheListState[type];
if (state && Array.isArray(state.items)) {
state.items = state.items.filter(item => item.name !== name);
state.loaded = true;
const state = getLocalState(type);
if (state) {
selectedLocal[type]?.delete(name);
if (state.visible) renderLocalCacheList(type, state.items);
if (state.total > 0) state.total -= 1;
await loadLocalCacheList(type, { page: state.page, pageSize: state.pageSize });
}
await loadStats();
}
@@ -936,14 +1307,11 @@ async function deleteSelectedLocal(type) {
}
});
}
const state = cacheListState[type];
if (state && Array.isArray(state.items)) {
const toRemove = new Set(names);
state.items = state.items.filter(item => !toRemove.has(item.name));
state.loaded = true;
}
const state = getLocalState(type);
selectedLocal[type].clear();
if (state && state.visible) renderLocalCacheList(type, state.items);
if (state) {
await loadLocalCacheList(type, { page: state.page, pageSize: state.pageSize });
}
await loadStats();
isLocalDeleting = false;
setActionButtonsState();
+8 -1
View File
@@ -94,7 +94,8 @@ const LOCALE_MAP = {
"label": "视频配置",
"concurrent": { title: "并发上限", desc: "Reverse 接口并发上限。" },
"timeout": { title: "请求超时", desc: "Reverse 接口超时时间(秒)。" },
"stream_timeout": { title: "流空闲超时", desc: "流式空闲超时时间(秒)。" }
"stream_timeout": { title: "流空闲超时", desc: "流式空闲超时时间(秒)。" },
"upscale_timing": { title: "超分时机", desc: "Basic 号池 720p 超分模式:single 为每轮扩展后超分,complete 为全部扩展后再超分。" }
},
@@ -486,6 +487,12 @@ function buildFieldCard(section, key, val) {
{ val: 'url', text: 'URL' }
]);
}
else if (section === 'video' && key === 'upscale_timing') {
built = buildSelectInput(section, key, val, [
{ val: 'single', text: 'single' },
{ val: 'complete', text: 'complete' }
]);
}
else if (section === 'imagine_fast' && key === 'size') {
built = buildSelectInput(section, key, val, [
{ val: '1024x1024', text: '1024x1024 (1:1)' },
+91
View File
@@ -111,6 +111,8 @@ async function init() {
if (apiKey === null) return;
setupEditPoolDefaults();
setupConfirmDialog();
setupSelectAllMenu();
refreshPageSizeOptionsI18n();
loadData();
}
@@ -351,12 +353,66 @@ function toggleSelectAll() {
updateSelectionState();
}
function closeSelectAllMenu() {
const popover = byId('select-all-popover');
if (popover) popover.classList.add('hidden');
}
function openSelectAllMenu() {
const popover = byId('select-all-popover');
if (popover) popover.classList.remove('hidden');
}
function isSelectAllMenuOpen() {
const popover = byId('select-all-popover');
return !!(popover && !popover.classList.contains('hidden'));
}
function setupSelectAllMenu() {
document.addEventListener('click', (event) => {
const wrap = byId('select-all-wrap');
if (!wrap) return;
if (wrap.contains(event.target)) return;
closeSelectAllMenu();
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape') {
closeSelectAllMenu();
}
});
}
function handleSelectAllPrimary(event) {
if (event) event.stopPropagation();
const selected = countSelected(flatTokens);
if (selected > 0) {
clearAllSelection();
return;
}
if (isSelectAllMenuOpen()) {
closeSelectAllMenu();
} else {
openSelectAllMenu();
}
}
function selectVisibleAllFromMenu() {
selectVisibleAll();
closeSelectAllMenu();
}
function selectAllFilteredFromMenu() {
selectAllFiltered();
closeSelectAllMenu();
}
function selectAllFiltered() {
const filtered = getFilteredTokens();
if (filtered.length === 0) return;
setSelectedForTokens(filtered, true);
syncVisibleSelectionUI(true);
updateSelectionState();
closeSelectAllMenu();
}
function selectVisibleAll() {
@@ -365,6 +421,7 @@ function selectVisibleAll() {
setSelectedForTokens(visible, true);
syncVisibleSelectionUI(true);
updateSelectionState();
closeSelectAllMenu();
}
function clearAllSelection() {
@@ -372,6 +429,7 @@ function clearAllSelection() {
setSelectedForTokens(flatTokens, false);
syncVisibleSelectionUI(false);
updateSelectionState();
closeSelectAllMenu();
}
function toggleSelect(index) {
@@ -394,6 +452,23 @@ function updateSelectionState() {
}
const selectedCountEl = byId('selected-count');
if (selectedCountEl) selectedCountEl.innerText = selectedCount;
const selectAllLabel = byId('select-all-label');
const selectAllTrigger = byId('select-all-trigger');
const selectAllCaret = byId('select-all-caret');
if (selectAllLabel) {
selectAllLabel.textContent = selectedCount > 0
? t('token.clearSelection')
: t('common.selectAll');
}
if (selectAllTrigger) {
selectAllTrigger.classList.toggle('is-active', selectedCount > 0);
}
if (selectAllCaret) {
selectAllCaret.style.display = selectedCount > 0 ? 'none' : 'inline';
}
if (selectedCount > 0) {
closeSelectAllMenu();
}
setActionButtonsState(selectedCount);
}
@@ -999,6 +1074,7 @@ function escapeHtml(text) {
function filterByStatus(status) {
currentFilter = status;
currentPage = 1;
closeSelectAllMenu();
// 更新 Tab 样式和 ARIA
document.querySelectorAll('.tab-item').forEach(tab => {
@@ -1043,12 +1119,24 @@ function getVisibleTokens() {
return getPaginationData().visibleTokens;
}
function refreshPageSizeOptionsI18n() {
const sizeSelect = byId('page-size');
if (!sizeSelect) return;
Array.from(sizeSelect.options).forEach((opt) => {
const size = parseInt(opt.value, 10);
if (!Number.isFinite(size)) return;
opt.textContent = t('token.perPage', { size });
});
}
function updatePaginationControls(totalCount, totalPages) {
const info = byId('pagination-info');
const prevBtn = byId('page-prev');
const nextBtn = byId('page-next');
const sizeSelect = byId('page-size');
refreshPageSizeOptionsI18n();
if (sizeSelect && String(sizeSelect.value) !== String(pageSize)) {
sizeSelect.value = String(pageSize);
}
@@ -1063,6 +1151,7 @@ function updatePaginationControls(totalCount, totalPages) {
function goPrevPage() {
if (currentPage <= 1) return;
currentPage -= 1;
closeSelectAllMenu();
renderTable();
}
@@ -1071,6 +1160,7 @@ function goNextPage() {
const totalPages = Math.max(1, Math.ceil(totalCount / pageSize));
if (currentPage >= totalPages) return;
currentPage += 1;
closeSelectAllMenu();
renderTable();
}
@@ -1080,6 +1170,7 @@ function changePageSize() {
if (!value || value === pageSize) return;
pageSize = value;
currentPage = 1;
closeSelectAllMenu();
renderTable();
}
+97 -37
View File
@@ -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.0" rel="stylesheet">
<link href="/static/admin/css/cache.css?v=1.6.0" 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/toast.css" rel="stylesheet">
</head>
@@ -88,39 +88,99 @@
<div id="local-cache-lists" class="space-y-4 hidden">
<div id="local-image-list" class="cache-list hidden">
<div class="rounded-lg overflow-hidden bg-white overflow-x-auto">
<table class="geist-table min-w-[600px]">
<thead>
<tr>
<th class="w-10 text-center">
<input id="local-image-select-all" type="checkbox" class="checkbox" onchange="toggleLocalSelectAll('image', this)">
</th>
<th class="w-108 text-left" data-i18n="cache.tableFile">文件</th>
<th class="w-32 text-left" data-i18n="cache.tableSize">大小</th>
<th class="w-48 text-left" data-i18n="cache.tableTime">时间</th>
<th class="w-24 text-center" data-i18n="cache.tableActions">操作</th>
</tr>
</thead>
<tbody id="local-image-body"></tbody>
</table>
<div class="cache-table-shell">
<div class="cache-pagination">
<div class="cache-pagination-left">
<button id="local-image-prev" type="button" class="cache-pagination-icon-btn" aria-label="上一页">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="15 18 9 12 15 6"></polyline>
</svg>
</button>
<div id="local-image-page-info" class="cache-pagination-info"></div>
<button id="local-image-next" type="button" class="cache-pagination-icon-btn" aria-label="下一页">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
</button>
</div>
<div class="cache-pagination-right">
<div id="local-image-select-wrap" class="cache-select-menu-wrap">
<button id="local-image-select-trigger" type="button" class="cache-pagination-action-btn">
<span id="local-image-select-label" data-i18n="common.selectAll">全选</span>
<svg id="local-image-select-caret" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="6 9 12 15 18 9"></polyline>
</svg>
</button>
<div id="local-image-select-popover" class="cache-select-all-popover hidden">
<button id="local-image-select-page" type="button" class="cache-select-all-option" data-i18n="cache.selectPage">全选本页</button>
<button id="local-image-select-all" type="button" class="cache-select-all-option" data-i18n="cache.selectAllFiles">全选全部</button>
</div>
</div>
<select id="local-image-page-size" class="cache-pagination-select"></select>
</div>
</div>
<div class="overflow-x-auto">
<table class="geist-table min-w-[600px]">
<thead>
<tr>
<th class="w-10 text-center"></th>
<th class="w-108 text-left" data-i18n="cache.tableFile">文件</th>
<th class="w-32 text-left" data-i18n="cache.tableSize">大小</th>
<th class="w-48 text-left" data-i18n="cache.tableTime">时间</th>
<th class="w-24 text-center" data-i18n="cache.tableActions">操作</th>
</tr>
</thead>
<tbody id="local-image-body"></tbody>
</table>
</div>
</div>
</div>
<div id="local-video-list" class="cache-list hidden">
<div class="rounded-lg overflow-hidden bg-white overflow-x-auto">
<table class="geist-table min-w-[600px]">
<thead>
<tr>
<th class="w-10 text-center">
<input id="local-video-select-all" type="checkbox" class="checkbox" onchange="toggleLocalSelectAll('video', this)">
</th>
<th class="w-108 text-left" data-i18n="cache.tableFile">文件</th>
<th class="w-32 text-left" data-i18n="cache.tableSize">大小</th>
<th class="w-48 text-left" data-i18n="cache.tableTime">时间</th>
<th class="w-24 text-center" data-i18n="cache.tableActions">操作</th>
</tr>
</thead>
<tbody id="local-video-body"></tbody>
</table>
<div class="cache-table-shell">
<div class="cache-pagination">
<div class="cache-pagination-left">
<button id="local-video-prev" type="button" class="cache-pagination-icon-btn" aria-label="上一页">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="15 18 9 12 15 6"></polyline>
</svg>
</button>
<div id="local-video-page-info" class="cache-pagination-info"></div>
<button id="local-video-next" type="button" class="cache-pagination-icon-btn" aria-label="下一页">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
</button>
</div>
<div class="cache-pagination-right">
<div id="local-video-select-wrap" class="cache-select-menu-wrap">
<button id="local-video-select-trigger" type="button" class="cache-pagination-action-btn">
<span id="local-video-select-label" data-i18n="common.selectAll">全选</span>
<svg id="local-video-select-caret" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="6 9 12 15 18 9"></polyline>
</svg>
</button>
<div id="local-video-select-popover" class="cache-select-all-popover hidden">
<button id="local-video-select-page" type="button" class="cache-select-all-option" data-i18n="cache.selectPage">全选本页</button>
<button id="local-video-select-all" type="button" class="cache-select-all-option" data-i18n="cache.selectAllFiles">全选全部</button>
</div>
</div>
<select id="local-video-page-size" class="cache-pagination-select"></select>
</div>
</div>
<div class="overflow-x-auto">
<table class="geist-table min-w-[600px]">
<thead>
<tr>
<th class="w-10 text-center"></th>
<th class="w-108 text-left" data-i18n="cache.tableFile">文件</th>
<th class="w-32 text-left" data-i18n="cache.tableSize">大小</th>
<th class="w-48 text-left" data-i18n="cache.tableTime">时间</th>
<th class="w-24 text-center" data-i18n="cache.tableActions">操作</th>
</tr>
</thead>
<tbody id="local-video-body"></tbody>
</table>
</div>
</div>
</div>
</div>
@@ -197,12 +257,12 @@
</dialog>
<script src="/static/i18n/i18n.js"></script>
<script src="/static/common/js/admin-auth.js?v=1.6.0"></script>
<script src="/static/common/js/batch-sse.js?v=1.6.0"></script>
<script src="/static/common/js/header.js?v=1.6.0"></script>
<script src="/static/common/js/footer.js?v=1.6.0"></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/toast.js"></script>
<script src="/static/admin/js/cache.js?v=1.6.0"></script>
<script src="/static/admin/js/cache.js?v=1.6.1"></script>
<script src="/static/common/js/draggable.js"></script>
</body>
+6 -6
View File
@@ -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.0" rel="stylesheet">
<link href="/static/admin/css/config.css?v=1.6.0" 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/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.0"></script>
<script src="/static/common/js/header.js?v=1.6.0"></script>
<script src="/static/common/js/footer.js?v=1.6.0"></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/toast.js"></script>
<script src="/static/admin/js/config.js?v=1.6.0"></script>
<script src="/static/admin/js/config.js?v=1.6.1"></script>
</body>
</html>
+5 -5
View File
@@ -24,8 +24,8 @@
}
}
</script>
<link href="/static/common/css/common.css?v=1.6.0" rel="stylesheet">
<link href="/static/common/css/login.css?v=1.6.0" rel="stylesheet">
<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/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.0"></script>
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
<script src="/static/common/js/toast.js"></script>
<script src="/static/common/js/footer.js?v=1.6.0"></script>
<script src="/static/admin/js/login.js?v=1.6.0"></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>
</body>
</html>
+65 -46
View File
@@ -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.0" rel="stylesheet">
<link href="/static/admin/css/token.css?v=1.6.0" 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/toast.css" rel="stylesheet">
</head>
@@ -119,51 +119,70 @@
</button>
</div>
<!-- Token Table -->
<div class="rounded-lg overflow-hidden bg-white mb-4 overflow-x-auto">
<table class="geist-table min-w-[800px]">
<thead>
<tr>
<th class="w-10"><input type="checkbox" id="select-all" class="checkbox" onclick="toggleSelectAll()"></th>
<th class="w-48 text-left" data-i18n="token.tableToken">Token</th>
<th class="w-24" data-i18n="token.tableType">类型</th>
<th class="w-24" data-i18n="token.tableStatus">状态</th>
<th class="w-20" data-i18n="token.tableQuota">额度</th>
<th class="text-left" data-i18n="token.tableNote">备注</th>
<th class="w-44 text-center" data-i18n="token.tableActions">操作</th>
</tr>
</thead>
<tbody id="token-table-body">
<!-- Dynamic Rows -->
</tbody>
</table>
<div class="token-table-shell rounded-lg overflow-hidden bg-white mb-4">
<!-- Pagination -->
<div class="pagination-bar">
<div class="pagination-left">
<button id="page-prev" type="button" class="pagination-icon-btn" onclick="goPrevPage()" aria-label="上一页">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="15 18 9 12 15 6"></polyline>
</svg>
</button>
<div id="pagination-info" class="pagination-info">第 0 / 0 页 · 共 0 条</div>
<button id="page-next" type="button" class="pagination-icon-btn" onclick="goNextPage()" aria-label="下一页">
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="9 18 15 12 9 6"></polyline>
</svg>
</button>
</div>
<div class="pagination-right">
<div id="select-all-wrap" class="select-menu-wrap">
<button id="select-all-trigger" type="button" class="pagination-action-btn" onclick="handleSelectAllPrimary(event)">
<span id="select-all-label" data-i18n="common.selectAll">全选</span>
<svg id="select-all-caret" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<polyline points="6 9 12 15 18 9"></polyline>
</svg>
</button>
<div id="select-all-popover" class="select-all-popover hidden">
<button type="button" class="select-all-option" onclick="selectVisibleAllFromMenu()" data-i18n="token.selectPage">全选本页</button>
<button type="button" class="select-all-option" onclick="selectAllFilteredFromMenu()" data-i18n="token.selectAllFiltered">全选全部</button>
</div>
</div>
<select id="page-size" class="pagination-size-select" onchange="changePageSize()">
<option value="20">20 / 页</option>
<option value="50" selected>50 / 页</option>
<option value="100">100 / 页</option>
<option value="200">200 / 页</option>
<option value="500">500 / 页</option>
<option value="1000">1000 / 页</option>
<option value="2000">2000 / 页</option>
</select>
</div>
</div>
<div class="overflow-x-auto">
<table class="geist-table min-w-[860px]">
<thead>
<tr>
<th class="w-10"><input type="checkbox" id="select-all" class="checkbox" onclick="toggleSelectAll()"></th>
<th class="w-56 text-left" data-i18n="token.tableToken">Token</th>
<th class="w-24" data-i18n="token.tableType">类型</th>
<th class="w-24" data-i18n="token.tableStatus">状态</th>
<th class="w-20" data-i18n="token.tableQuota">额度</th>
<th class="text-left" data-i18n="token.tableNote">备注</th>
<th class="w-44 text-center" data-i18n="token.tableActions">操作</th>
</tr>
</thead>
<tbody id="token-table-body">
<!-- Dynamic Rows -->
</tbody>
</table>
</div>
<div id="loading" class="text-center py-12 text-[var(--accents-4)]" data-i18n="common.loading">加载中...</div>
<div id="empty-state" class="hidden table-empty" data-i18n="token.emptyState">
暂无 Token,请点击右上角导入或添加。
</div>
</div>
<!-- Pagination -->
<div class="pagination-bar">
<div id="pagination-info" class="text-xs text-[var(--accents-5)]">第 0 / 0 页 · 共 0 条</div>
<div class="flex items-center gap-2">
<button class="geist-button-outline text-xs px-3" onclick="selectVisibleAll()" data-i18n="token.selectPage">全选本页</button>
<button class="geist-button-outline text-xs px-3" onclick="selectAllFiltered()" data-i18n="token.selectAllFiltered">全选全部</button>
<button class="geist-button-outline text-xs px-3" onclick="clearAllSelection()" data-i18n="token.clearSelection">取消全选</button>
<button id="page-prev" class="geist-button-outline text-xs px-3" onclick="goPrevPage()" data-i18n="token.prevPage">上一页</button>
<button id="page-next" class="geist-button-outline text-xs px-3" onclick="goNextPage()" data-i18n="token.nextPage">下一页</button>
<select id="page-size" class="geist-input h-[30px]" onchange="changePageSize()">
<option value="20">20 / 页</option>
<option value="50" selected>50 / 页</option>
<option value="100">100 / 页</option>
<option value="200">200 / 页</option>
<option value="500">500 / 页</option>
<option value="1000">1000 / 页</option>
<option value="2000">2000 / 页</option>
</select>
</div>
</div>
<!-- Batch Actions Bar (Floating Bottom) -->
</div>
@@ -304,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.0"></script>
<script src="/static/common/js/batch-sse.js?v=1.6.0"></script>
<script src="/static/common/js/header.js?v=1.6.0"></script>
<script src="/static/common/js/footer.js?v=1.6.0"></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/toast.js"></script>
<script src="/static/admin/js/token.js?v=1.6.0"></script>
<script src="/static/admin/js/token.js?v=1.6.1"></script>
</body>
</html>
+1 -1
View File
@@ -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.0');
const res = await fetch('/static/common/html/footer.html?v=1.6.1');
if (!res.ok) return;
container.innerHTML = await res.text();
} catch (e) {
+1 -1
View File
@@ -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.0');
const res = await fetch('/static/common/html/function-header.html?v=1.6.1');
if (!res.ok) return;
container.innerHTML = await res.text();
const logoutBtn = container.querySelector('#function-logout-btn');
+1 -1
View File
@@ -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.0');
const res = await fetch('/static/common/html/header.html?v=1.6.1');
if (!res.ok) return;
container.innerHTML = await res.text();
const path = window.location.pathname;
+25
View File
@@ -395,6 +395,31 @@
}
progressBuffer += text;
const roundMatches = [...progressBuffer.matchAll(/\[round=(\d+)\/(\d+)\]\s*progress=([0-9]+(?:\.[0-9]+)?)%/g)];
if (roundMatches.length) {
const last = roundMatches[roundMatches.length - 1];
const round = parseInt(last[1], 10);
const total = parseInt(last[2], 10);
const value = parseFloat(last[3]);
setIndeterminate(false);
updateProgress(value);
if (progressText && Number.isFinite(round) && Number.isFinite(total) && total > 0) {
progressText.textContent = `${Math.round(value)}% · ${round}/${total}`;
}
progressBuffer = progressBuffer.slice(Math.max(0, progressBuffer.length - 300));
return;
}
const genericProgressMatches = [...progressBuffer.matchAll(/progress=([0-9]+(?:\.[0-9]+)?)%/g)];
if (genericProgressMatches.length) {
const last = genericProgressMatches[genericProgressMatches.length - 1];
const value = parseFloat(last[1]);
setIndeterminate(false);
updateProgress(value);
progressBuffer = progressBuffer.slice(Math.max(0, progressBuffer.length - 240));
return;
}
const matches = [...progressBuffer.matchAll(/进度\s*(\d+)%/g)];
if (matches.length) {
const last = matches[matches.length - 1];
+6 -6
View File
@@ -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.0" rel="stylesheet">
<link href="/static/function/css/chat.css?v=1.6.0" 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/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.0"></script>
<script src="/static/common/js/function-header.js?v=1.6.0"></script>
<script src="/static/common/js/footer.js?v=1.6.0"></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/toast.js"></script>
<script src="/static/function/js/chat.js?v=1.6.0"></script>
<script src="/static/function/js/chat.js?v=1.6.1"></script>
</body>
</html>
+6 -6
View File
@@ -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.0" rel="stylesheet">
<link href="/static/function/css/imagine.css?v=1.6.0" 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/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.0"></script>
<script src="/static/common/js/function-header.js?v=1.6.0"></script>
<script src="/static/common/js/footer.js?v=1.6.0"></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/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.0"></script>
<script src="/static/function/js/imagine.js?v=1.6.1"></script>
</body>
</html>
+5 -5
View File
@@ -24,8 +24,8 @@
}
}
</script>
<link href="/static/common/css/common.css?v=1.6.0" rel="stylesheet">
<link href="/static/common/css/login.css?v=1.6.0" rel="stylesheet">
<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/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.0"></script>
<script src="/static/common/js/admin-auth.js?v=1.6.1"></script>
<script src="/static/common/js/toast.js"></script>
<script src="/static/common/js/footer.js?v=1.6.0"></script>
<script src="/static/function/js/login.js?v=1.6.0"></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>
</body>
</html>
+6 -6
View File
@@ -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.0" rel="stylesheet">
<link href="/static/function/css/video.css?v=1.6.0" 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/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.0"></script>
<script src="/static/common/js/function-header.js?v=1.6.0"></script>
<script src="/static/common/js/footer.js?v=1.6.0"></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/toast.js"></script>
<script src="/static/function/js/video.js?v=1.6.0"></script>
<script src="/static/function/js/video.js?v=1.6.1"></script>
</body>
</html>
+6 -6
View File
@@ -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.0" rel="stylesheet">
<link href="/static/function/css/voice.css?v=1.6.0" 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/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.0"></script>
<script src="/static/common/js/function-header.js?v=1.6.0"></script>
<script src="/static/common/js/footer.js?v=1.6.0"></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/toast.js"></script>
<script src="/static/function/js/voice.js?v=1.6.0"></script>
<script src="/static/function/js/voice.js?v=1.6.1"></script>
</body>
</html>
+11 -1
View File
@@ -24,6 +24,7 @@
"waitTaskFinish": "Please wait for the current task to finish",
"pause": "Pause",
"stop": "Stop",
"selectAll": "Select all",
"selected": "Selected",
"items": "items",
"export": "Export",
@@ -172,7 +173,8 @@
"video": {
"concurrent": {"title": "Concurrency Limit", "desc": "Reverse API concurrency limit."},
"timeout": {"title": "Request Timeout", "desc": "Reverse API timeout (seconds)."},
"stream_timeout": {"title": "Stream Idle Timeout", "desc": "Streaming idle timeout (seconds)."}
"stream_timeout": {"title": "Stream Idle Timeout", "desc": "Streaming idle timeout (seconds)."},
"upscale_timing": {"title": "Upscale Timing", "desc": "Basic pool 720p upscale mode: single upscales after each extension round, complete upscales once after all rounds."}
},
"image": {
"timeout": {"title": "Request Timeout", "desc": "WebSocket request timeout (seconds)."},
@@ -333,6 +335,14 @@
"tableType": "Type",
"tableAssetCount": "Asset Count",
"tableLastClear": "Last Cleared",
"selectPage": "Select page",
"selectAllFiles": "Select all",
"clearSelection": "Clear selection",
"prevPage": "Prev",
"nextPage": "Next",
"perPageLabel": "Per page",
"perPage": "{size} / page",
"pagination": "Page {current} / {total} · {count} items",
"notLoaded": "Not loaded",
"noAccounts": "No accounts available",
"noFiles": "No files",
+11 -1
View File
@@ -24,6 +24,7 @@
"waitTaskFinish": "请等待当前任务结束",
"pause": "暂停",
"stop": "终止",
"selectAll": "全选",
"selected": "已选择",
"items": "项",
"export": "导出",
@@ -172,7 +173,8 @@
"video": {
"concurrent": {"title": "并发上限", "desc": "Reverse 接口并发上限。"},
"timeout": {"title": "请求超时", "desc": "Reverse 接口超时时间(秒)。"},
"stream_timeout": {"title": "流空闲超时", "desc": "流式空闲超时时间(秒)。"}
"stream_timeout": {"title": "流空闲超时", "desc": "流式空闲超时时间(秒)。"},
"upscale_timing": {"title": "超分时机", "desc": "Basic 号池 720p 超分模式:single 为每轮扩展后超分,complete 为全部扩展完成后再超分。"}
},
"image": {
"timeout": {"title": "请求超时", "desc": "WebSocket 请求超时时间(秒)。"},
@@ -333,6 +335,14 @@
"tableType": "类型",
"tableAssetCount": "资产数",
"tableLastClear": "上次清空时间",
"selectPage": "全选本页",
"selectAllFiles": "全选全部",
"clearSelection": "取消全选",
"prevPage": "上一页",
"nextPage": "下一页",
"perPageLabel": "每页",
"perPage": "{size} / 页",
"pagination": "第 {current} / {total} 页 · 共 {count} 条",
"notLoaded": "未加载",
"noAccounts": "暂无可用账号",
"noFiles": "暂无文件",
+9 -3
View File
@@ -91,12 +91,18 @@ class AuthenticationException(AppException):
class UpstreamException(AppException):
"""上游服务错误"""
def __init__(self, message: str, details: Any = None):
def __init__(
self,
message: str,
details: Any = None,
status_code: int = 502,
code: str = "upstream_error",
):
super().__init__(
message=message,
error_type=ErrorType.SERVER.value,
code="upstream_error",
status_code=502,
code=code,
status_code=status_code,
)
self.details = details
File diff suppressed because it is too large. Load diff
+4
View File
@@ -148,6 +148,10 @@ concurrent = 100
timeout = 60
# 流式空闲超时时间(秒)
stream_timeout = 60
# Basic 号池视频超分模式
# single: 单次扩展完成后超分(速度更慢,效果更好)
# complete: 所有扩展完成后超分(速度更快,效果更差)
upscale_timing = "complete"
# ==================== 语音配置 ====================
[voice]
+49 -3
View File
@@ -164,7 +164,7 @@ curl http://localhost:8000/v1/chat/completions \
| `parallel_tool_calls` | boolean | Allow parallel tool calls | `true`, `false` |
| `video_config` | object | **Video model only** | Supported: `grok-imagine-1.0-video` |
| └─ `aspect_ratio` | string | Video aspect ratio | `16:9`, `9:16`, `1:1`, `2:3`, `3:2`, `1280x720`, `720x1280`, `1792x1024`, `1024x1792`, `1024x1024` |
| └─ `video_length` | integer | Video length (seconds) | `6`, `10`, `15` |
| └─ `video_length` | integer | Video length (seconds) | `6` ~ `30` |
| └─ `resolution_name` | string | Resolution | `480p`, `720p` |
| └─ `preset` | string | Style preset | `fun`, `normal`, `spicy`, `custom` |
| `image_config` | object | **Image models only** | Supported: `grok-imagine-1.0` / `grok-imagine-1.0-fast` / `grok-imagine-1.0-edit` |
@@ -333,6 +333,51 @@ curl http://localhost:8000/v1/images/edits \
<br>
### `POST /v1/videos`
> Video generation endpoint (OpenAI videos.create compatible)
```bash
curl http://localhost:8000/v1/videos \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GROK2API_API_KEY" \
-d '{
"model": "grok-imagine-1.0-video",
"prompt": "Neon rainy street at night, cinematic slow tracking shot",
"size": "1792x1024",
"seconds": 18,
"quality": "standard"
}'
```
<details>
<summary>Supported request parameters</summary>
<br>
| Field | Type | Description | Allowed values |
| :-- | :-- | :-- | :-- |
| `model` | string | Video model | `grok-imagine-1.0-video` |
| `prompt` | string | Video prompt | - |
| `size` | string | Frame size (mapped to aspect_ratio) | `1280x720`, `720x1280`, `1792x1024`, `1024x1792`, `1024x1024` |
| `seconds` | integer | Target duration (seconds) | `6` ~ `30` |
| `quality` | string | Video quality (mapped to resolution) | `standard`, `high` |
| `image_reference` | object/string | Reference image (optional) | `{"image_url":"https://..."}` or Data URI |
| `input_reference` | file | multipart reference image (optional) | `png`, `jpg`, `webp` |
**Notes**:
- Server-side chain extension now supports 6~30 seconds automatically, so **`/v1/video/extend` is not required**.
- `quality=standard` maps to `480p`; `quality=high` maps to `720p`.
- For basic-pool requests at `720p`, generation falls back to `480p` first, then upscales according to `video.upscale_timing`.
- If both `image_reference` and `input_reference` are provided, references are processed in order; the video pipeline uses the first image only.
<br>
</details>
<br>
## Configuration
Config file: `data/config.toml`
@@ -350,8 +395,8 @@ Config file: `data/config.toml`
| **app** | `app_url` | App URL | External base URL used for file links. | `""` |
| | `app_key` | Admin password | Login password for admin panel. | `grok2api` |
| | `api_key` | API key | Optional API key for access (comma-separated string or array). | `""` |
| | `public_enabled` | Public mode | Enable public features. | `false` |
| | `public_key` | Public key | Public access key (optional). | `""` |
| | `function_enabled` | Function mode | Enable function pages/features. | `false` |
| | `function_key` | Function key | Access key for function endpoints/pages (optional). | `""` |
| | `image_format` | Image format | `url` or `base64`. | `url` |
| | `video_format` | Video format | `html` or `url` (processed link). | `html` |
| | `temporary` | Temporary chat | Enable temporary chat mode. | `true` |
@@ -406,6 +451,7 @@ Config file: `data/config.toml`
| **video** | `concurrent` | Concurrency | Reverse video concurrency limit. | `100` |
| | `timeout` | Timeout | Reverse video timeout (seconds). | `60` |
| | `stream_timeout` | Stream timeout | Stream idle timeout (seconds). | `60` |
| | `upscale_timing` | Upscale timing | Basic-pool 720p upscale mode: `single` (after each extension round) / `complete` (after all rounds). | `complete` |
| **voice** | `timeout` | Timeout | Voice request timeout (seconds). | `60` |
| **asset** | `upload_concurrent` | Upload concurrency | Upload concurrency. | `100` |
| | `upload_timeout` | Upload timeout | Upload timeout (seconds). | `60` |
+1 -1
View File
@@ -1,6 +1,6 @@
[project]
name = "grok2api"
version = "1.6.0"
version = "1.6.1"
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"
+49 -3
View File
@@ -164,7 +164,7 @@ curl http://localhost:8000/v1/chat/completions \
| `parallel_tool_calls` | boolean | 是否允许并行工具调用 | `true`, `false` |
| `video_config` | object | **视频模型专用配置对象** | 支持:`grok-imagine-1.0-video` |
| └─`aspect_ratio` | string | 视频宽高比 | `16:9`, `9:16`, `1:1`, `2:3`, `3:2`, `1280x720`, `720x1280`, `1792x1024`, `1024x1792`, `1024x1024` |
| └─`video_length` | integer | 视频时长 (秒) | `6`, `10`, `15` |
| └─`video_length` | integer | 视频时长 (秒) | `6` ~ `30` |
| └─`resolution_name` | string | 分辨率 | `480p`, `720p` |
| └─`preset` | string | 风格预设 | `fun`, `normal`, `spicy`, `custom` |
| `image_config` | object | **图片模型专用配置对象** | 支持:`grok-imagine-1.0` / `grok-imagine-1.0-fast` / `grok-imagine-1.0-edit` |
@@ -334,6 +334,51 @@ curl http://localhost:8000/v1/images/edits \
<br>
### `POST /v1/videos`
> 视频生成接口(OpenAI videos.create 兼容)
```bash
curl http://localhost:8000/v1/videos \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $GROK2API_API_KEY" \
-d '{
"model": "grok-imagine-1.0-video",
"prompt": "霓虹雨夜街头,慢镜头追拍",
"size": "1792x1024",
"seconds": 18,
"quality": "standard"
}'
```
<details>
<summary>支持的请求参数</summary>
<br>
| 字段 | 类型 | 说明 | 可用参数 |
| :-- | :-- | :-- | :-- |
| `model` | string | 视频模型名 | `grok-imagine-1.0-video` |
| `prompt` | string | 视频提示词 | - |
| `size` | string | 画面比例(会映射到 aspect_ratio) | `1280x720`, `720x1280`, `1792x1024`, `1024x1792`, `1024x1024` |
| `seconds` | integer | 目标时长(秒) | `6` ~ `30` |
| `quality` | string | 视频质量(映射到 resolution) | `standard`, `high` |
| `image_reference` | object/string | 参考图(可选) | `{"image_url":"https://..."}` 或 Data URI |
| `input_reference` | file | multipart 参考图(可选) | `png`, `jpg`, `webp` |
**注意事项**:
- 服务端已支持 6~30 秒自动链式扩展,**无需使用 `/v1/video/extend`**。
- `quality=standard` 对应 `480p`;`quality=high` 对应 `720p`。
- 基础号池请求 `720p` 时会先产出 `480p` 再按 `video.upscale_timing` 执行超分。
- `image_reference` 与 `input_reference` 同时传入时,会按顺序作为参考图输入;视频链路只使用第 1 张。
<br>
</details>
<br>
## 参数配置
配置文件:`data/config.toml`
@@ -351,8 +396,8 @@ curl http://localhost:8000/v1/images/edits \
| **app** | `app_url` | 应用地址 | 当前 Grok2API 服务的外部访问 URL,用于文件链接访问。 | `""` |
| | `app_key` | 后台密码 | 登录 Grok2API 管理后台的密码(必填)。 | `grok2api` |
| | `api_key` | API 密钥 | 调用 Grok2API 服务的 Token(可选,支持逗号分隔或数组)。 | `""` |
| | `public_enabled` | Public 开关 | 是否启用 public 功能玩法。 | `false` |
| | `public_key` | Public 密钥 | Public 调用密钥(可选)。 | `""` |
| | `function_enabled` | Function 开关 | 是否启用 function 功能玩法。 | `false` |
| | `function_key` | Function 密钥 | Function 调用密钥(可选)。 | `""` |
| | `image_format` | 图片格式 | 生成的图片格式(url 或 base64)。 | `url` |
| | `video_format` | 视频格式 | 生成的视频格式(html 或 url,url 为处理后的链接)。 | `html` |
| | `temporary` | 临时对话 | 是否启用临时对话模式。 | `true` |
@@ -407,6 +452,7 @@ curl http://localhost:8000/v1/images/edits \
| **video** | `concurrent` | 并发上限 | Reverse 接口并发上限。 | `100` |
| | `timeout` | 请求超时 | Reverse 接口超时时间(秒)。 | `60` |
| | `stream_timeout` | 流空闲超时 | 流式空闲超时时间(秒)。 | `60` |
| | `upscale_timing` | 超分时机 | Basic 号池 720p 超分模式:`single`(每轮扩展后超分)/ `complete`(所有扩展后超分)。 | `complete` |
| **voice** | `timeout` | 请求超时 | Voice 请求超时时间(秒)。 | `60` |
| **asset** | `upload_concurrent` | 上传并发 | 上传接口的最大并发数。 | `100` |
| | `upload_timeout` | 上传超时 | 上传接口超时时间(秒)。 | `60` |
Generated
+1 -1
View File
@@ -522,7 +522,7 @@ wheels = [
[[package]]
name = "grok2api"
version = "1.6.0"
version = "1.6.1"
source = { virtual = "." }
dependencies = [
{ name = "aiofiles" },