jojo/routers/web/admin/federation_hosts.go
Gusted 6a5dda7116 chore: modernize code (#12065)
Followup of !11115, it was not checked against the the modernizer linter.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/12065
Reviewed-by: Otto <otto@codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
2026-04-09 21:34:33 +02:00

55 lines
1.3 KiB
Go

// Copyright 2026 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package admin
import (
"net/http"
"forgejo.org/models/db"
"forgejo.org/models/forgefed"
"forgejo.org/modules/base"
"forgejo.org/modules/setting"
"forgejo.org/services/context"
)
const (
tplFederationHosts base.TplName = "admin/federation/hosts"
)
func FederationHosts(ctx *context.Context) {
sort := ctx.FormTrim("sort")
page := max(ctx.FormInt("page"), 1)
hosts, err := forgefed.FindFederationHosts(ctx, db.ListOptions{
Page: page,
PageSize: setting.UI.Admin.FederationHostPagingNum,
})
if err != nil {
ctx.ServerError("GetFederationHosts", err)
return
}
total, err := forgefed.CountFederationHosts(ctx)
if err != nil {
ctx.ServerError("CountFederationHosts", err)
return
}
ctx.Data["Title"] = ctx.Tr("admin.federation.hosts.title")
ctx.Data["PageIsAdminFederationHosts"] = true
ctx.Data["SortType"] = sort
ctx.Data["TotalCount"] = int(total)
ctx.Data["Hosts"] = hosts
numPages := 0
if total > 0 {
numPages = (int(total) - 1/setting.UI.Admin.FederationHostPagingNum)
}
pager := context.NewPagination(int(total), setting.UI.Admin.FederationHostPagingNum, page, numPages)
pager.SetDefaultParams(ctx)
ctx.Data["Page"] = pager
ctx.HTML(http.StatusOK, tplFederationHosts)
}