diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..f5c153e --- /dev/null +++ b/.prettierrc @@ -0,0 +1,13 @@ +{ + "overrides": [ + { + "files": [ + "*.ejs" + ], + "options": { + "printWidth": 160, + "bracketSameLine": true + } + } + ] +} diff --git a/src/admin/ui/users.ts b/src/admin/ui/users.ts index 60c947a..130fe9b 100644 --- a/src/admin/ui/users.ts +++ b/src/admin/ui/users.ts @@ -165,6 +165,12 @@ router.post("/maintenance", (req, res) => { message = `success: All users' token quotas reset to ${turbo} (Turbo), ${gpt4} (GPT-4), ${claude} (Claude).`; break; } + case "resetCounts": { + const users = userStore.getUsers(); + users.forEach((user) => userStore.resetUsage(user.token)); + message = `success: All users' token usage records reset.`; + break; + } default: { throw new HttpError(400, "Invalid action"); } diff --git a/src/proxy/auth/user-store.ts b/src/proxy/auth/user-store.ts index 87eff02..525f5e8 100644 --- a/src/proxy/auth/user-store.ts +++ b/src/proxy/auth/user-store.ts @@ -228,6 +228,15 @@ export function refreshQuota(token: string) { usersToFlush.add(token); } +export function resetUsage(token: string) { + const user = users.get(token); + if (!user) return; + const { tokenCounts } = user; + const counts = Object.entries(tokenCounts) as [ModelFamily, number][]; + counts.forEach(([model]) => (tokenCounts[model] = 0)); + usersToFlush.add(token); +} + /** Disables the given user, optionally providing a reason. */ export function disableUser(token: string, reason?: string) { const user = users.get(token); diff --git a/src/views/admin/index.ejs b/src/views/admin/index.ejs index ae574a2..4f37287 100644 --- a/src/views/admin/index.ejs +++ b/src/views/admin/index.ejs @@ -1,20 +1,12 @@ -<%- include("../_partials/admin-header", { title: "OAI Reverse Proxy Admin" }) -%> +<%- include("../_partials/admin-header", { title: "OAI Reverse Proxy Admin" }) %>
- ⚠️ Users will be lost when the server restarts because persistence is not
- configured.
-
Be sure to export your users and import them again after restarting the
- server if you want to keep them.
+ ⚠️ Users will be lost when the server restarts because persistence is not configured.
+
Be sure to export your users and import them again after restarting the server if you want to keep them.
See the
-
+
user management documentation
to learn how to set up persistence.
@@ -31,18 +23,38 @@