mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-31 11:52:10 +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:
parent
2eeae4edb6
commit
c4d70a0325
64 changed files with 236 additions and 449 deletions
|
@ -42,7 +42,7 @@ func ListUnadoptedRepositories(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/forbidden"
|
||||
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
repoNames, count, err := repository.ListUnadoptedRepositories(ctx.Form("query"), &listOptions)
|
||||
repoNames, count, err := repository.ListUnadoptedRepositories(ctx.FormString("query"), &listOptions)
|
||||
if err != nil {
|
||||
ctx.InternalServerError(err)
|
||||
}
|
||||
|
|
|
@ -93,7 +93,7 @@ import (
|
|||
|
||||
func sudo() func(ctx *context.APIContext) {
|
||||
return func(ctx *context.APIContext) {
|
||||
sudo := ctx.Form("sudo")
|
||||
sudo := ctx.FormString("sudo")
|
||||
if len(sudo) == 0 {
|
||||
sudo = ctx.Req.Header.Get("Sudo")
|
||||
}
|
||||
|
|
|
@ -171,7 +171,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/empty"
|
||||
|
||||
lastRead := int64(0)
|
||||
qLastRead := strings.Trim(ctx.Form("last_read_at"), " ")
|
||||
qLastRead := strings.Trim(ctx.FormString("last_read_at"), " ")
|
||||
if len(qLastRead) > 0 {
|
||||
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
|
||||
if err != nil {
|
||||
|
@ -200,7 +200,7 @@ func ReadRepoNotifications(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
targetStatus := statusStringToNotificationStatus(ctx.Form("to-status"))
|
||||
targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status"))
|
||||
if targetStatus == 0 {
|
||||
targetStatus = models.NotificationStatusRead
|
||||
}
|
||||
|
|
|
@ -82,7 +82,7 @@ func ReadThread(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
targetStatus := statusStringToNotificationStatus(ctx.Form("to-status"))
|
||||
targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status"))
|
||||
if targetStatus == 0 {
|
||||
targetStatus = models.NotificationStatusRead
|
||||
}
|
||||
|
|
|
@ -122,7 +122,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
|||
// "$ref": "#/responses/empty"
|
||||
|
||||
lastRead := int64(0)
|
||||
qLastRead := strings.Trim(ctx.Form("last_read_at"), " ")
|
||||
qLastRead := strings.Trim(ctx.FormString("last_read_at"), " ")
|
||||
if len(qLastRead) > 0 {
|
||||
tmpLastRead, err := time.Parse(time.RFC3339, qLastRead)
|
||||
if err != nil {
|
||||
|
@ -147,7 +147,7 @@ func ReadNotifications(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
targetStatus := statusStringToNotificationStatus(ctx.Form("to-status"))
|
||||
targetStatus := statusStringToNotificationStatus(ctx.FormString("to-status"))
|
||||
if targetStatus == 0 {
|
||||
targetStatus = models.NotificationStatusRead
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func ListLabels(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/LabelList"
|
||||
|
||||
labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.Form("sort"), utils.GetListOptions(ctx))
|
||||
labels, err := models.GetLabelsByOrgID(ctx.Org.Organization.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByOrgID", err)
|
||||
return
|
||||
|
|
|
@ -658,9 +658,9 @@ func SearchTeam(ctx *context.APIContext) {
|
|||
|
||||
opts := &models.SearchTeamOptions{
|
||||
UserID: ctx.User.ID,
|
||||
Keyword: strings.TrimSpace(ctx.Form("q")),
|
||||
Keyword: strings.TrimSpace(ctx.FormString("q")),
|
||||
OrgID: ctx.Org.Organization.ID,
|
||||
IncludeDesc: ctx.Form("include_desc") == "" || ctx.FormBool("include_desc"),
|
||||
IncludeDesc: ctx.FormString("include_desc") == "" || ctx.FormBool("include_desc"),
|
||||
ListOptions: listOptions,
|
||||
}
|
||||
|
||||
|
|
|
@ -147,7 +147,7 @@ func GetAllCommits(ctx *context.APIContext) {
|
|||
listOptions.PageSize = setting.Git.CommitsRangeSize
|
||||
}
|
||||
|
||||
sha := ctx.Form("sha")
|
||||
sha := ctx.FormString("sha")
|
||||
|
||||
var baseCommit *git.Commit
|
||||
if len(sha) == 0 {
|
||||
|
|
|
@ -106,7 +106,7 @@ func SearchIssues(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
var isClosed util.OptionalBool
|
||||
switch ctx.Form("state") {
|
||||
switch ctx.FormString("state") {
|
||||
case "closed":
|
||||
isClosed = util.OptionalBoolTrue
|
||||
case "all":
|
||||
|
@ -140,7 +140,7 @@ func SearchIssues(ctx *context.APIContext) {
|
|||
var issues []*models.Issue
|
||||
var filteredCount int64
|
||||
|
||||
keyword := strings.Trim(ctx.Form("q"), " ")
|
||||
keyword := strings.Trim(ctx.FormString("q"), " ")
|
||||
if strings.IndexByte(keyword, 0) >= 0 {
|
||||
keyword = ""
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ func SearchIssues(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
var isPull util.OptionalBool
|
||||
switch ctx.Form("type") {
|
||||
switch ctx.FormString("type") {
|
||||
case "pulls":
|
||||
isPull = util.OptionalBoolTrue
|
||||
case "issues":
|
||||
|
@ -162,13 +162,13 @@ func SearchIssues(ctx *context.APIContext) {
|
|||
isPull = util.OptionalBoolNone
|
||||
}
|
||||
|
||||
labels := strings.TrimSpace(ctx.Form("labels"))
|
||||
labels := strings.TrimSpace(ctx.FormString("labels"))
|
||||
var includedLabelNames []string
|
||||
if len(labels) > 0 {
|
||||
includedLabelNames = strings.Split(labels, ",")
|
||||
}
|
||||
|
||||
milestones := strings.TrimSpace(ctx.Form("milestones"))
|
||||
milestones := strings.TrimSpace(ctx.FormString("milestones"))
|
||||
var includedMilestones []string
|
||||
if len(milestones) > 0 {
|
||||
includedMilestones = strings.Split(milestones, ",")
|
||||
|
@ -319,7 +319,7 @@ func ListIssues(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
var isClosed util.OptionalBool
|
||||
switch ctx.Form("state") {
|
||||
switch ctx.FormString("state") {
|
||||
case "closed":
|
||||
isClosed = util.OptionalBoolTrue
|
||||
case "all":
|
||||
|
@ -331,7 +331,7 @@ func ListIssues(ctx *context.APIContext) {
|
|||
var issues []*models.Issue
|
||||
var filteredCount int64
|
||||
|
||||
keyword := strings.Trim(ctx.Form("q"), " ")
|
||||
keyword := strings.Trim(ctx.FormString("q"), " ")
|
||||
if strings.IndexByte(keyword, 0) >= 0 {
|
||||
keyword = ""
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ func ListIssues(ctx *context.APIContext) {
|
|||
}
|
||||
}
|
||||
|
||||
if splitted := strings.Split(ctx.Form("labels"), ","); len(splitted) > 0 {
|
||||
if splitted := strings.Split(ctx.FormString("labels"), ","); len(splitted) > 0 {
|
||||
labelIDs, err = models.GetLabelIDsInRepoByNames(ctx.Repo.Repository.ID, splitted)
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelIDsInRepoByNames", err)
|
||||
|
@ -354,7 +354,7 @@ func ListIssues(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
var mileIDs []int64
|
||||
if part := strings.Split(ctx.Form("milestones"), ","); len(part) > 0 {
|
||||
if part := strings.Split(ctx.FormString("milestones"), ","); len(part) > 0 {
|
||||
for i := range part {
|
||||
// uses names and fall back to ids
|
||||
// non existent milestones are discarded
|
||||
|
@ -386,7 +386,7 @@ func ListIssues(ctx *context.APIContext) {
|
|||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
var isPull util.OptionalBool
|
||||
switch ctx.Form("type") {
|
||||
switch ctx.FormString("type") {
|
||||
case "pulls":
|
||||
isPull = util.OptionalBoolTrue
|
||||
case "issues":
|
||||
|
@ -448,7 +448,7 @@ func ListIssues(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
func getUserIDForFilter(ctx *context.APIContext, queryName string) int64 {
|
||||
userName := ctx.Form(queryName)
|
||||
userName := ctx.FormString(queryName)
|
||||
if len(userName) == 0 {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ func ListTrackedTimes(ctx *context.APIContext) {
|
|||
IssueID: issue.ID,
|
||||
}
|
||||
|
||||
qUser := strings.Trim(ctx.Form("user"), " ")
|
||||
qUser := strings.Trim(ctx.FormString("user"), " ")
|
||||
if qUser != "" {
|
||||
user, err := models.GetUserByName(qUser)
|
||||
if models.IsErrUserNotExist(err) {
|
||||
|
@ -500,7 +500,7 @@ func ListTrackedTimesByRepository(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
// Filters
|
||||
qUser := strings.Trim(ctx.Form("user"), " ")
|
||||
qUser := strings.Trim(ctx.FormString("user"), " ")
|
||||
if qUser != "" {
|
||||
user, err := models.GetUserByName(qUser)
|
||||
if models.IsErrUserNotExist(err) {
|
||||
|
|
|
@ -78,7 +78,7 @@ func ListDeployKeys(ctx *context.APIContext) {
|
|||
var keys []*models.DeployKey
|
||||
var err error
|
||||
|
||||
fingerprint := ctx.Form("fingerprint")
|
||||
fingerprint := ctx.FormString("fingerprint")
|
||||
keyID := ctx.FormInt64("key_id")
|
||||
if fingerprint != "" || keyID != 0 {
|
||||
keys, err = models.SearchDeployKeys(ctx.Repo.Repository.ID, keyID, fingerprint)
|
||||
|
|
|
@ -49,7 +49,7 @@ func ListLabels(ctx *context.APIContext) {
|
|||
// "200":
|
||||
// "$ref": "#/responses/LabelList"
|
||||
|
||||
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.Form("sort"), utils.GetListOptions(ctx))
|
||||
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID, ctx.FormString("sort"), utils.GetListOptions(ctx))
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetLabelsByRepoID", err)
|
||||
return
|
||||
|
|
|
@ -60,8 +60,8 @@ func ListMilestones(ctx *context.APIContext) {
|
|||
milestones, err := models.GetMilestones(models.GetMilestonesOption{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
State: api.StateType(ctx.Form("state")),
|
||||
Name: ctx.Form("name"),
|
||||
State: api.StateType(ctx.FormString("state")),
|
||||
Name: ctx.FormString("name"),
|
||||
})
|
||||
if err != nil {
|
||||
ctx.Error(http.StatusInternalServerError, "GetMilestones", err)
|
||||
|
|
|
@ -190,7 +190,7 @@ func CreateReleaseAttachment(ctx *context.APIContext) {
|
|||
}
|
||||
|
||||
var filename = header.Filename
|
||||
if query := ctx.Form("name"); query != "" {
|
||||
if query := ctx.FormString("name"); query != "" {
|
||||
filename = query
|
||||
}
|
||||
|
||||
|
|
|
@ -135,19 +135,19 @@ func Search(ctx *context.APIContext) {
|
|||
opts := &models.SearchRepoOptions{
|
||||
ListOptions: utils.GetListOptions(ctx),
|
||||
Actor: ctx.User,
|
||||
Keyword: strings.Trim(ctx.Form("q"), " "),
|
||||
Keyword: strings.Trim(ctx.FormString("q"), " "),
|
||||
OwnerID: ctx.FormInt64("uid"),
|
||||
PriorityOwnerID: ctx.FormInt64("priority_owner_id"),
|
||||
TeamID: ctx.FormInt64("team_id"),
|
||||
TopicOnly: ctx.FormBool("topic"),
|
||||
Collaborate: util.OptionalBoolNone,
|
||||
Private: ctx.IsSigned && (ctx.Form("private") == "" || ctx.FormBool("private")),
|
||||
Private: ctx.IsSigned && (ctx.FormString("private") == "" || ctx.FormBool("private")),
|
||||
Template: util.OptionalBoolNone,
|
||||
StarredByID: ctx.FormInt64("starredBy"),
|
||||
IncludeDescription: ctx.FormBool("includeDesc"),
|
||||
}
|
||||
|
||||
if ctx.Form("template") != "" {
|
||||
if ctx.FormString("template") != "" {
|
||||
opts.Template = util.OptionalBoolOf(ctx.FormBool("template"))
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ func Search(ctx *context.APIContext) {
|
|||
opts.Collaborate = util.OptionalBoolFalse
|
||||
}
|
||||
|
||||
var mode = ctx.Form("mode")
|
||||
var mode = ctx.FormString("mode")
|
||||
switch mode {
|
||||
case "source":
|
||||
opts.Fork = util.OptionalBoolFalse
|
||||
|
@ -173,17 +173,17 @@ func Search(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
if ctx.Form("archived") != "" {
|
||||
if ctx.FormString("archived") != "" {
|
||||
opts.Archived = util.OptionalBoolOf(ctx.FormBool("archived"))
|
||||
}
|
||||
|
||||
if ctx.Form("is_private") != "" {
|
||||
if ctx.FormString("is_private") != "" {
|
||||
opts.IsPrivate = util.OptionalBoolOf(ctx.FormBool("is_private"))
|
||||
}
|
||||
|
||||
var sortMode = ctx.Form("sort")
|
||||
var sortMode = ctx.FormString("sort")
|
||||
if len(sortMode) > 0 {
|
||||
var sortOrder = ctx.Form("order")
|
||||
var sortOrder = ctx.FormString("order")
|
||||
if len(sortOrder) == 0 {
|
||||
sortOrder = "asc"
|
||||
}
|
||||
|
|
|
@ -274,7 +274,7 @@ func TopicSearch(ctx *context.APIContext) {
|
|||
return
|
||||
}
|
||||
|
||||
kw := ctx.Form("q")
|
||||
kw := ctx.FormString("q")
|
||||
|
||||
listOptions := utils.GetListOptions(ctx)
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ func listPublicKeys(ctx *context.APIContext, user *models.User) {
|
|||
var keys []*models.PublicKey
|
||||
var err error
|
||||
|
||||
fingerprint := ctx.Form("fingerprint")
|
||||
fingerprint := ctx.FormString("fingerprint")
|
||||
username := ctx.Params("username")
|
||||
|
||||
if fingerprint != "" {
|
||||
|
|
|
@ -58,7 +58,7 @@ func Search(ctx *context.APIContext) {
|
|||
|
||||
opts := &models.SearchUserOptions{
|
||||
Actor: ctx.User,
|
||||
Keyword: strings.Trim(ctx.Form("q"), " "),
|
||||
Keyword: strings.Trim(ctx.FormString("q"), " "),
|
||||
UID: ctx.FormInt64("uid"),
|
||||
Type: models.UserTypeIndividual,
|
||||
ListOptions: listOptions,
|
||||
|
|
|
@ -54,7 +54,7 @@ func parseTime(value string) (int64, error) {
|
|||
|
||||
// prepareQueryArg unescape and trim a query arg
|
||||
func prepareQueryArg(ctx *context.APIContext, name string) (value string, err error) {
|
||||
value, err = url.PathUnescape(ctx.Form(name))
|
||||
value, err = url.PathUnescape(ctx.FormString(name))
|
||||
value = strings.TrimSpace(value)
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue