fix pages viewing
This commit is contained in:
@@ -2,7 +2,7 @@ import db, { nowIso, toIso } from "../db";
|
||||
import { applyCaddyConfig } from "../caddy";
|
||||
import { logAuditEvent } from "../audit";
|
||||
import { proxyHosts } from "../db/schema";
|
||||
import { desc, eq, count } from "drizzle-orm";
|
||||
import { desc, eq, count, ilike, or } from "drizzle-orm";
|
||||
import { getAuthentikSettings, getGeoBlockSettings, GeoBlockSettings } from "../settings";
|
||||
|
||||
const DEFAULT_AUTHENTIK_HEADERS = [
|
||||
@@ -1329,15 +1329,30 @@ export async function listProxyHosts(): Promise<ProxyHost[]> {
|
||||
return hosts.map(parseProxyHost);
|
||||
}
|
||||
|
||||
export async function countProxyHosts(): Promise<number> {
|
||||
const [row] = await db.select({ value: count() }).from(proxyHosts);
|
||||
export async function countProxyHosts(search?: string): Promise<number> {
|
||||
const where = search
|
||||
? or(
|
||||
ilike(proxyHosts.name, `%${search}%`),
|
||||
ilike(proxyHosts.domains, `%${search}%`),
|
||||
ilike(proxyHosts.upstreams, `%${search}%`)
|
||||
)
|
||||
: undefined;
|
||||
const [row] = await db.select({ value: count() }).from(proxyHosts).where(where);
|
||||
return row?.value ?? 0;
|
||||
}
|
||||
|
||||
export async function listProxyHostsPaginated(limit: number, offset: number): Promise<ProxyHost[]> {
|
||||
export async function listProxyHostsPaginated(limit: number, offset: number, search?: string): Promise<ProxyHost[]> {
|
||||
const where = search
|
||||
? or(
|
||||
ilike(proxyHosts.name, `%${search}%`),
|
||||
ilike(proxyHosts.domains, `%${search}%`),
|
||||
ilike(proxyHosts.upstreams, `%${search}%`)
|
||||
)
|
||||
: undefined;
|
||||
const hosts = await db
|
||||
.select()
|
||||
.from(proxyHosts)
|
||||
.where(where)
|
||||
.orderBy(desc(proxyHosts.createdAt))
|
||||
.limit(limit)
|
||||
.offset(offset);
|
||||
|
||||
Reference in New Issue
Block a user