feat: add DISABLE_ADMIN_PASSWORD_CHECK (#386)

This commit is contained in:
Dream Hunter
2024-08-11 00:10:16 +08:00
committed by GitHub
parent fc07f1cd87
commit 15063b2e97
7 changed files with 20 additions and 0 deletions

View File

@@ -25,6 +25,7 @@ export type Bindings = {
DOMAIN_LABELS: string | string[] | undefined
PASSWORDS: string | string[] | undefined
ADMIN_PASSWORDS: string | string[] | undefined
DISABLE_ADMIN_PASSWORD_CHECK: string | boolean | undefined
JWT_SECRET: string
BLACK_LIST: string | undefined
ENABLE_AUTO_REPLY: string | boolean | undefined

View File

@@ -153,6 +153,7 @@ app.use('/user_api/*', async (c, next) => {
});
// admin auth
app.use('/admin/*', async (c, next) => {
// check header x-admin-auth
const adminPasswords = getAdminPasswords(c);
if (adminPasswords && adminPasswords.length > 0) {
@@ -182,6 +183,13 @@ app.use('/admin/*', async (c, next) => {
console.error(e);
}
}
// disable admin api check
if (getBooleanValue(c.env.DISABLE_ADMIN_PASSWORD_CHECK)) {
await next();
return;
}
return c.text("Need Admin Password", 401)
});