mirror of
https://git.evilfox.cc/test2/wg.git
synced 2026-08-01 04:13:24 +00:00
Show all WireGuard configs in admin without pagination.
This commit is contained in:
@@ -176,22 +176,14 @@ func generateToken(n int) (string, error) {
|
||||
|
||||
func (a *App) AdminWG(w http.ResponseWriter, r *http.Request) {
|
||||
u := a.Auth.CurrentUser(r)
|
||||
page, _ := strconv.Atoi(r.URL.Query().Get("page"))
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
const perPage = 10
|
||||
|
||||
var total int
|
||||
_ = a.DB.QueryRow(r.Context(), `SELECT COUNT(*) FROM wg_configs`).Scan(&total)
|
||||
totalPages := (total + perPage - 1) / perPage
|
||||
if totalPages < 1 {
|
||||
totalPages = 1
|
||||
}
|
||||
offset := (page - 1) * perPage
|
||||
|
||||
rows, err := a.DB.Query(r.Context(), `
|
||||
SELECT id, COALESCE(token,''), original_filename, created_at
|
||||
FROM wg_configs ORDER BY created_at DESC LIMIT $1 OFFSET $2`, perPage, offset)
|
||||
FROM wg_configs
|
||||
ORDER BY created_at DESC`)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
@@ -214,8 +206,7 @@ func (a *App) AdminWG(w http.ResponseWriter, r *http.Request) {
|
||||
a.render(w, "admin_wg.html", map[string]any{
|
||||
"User": u,
|
||||
"Configs": configs,
|
||||
"Page": page,
|
||||
"TotalPages": totalPages,
|
||||
"Total": total,
|
||||
"Message": msg,
|
||||
"MessageType": msgType,
|
||||
"NewToken": token,
|
||||
|
||||
Reference in New Issue
Block a user