diff options
Diffstat (limited to 'routers')
-rw-r--r-- | routers/admin/admin.go | 3 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 13 | ||||
-rw-r--r-- | routers/api/v1/repo/milestone.go | 7 | ||||
-rw-r--r-- | routers/api/v1/repo/pull.go | 10 | ||||
-rw-r--r-- | routers/dev/template.go | 5 | ||||
-rw-r--r-- | routers/private/key.go | 4 | ||||
-rw-r--r-- | routers/repo/blame.go | 5 | ||||
-rw-r--r-- | routers/repo/http.go | 4 | ||||
-rw-r--r-- | routers/repo/milestone.go | 7 | ||||
-rw-r--r-- | routers/repo/setting.go | 10 | ||||
-rw-r--r-- | routers/repo/wiki.go | 5 | ||||
-rw-r--r-- | routers/user/auth.go | 11 | ||||
-rw-r--r-- | routers/user/auth_openid.go | 3 | ||||
-rw-r--r-- | routers/user/oauth.go | 8 | ||||
-rw-r--r-- | routers/user/setting/account.go | 3 |
15 files changed, 52 insertions, 46 deletions
diff --git a/routers/admin/admin.go b/routers/admin/admin.go index 370f816525..8339c1eaec 100644 --- a/routers/admin/admin.go +++ b/routers/admin/admin.go @@ -24,6 +24,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/process" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/timeutil" ) const ( @@ -78,7 +79,7 @@ var sysStatus struct { } func updateSystemStatus() { - sysStatus.Uptime = base.TimeSincePro(startTime, "en") + sysStatus.Uptime = timeutil.TimeSincePro(startTime, "en") m := new(runtime.MemStats) runtime.ReadMemStats(m) diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index daaa3d5985..8595be335b 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -16,6 +16,7 @@ import ( issue_indexer "code.gitea.io/gitea/modules/indexer/issues" "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" api "code.gitea.io/gitea/modules/structs" @@ -183,9 +184,9 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) { // "201": // "$ref": "#/responses/Issue" - var deadlineUnix util.TimeStamp + var deadlineUnix timeutil.TimeStamp if form.Deadline != nil && ctx.Repo.CanWrite(models.UnitTypeIssues) { - deadlineUnix = util.TimeStamp(form.Deadline.Unix()) + deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix()) } issue := &models.Issue{ @@ -310,9 +311,9 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) { } // Update the deadline - var deadlineUnix util.TimeStamp + var deadlineUnix timeutil.TimeStamp if form.Deadline != nil && !form.Deadline.IsZero() && ctx.Repo.CanWrite(models.UnitTypeIssues) { - deadlineUnix = util.TimeStamp(form.Deadline.Unix()) + deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix()) } if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { @@ -430,12 +431,12 @@ func UpdateIssueDeadline(ctx *context.APIContext, form api.EditDeadlineOption) { return } - var deadlineUnix util.TimeStamp + var deadlineUnix timeutil.TimeStamp var deadline time.Time if form.Deadline != nil && !form.Deadline.IsZero() { deadline = time.Date(form.Deadline.Year(), form.Deadline.Month(), form.Deadline.Day(), 23, 59, 59, 0, form.Deadline.Location()) - deadlineUnix = util.TimeStamp(deadline.Unix()) + deadlineUnix = timeutil.TimeStamp(deadline.Unix()) } if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go index 14030a2186..9bc73852ca 100644 --- a/routers/api/v1/repo/milestone.go +++ b/routers/api/v1/repo/milestone.go @@ -9,9 +9,8 @@ import ( "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/context" - "code.gitea.io/gitea/modules/util" - api "code.gitea.io/gitea/modules/structs" + "code.gitea.io/gitea/modules/timeutil" ) // ListMilestones list milestones for a repository @@ -127,7 +126,7 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) { RepoID: ctx.Repo.Repository.ID, Name: form.Title, Content: form.Description, - DeadlineUnix: util.TimeStamp(form.Deadline.Unix()), + DeadlineUnix: timeutil.TimeStamp(form.Deadline.Unix()), } if err := models.NewMilestone(milestone); err != nil { @@ -187,7 +186,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) { milestone.Content = *form.Description } if form.Deadline != nil && !form.Deadline.IsZero() { - milestone.DeadlineUnix = util.TimeStamp(form.Deadline.Unix()) + milestone.DeadlineUnix = timeutil.TimeStamp(form.Deadline.Unix()) } if err := models.UpdateMilestone(milestone); err != nil { diff --git a/routers/api/v1/repo/pull.go b/routers/api/v1/repo/pull.go index d99c9a00c9..8168c6b010 100644 --- a/routers/api/v1/repo/pull.go +++ b/routers/api/v1/repo/pull.go @@ -17,7 +17,7 @@ import ( "code.gitea.io/gitea/modules/notification" "code.gitea.io/gitea/modules/pull" api "code.gitea.io/gitea/modules/structs" - "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/modules/timeutil" ) // ListPullRequests returns a list of all PRs @@ -247,9 +247,9 @@ func CreatePullRequest(ctx *context.APIContext, form api.CreatePullRequestOption return } - var deadlineUnix util.TimeStamp + var deadlineUnix timeutil.TimeStamp if form.Deadline != nil { - deadlineUnix = util.TimeStamp(form.Deadline.Unix()) + deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix()) } maxIndex, err := models.GetMaxIndexOfIssue(repo.ID) @@ -375,9 +375,9 @@ func EditPullRequest(ctx *context.APIContext, form api.EditPullRequestOption) { } // Update Deadline - var deadlineUnix util.TimeStamp + var deadlineUnix timeutil.TimeStamp if form.Deadline != nil && !form.Deadline.IsZero() { - deadlineUnix = util.TimeStamp(form.Deadline.Unix()) + deadlineUnix = timeutil.TimeStamp(form.Deadline.Unix()) } if err := models.UpdateIssueDeadline(issue, deadlineUnix, ctx.User); err != nil { diff --git a/routers/dev/template.go b/routers/dev/template.go index ad0d2c1cd3..92599a7423 100644 --- a/routers/dev/template.go +++ b/routers/dev/template.go @@ -9,6 +9,7 @@ import ( "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/timeutil" ) // TemplatePreview render for previewing the indicated template @@ -18,8 +19,8 @@ func TemplatePreview(ctx *context.Context) { ctx.Data["AppVer"] = setting.AppVer ctx.Data["AppUrl"] = setting.AppURL ctx.Data["Code"] = "2014031910370000009fff6782aadb2162b4a997acb69d4400888e0b9274657374" - ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) - ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language()) + ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) + ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language()) ctx.Data["CurDbValue"] = "" ctx.HTML(200, base.TplName(ctx.Params("*"))) diff --git a/routers/private/key.go b/routers/private/key.go index f7212ec892..8c1dbd40f1 100644 --- a/routers/private/key.go +++ b/routers/private/key.go @@ -7,7 +7,7 @@ package private import ( "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/modules/timeutil" macaron "gopkg.in/macaron.v1" ) @@ -34,7 +34,7 @@ func UpdatePublicKeyInRepo(ctx *macaron.Context) { }) return } - deployKey.UpdatedUnix = util.TimeStampNow() + deployKey.UpdatedUnix = timeutil.TimeStampNow() if err = models.UpdateDeployKeyCols(deployKey, "updated_unix"); err != nil { ctx.JSON(500, map[string]interface{}{ "err": err.Error(), diff --git a/routers/repo/blame.go b/routers/repo/blame.go index 07952a4cae..5578942a9f 100644 --- a/routers/repo/blame.go +++ b/routers/repo/blame.go @@ -14,7 +14,6 @@ import ( "strings" "code.gitea.io/gitea/models" - "code.gitea.io/gitea/modules/base" "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/git" @@ -22,7 +21,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/modules/timeutil" ) const ( @@ -212,7 +211,7 @@ func renderBlame(ctx *context.Context, blameParts []git.BlamePart, commitNames m if index == 0 { // User avatar image avatar := "" - commitSince := base.TimeSinceUnix(util.TimeStamp(commit.Author.When.Unix()), ctx.Data["Lang"].(string)) + commitSince := timeutil.TimeSinceUnix(timeutil.TimeStamp(commit.Author.When.Unix()), ctx.Data["Lang"].(string)) if commit.User != nil { authorName := commit.Author.Name if len(commit.User.FullName) > 0 { diff --git a/routers/repo/http.go b/routers/repo/http.go index c0bf830969..09dd820585 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -25,7 +25,7 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/modules/timeutil" ) // HTTP implmentation git smart HTTP protocol @@ -203,7 +203,7 @@ func HTTP(ctx *context.Context) { return } } - token.UpdatedUnix = util.TimeStampNow() + token.UpdatedUnix = timeutil.TimeStampNow() if err = models.UpdateAccessToken(token); err != nil { ctx.ServerError("UpdateAccessToken", err) } diff --git a/routers/repo/milestone.go b/routers/repo/milestone.go index 5b8a5faa33..b4056cc6d1 100644 --- a/routers/repo/milestone.go +++ b/routers/repo/milestone.go @@ -13,6 +13,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/markup/markdown" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" ) @@ -120,7 +121,7 @@ func NewMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) { RepoID: ctx.Repo.Repository.ID, Name: form.Title, Content: form.Content, - DeadlineUnix: util.TimeStamp(deadline.Unix()), + DeadlineUnix: timeutil.TimeStamp(deadline.Unix()), }); err != nil { ctx.ServerError("NewMilestone", err) return @@ -190,7 +191,7 @@ func EditMilestonePost(ctx *context.Context, form auth.CreateMilestoneForm) { } m.Name = form.Title m.Content = form.Content - m.DeadlineUnix = util.TimeStamp(deadline.Unix()) + m.DeadlineUnix = timeutil.TimeStamp(deadline.Unix()) if err = models.UpdateMilestone(m); err != nil { ctx.ServerError("UpdateMilestone", err) return @@ -223,7 +224,7 @@ func ChangeMilestonStatus(ctx *context.Context) { ctx.Redirect(ctx.Repo.RepoLink + "/milestones?state=open") case "close": if !m.IsClosed { - m.ClosedDateUnix = util.TimeStampNow() + m.ClosedDateUnix = timeutil.TimeStampNow() if err = models.ChangeMilestoneStatus(m, true); err != nil { ctx.ServerError("ChangeMilestoneStatus", err) return diff --git a/routers/repo/setting.go b/routers/repo/setting.go index 757295069e..c9ecb63020 100644 --- a/routers/repo/setting.go +++ b/routers/repo/setting.go @@ -14,9 +14,6 @@ import ( "strings" "time" - "github.com/Unknwon/com" - "mvdan.cc/xurls/v2" - "code.gitea.io/gitea/models" "code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/base" @@ -24,9 +21,12 @@ import ( "code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/validation" "code.gitea.io/gitea/routers/utils" + + "github.com/Unknwon/com" + "mvdan.cc/xurls/v2" ) const ( @@ -144,7 +144,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) { ctx.Repo.Mirror.EnablePrune = form.EnablePrune ctx.Repo.Mirror.Interval = interval if interval != 0 { - ctx.Repo.Mirror.NextUpdateUnix = util.TimeStampNow().AddDuration(interval) + ctx.Repo.Mirror.NextUpdateUnix = timeutil.TimeStampNow().AddDuration(interval) } else { ctx.Repo.Mirror.NextUpdateUnix = 0 } diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index 0d965f2183..54cb4b83dd 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -19,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/markup" "code.gitea.io/gitea/modules/markup/markdown" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" ) @@ -58,7 +59,7 @@ func MustEnableWiki(ctx *context.Context) { type PageMeta struct { Name string SubURL string - UpdatedUnix util.TimeStamp + UpdatedUnix timeutil.TimeStamp } // findEntryForFile finds the tree entry for a target filepath. @@ -413,7 +414,7 @@ func WikiPages(ctx *context.Context) { pages = append(pages, PageMeta{ Name: wikiName, SubURL: models.WikiNameToSubURL(wikiName), - UpdatedUnix: util.TimeStamp(c.Author.When.Unix()), + UpdatedUnix: timeutil.TimeStamp(c.Author.When.Unix()), }) } ctx.Data["Pages"] = pages diff --git a/routers/user/auth.go b/routers/user/auth.go index f78171a1b7..6850bbe11b 100644 --- a/routers/user/auth.go +++ b/routers/user/auth.go @@ -19,6 +19,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/recaptcha" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/timeutil" "code.gitea.io/gitea/modules/util" "github.com/go-macaron/captcha" @@ -950,7 +951,7 @@ func LinkAccountPostRegister(ctx *context.Context, cpt *captcha.Captcha, form au models.SendActivateAccountMail(ctx.Context, u) ctx.Data["IsSendRegisterMail"] = true ctx.Data["Email"] = u.Email - ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) + ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) ctx.HTML(200, TplActivate) if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { @@ -1096,7 +1097,7 @@ func SignUpPost(ctx *context.Context, cpt *captcha.Captcha, form auth.RegisterFo models.SendActivateAccountMail(ctx.Context, u) ctx.Data["IsSendRegisterMail"] = true ctx.Data["Email"] = u.Email - ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) + ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) ctx.HTML(200, TplActivate) if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { @@ -1123,7 +1124,7 @@ func Activate(ctx *context.Context) { if ctx.Cache.IsExist("MailResendLimit_" + ctx.User.LowerName) { ctx.Data["ResendLimited"] = true } else { - ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) + ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) models.SendActivateAccountMail(ctx.Context, ctx.User) if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { @@ -1224,7 +1225,7 @@ func ForgotPasswdPost(ctx *context.Context) { u, err := models.GetUserByEmail(email) if err != nil { if models.IsErrUserNotExist(err) { - ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language()) + ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language()) ctx.Data["IsResetSent"] = true ctx.HTML(200, tplForgotPassword) return @@ -1251,7 +1252,7 @@ func ForgotPasswdPost(ctx *context.Context) { log.Error("Set cache(MailResendLimit) fail: %v", err) } - ctx.Data["ResetPwdCodeLives"] = base.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language()) + ctx.Data["ResetPwdCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ResetPwdCodeLives, ctx.Locale.Language()) ctx.Data["IsResetSent"] = true ctx.HTML(200, tplForgotPassword) } diff --git a/routers/user/auth_openid.go b/routers/user/auth_openid.go index d6baf0d92b..48dbf02ffb 100644 --- a/routers/user/auth_openid.go +++ b/routers/user/auth_openid.go @@ -17,6 +17,7 @@ import ( "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/recaptcha" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/timeutil" "github.com/go-macaron/captcha" ) @@ -446,7 +447,7 @@ func RegisterOpenIDPost(ctx *context.Context, cpt *captcha.Captcha, form auth.Si models.SendActivateAccountMail(ctx.Context, u) ctx.Data["IsSendRegisterMail"] = true ctx.Data["Email"] = u.Email - ctx.Data["ActiveCodeLives"] = base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) + ctx.Data["ActiveCodeLives"] = timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()) ctx.HTML(200, TplActivate) if err := ctx.Cache.Put("MailResendLimit_"+u.LowerName, u.LowerName, 180); err != nil { diff --git a/routers/user/oauth.go b/routers/user/oauth.go index 924bac8ef6..19add5e647 100644 --- a/routers/user/oauth.go +++ b/routers/user/oauth.go @@ -7,7 +7,6 @@ package user import ( "encoding/base64" "fmt" - "github.com/go-macaron/binding" "net/url" "strings" @@ -17,9 +16,10 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" - "code.gitea.io/gitea/modules/util" + "code.gitea.io/gitea/modules/timeutil" "github.com/dgrijalva/jwt-go" + "github.com/go-macaron/binding" ) const ( @@ -118,7 +118,7 @@ func newAccessTokenResponse(grant *models.OAuth2Grant) (*AccessTokenResponse, *A } } // generate access token to access the API - expirationDate := util.TimeStampNow().Add(setting.OAuth2.AccessTokenExpirationTime) + expirationDate := timeutil.TimeStampNow().Add(setting.OAuth2.AccessTokenExpirationTime) accessToken := &models.OAuth2Token{ GrantID: grant.ID, Type: models.TypeAccessToken, @@ -135,7 +135,7 @@ func newAccessTokenResponse(grant *models.OAuth2Grant) (*AccessTokenResponse, *A } // generate refresh token to request an access token after it expired later - refreshExpirationDate := util.TimeStampNow().Add(setting.OAuth2.RefreshTokenExpirationTime * 60 * 60).AsTime().Unix() + refreshExpirationDate := timeutil.TimeStampNow().Add(setting.OAuth2.RefreshTokenExpirationTime * 60 * 60).AsTime().Unix() refreshToken := &models.OAuth2Token{ GrantID: grant.ID, Counter: grant.Counter, diff --git a/routers/user/setting/account.go b/routers/user/setting/account.go index 3fd6a8db5e..c6b5c0c2dc 100644 --- a/routers/user/setting/account.go +++ b/routers/user/setting/account.go @@ -12,6 +12,7 @@ import ( "code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/setting" + "code.gitea.io/gitea/modules/timeutil" ) const ( @@ -112,7 +113,7 @@ func EmailPost(ctx *context.Context, form auth.AddEmailForm) { if err := ctx.Cache.Put("MailResendLimit_"+ctx.User.LowerName, ctx.User.LowerName, 180); err != nil { log.Error("Set cache(MailResendLimit) fail: %v", err) } - ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, base.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()))) + ctx.Flash.Info(ctx.Tr("settings.add_email_confirmation_sent", email.Email, timeutil.MinutesToFriendly(setting.Service.ActiveCodeLives, ctx.Locale.Language()))) } else { ctx.Flash.Success(ctx.Tr("settings.add_email_success")) } |