feat: add USER_ROLES && admin pages search when keybord enter && auto trim (#348)

* feat: add USER_ROLES

* feat: admin pages search when keybord enter && auto trim

* feat: update version to v0.6.0
This commit is contained in:
Dream Hunter
2024-07-14 19:57:43 +08:00
committed by GitHub
parent 26ccfdd6e0
commit 75c48beb3b
25 changed files with 370 additions and 49 deletions

View File

@@ -1,6 +1,7 @@
import { Context } from "hono";
import { createMimeMessage } from "mimetext";
import { HonoCustomType } from "./types";
import { HonoCustomType, UserRole } from "./types";
import { User } from "telegraf/types";
export const getJsonSetting = async (
c: Context<HonoCustomType>, key: string
@@ -97,6 +98,12 @@ export const getStringArray = (
return value;
}
export const getDefaultDomains = (c: Context<HonoCustomType>): string[] => {
const domains = getStringArray(c.env.DEFAULT_DOMAINS);
if (domains && domains.length > 0) return domains;
return getDomains(c);
}
export const getDomains = (c: Context<HonoCustomType>): string[] => {
if (!c.env.DOMAINS) {
return [];
@@ -113,6 +120,22 @@ export const getDomains = (c: Context<HonoCustomType>): string[] => {
return c.env.DOMAINS;
}
export const getUserRoles = (c: Context<HonoCustomType>): UserRole[] => {
if (!c.env.USER_ROLES) {
return [];
}
// check if USER_ROLES is an array, if not use json.parse
if (!Array.isArray(c.env.USER_ROLES)) {
try {
return JSON.parse(c.env.USER_ROLES);
} catch (e) {
console.error("Failed to parse USER_ROLES", e);
return [];
}
}
return c.env.USER_ROLES;
}
export const getPasswords = (c: Context<HonoCustomType>): string[] => {
if (!c.env.PASSWORDS) {
return [];