mirror of
https://github.com/open-webui/computer.git
synced 2026-11-22 21:50:43 -05:00
refac
This commit is contained in:
1 parent
e65aa7070d
commit
d6734141e3
3 files changed
+4
-3
No files matched your search
@@ -131,7 +131,7 @@ export const getChat = (chatId: string, modelId?: string) => {
|
||||
return fetchJSON<ChatDetail>(`/api/chats/${chatId}${suffix}`);
|
||||
};
|
||||
|
||||
export const getUsage = (days = 730) => fetchJSON<UsageResponse>(`/api/chats/usage?days=${days}`);
|
||||
export const getUsage = () => fetchJSON<UsageResponse>('/api/chats/usage');
|
||||
|
||||
export const deleteChat = (chatId: string) =>
|
||||
fetchJSON<{ ok: boolean }>(`/api/chats/${chatId}`, { method: 'DELETE' });
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
async function loadUsage() {
|
||||
loading = true;
|
||||
try {
|
||||
usage = await getUsage(730);
|
||||
usage = await getUsage();
|
||||
} catch {
|
||||
usage = null;
|
||||
toast.error(tr('usage.failedToLoad'));
|
||||
|
||||
@@ -329,7 +329,7 @@ async def get_models(request: Request):
|
||||
|
||||
|
||||
@router.get("/usage")
|
||||
async def get_usage(request: Request, days: int = Query(730, ge=7, le=732)):
|
||||
async def get_usage(request: Request, days: int | None = Query(None, ge=7, le=732)):
|
||||
"""Aggregate personal chat usage for the settings Usage tab."""
|
||||
user_id = _get_user(request)
|
||||
|
||||
@@ -402,6 +402,7 @@ async def get_usage(request: Request, days: int = Query(730, ge=7, le=732)):
|
||||
rows.append((message, day_date, tokens))
|
||||
|
||||
today = datetime.now(timezone.utc).date()
|
||||
days = days or 730
|
||||
start = today - timedelta(days=days - 1)
|
||||
period_start = int(
|
||||
datetime.combine(start, datetime.min.time(), tzinfo=timezone.utc).timestamp()
|
||||
|
||||
Reference in new issue
Block a user