1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-23 02:38:35 +00:00

Rename ctx.Form() to ctx.FormString() and move code into own file (#16571)

Followup from #16562 prepare for #16567

* Rename ctx.Form() to ctx.FormString()
* Reimplement FormX func to need less code and cpu cycles
* Move code into own file
This commit is contained in:
6543
2021-08-11 02:31:13 +02:00
committed by GitHub
parent 2eeae4edb6
commit c4d70a0325
64 changed files with 236 additions and 449 deletions

View File

@@ -161,7 +161,7 @@ func DashboardPost(ctx *context.Context) {
// SendTestMail send test mail to confirm mail service is OK
func SendTestMail(ctx *context.Context) {
email := ctx.Form("email")
email := ctx.FormString("email")
// Send a test email to the user's email address and redirect back to Config
if err := mailer.SendTestMail(email); err != nil {
ctx.Flash.Error(ctx.Tr("admin.config.test_mail_failed", email, err))
@@ -377,7 +377,7 @@ func Flush(ctx *context.Context) {
ctx.Status(404)
return
}
timeout, err := time.ParseDuration(ctx.Form("timeout"))
timeout, err := time.ParseDuration(ctx.FormString("timeout"))
if err != nil {
timeout = -1
}
@@ -405,7 +405,7 @@ func AddWorkers(ctx *context.Context) {
ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10))
return
}
timeout, err := time.ParseDuration(ctx.Form("timeout"))
timeout, err := time.ParseDuration(ctx.FormString("timeout"))
if err != nil {
ctx.Flash.Error(ctx.Tr("admin.monitor.queue.pool.addworkers.musttimeoutduration"))
ctx.Redirect(setting.AppSubURL + "/admin/monitor/queue/" + strconv.FormatInt(qid, 10))
@@ -435,9 +435,9 @@ func SetQueueSettings(ctx *context.Context) {
return
}
maxNumberStr := ctx.Form("max-number")
numberStr := ctx.Form("number")
timeoutStr := ctx.Form("timeout")
maxNumberStr := ctx.FormString("max-number")
numberStr := ctx.FormString("number")
timeoutStr := ctx.FormString("timeout")
var err error
var maxNumber, number int

View File

@@ -51,8 +51,8 @@ func Emails(ctx *context.Context) {
orderBy models.SearchEmailOrderBy
)
ctx.Data["SortType"] = ctx.Form("sort")
switch ctx.Form("sort") {
ctx.Data["SortType"] = ctx.FormString("sort")
switch ctx.FormString("sort") {
case "email":
orderBy = models.SearchEmailOrderByEmail
case "reverseemail":
@@ -68,10 +68,10 @@ func Emails(ctx *context.Context) {
opts.Keyword = ctx.FormTrim("q")
opts.SortType = orderBy
if len(ctx.Form("is_activated")) != 0 {
if len(ctx.FormString("is_activated")) != 0 {
opts.IsActivated = util.OptionalBoolOf(ctx.FormBool("activated"))
}
if len(ctx.Form("is_primary")) != 0 {
if len(ctx.FormString("is_primary")) != 0 {
opts.IsPrimary = util.OptionalBoolOf(ctx.FormBool("primary"))
}
@@ -114,9 +114,9 @@ func ActivateEmail(ctx *context.Context) {
truefalse := map[string]bool{"1": true, "0": false}
uid := ctx.FormInt64("uid")
email := ctx.Form("email")
primary, okp := truefalse[ctx.Form("primary")]
activate, oka := truefalse[ctx.Form("activate")]
email := ctx.FormString("email")
primary, okp := truefalse[ctx.FormString("primary")]
activate, oka := truefalse[ctx.FormString("activate")]
if uid == 0 || len(email) == 0 || !okp || !oka {
ctx.Error(http.StatusBadRequest)

View File

@@ -59,7 +59,7 @@ func DeleteRepo(ctx *context.Context) {
ctx.Flash.Success(ctx.Tr("repo.settings.deletion_success"))
ctx.JSON(http.StatusOK, map[string]interface{}{
"redirect": setting.AppSubURL + "/admin/repos?page=" + ctx.Form("page") + "&sort=" + ctx.Form("sort"),
"redirect": setting.AppSubURL + "/admin/repos?page=" + ctx.FormString("page") + "&sort=" + ctx.FormString("sort"),
})
}
@@ -83,7 +83,7 @@ func UnadoptedRepos(ctx *context.Context) {
doSearch := ctx.FormBool("search")
ctx.Data["search"] = doSearch
q := ctx.Form("q")
q := ctx.FormString("q")
if !doSearch {
pager := context.NewPagination(0, opts.PageSize, opts.Page, 5)
@@ -109,10 +109,10 @@ func UnadoptedRepos(ctx *context.Context) {
// AdoptOrDeleteRepository adopts or deletes a repository
func AdoptOrDeleteRepository(ctx *context.Context) {
dir := ctx.Form("id")
action := ctx.Form("action")
dir := ctx.FormString("id")
action := ctx.FormString("action")
page := ctx.FormInt("page")
q := ctx.Form("q")
q := ctx.FormString("q")
dirSplit := strings.SplitN(dir, "/", 2)
if len(dirSplit) != 2 {