aboutsummaryrefslogtreecommitdiff
path: root/internal/context
diff options
context:
space:
mode:
Diffstat (limited to 'internal/context')
-rw-r--r--internal/context/api.go12
-rw-r--r--internal/context/auth.go24
-rw-r--r--internal/context/context.go26
-rw-r--r--internal/context/notice.go6
-rw-r--r--internal/context/org.go4
-rw-r--r--internal/context/repo.go6
6 files changed, 39 insertions, 39 deletions
diff --git a/internal/context/api.go b/internal/context/api.go
index 153997d3..881e9aa8 100644
--- a/internal/context/api.go
+++ b/internal/context/api.go
@@ -13,7 +13,7 @@ import (
"gopkg.in/macaron.v1"
log "unknwon.dev/clog/v2"
- "gogs.io/gogs/internal/setting"
+ "gogs.io/gogs/internal/conf"
)
type APIContext struct {
@@ -79,16 +79,16 @@ func (c *APIContext) SetLinkHeader(total, pageSize int) {
page := paginater.New(total, pageSize, c.QueryInt("page"), 0)
links := make([]string, 0, 4)
if page.HasNext() {
- links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"next\"", setting.AppURL, c.Req.URL.Path[1:], page.Next()))
+ links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"next\"", conf.Server.ExternalURL, c.Req.URL.Path[1:], page.Next()))
}
if !page.IsLast() {
- links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"last\"", setting.AppURL, c.Req.URL.Path[1:], page.TotalPages()))
+ links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"last\"", conf.Server.ExternalURL, c.Req.URL.Path[1:], page.TotalPages()))
}
if !page.IsFirst() {
- links = append(links, fmt.Sprintf("<%s%s?page=1>; rel=\"first\"", setting.AppURL, c.Req.URL.Path[1:]))
+ links = append(links, fmt.Sprintf("<%s%s?page=1>; rel=\"first\"", conf.Server.ExternalURL, c.Req.URL.Path[1:]))
}
if page.HasPrevious() {
- links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"prev\"", setting.AppURL, c.Req.URL.Path[1:], page.Previous()))
+ links = append(links, fmt.Sprintf("<%s%s?page=%d>; rel=\"prev\"", conf.Server.ExternalURL, c.Req.URL.Path[1:], page.Previous()))
}
if len(links) > 0 {
@@ -100,7 +100,7 @@ func APIContexter() macaron.Handler {
return func(ctx *Context) {
c := &APIContext{
Context: ctx,
- BaseURL: setting.AppURL + "api/v1",
+ BaseURL: conf.Server.ExternalURL + "api/v1",
}
ctx.Map(c)
}
diff --git a/internal/context/auth.go b/internal/context/auth.go
index cc6c804c..b0ddfc6f 100644
--- a/internal/context/auth.go
+++ b/internal/context/auth.go
@@ -13,7 +13,7 @@ import (
"gopkg.in/macaron.v1"
"gogs.io/gogs/internal/auth"
- "gogs.io/gogs/internal/setting"
+ "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/tool"
)
@@ -27,8 +27,8 @@ type ToggleOptions struct {
func Toggle(options *ToggleOptions) macaron.Handler {
return func(c *Context) {
// Cannot view any page before installation.
- if !setting.InstallLock {
- c.Redirect(setting.AppSubURL + "/install")
+ if !conf.InstallLock {
+ c.Redirect(conf.Server.Subpath + "/install")
return
}
@@ -40,14 +40,14 @@ func Toggle(options *ToggleOptions) macaron.Handler {
}
// Check non-logged users landing page.
- if !c.IsLogged && c.Req.RequestURI == "/" && setting.LandingPageURL != setting.LANDING_PAGE_HOME {
- c.Redirect(setting.AppSubURL + string(setting.LandingPageURL))
+ if !c.IsLogged && c.Req.RequestURI == "/" && conf.Server.LandingURL != "/" {
+ c.Redirect(conf.Server.LandingURL)
return
}
// Redirect to dashboard if user tries to visit any non-login page.
if options.SignOutRequired && c.IsLogged && c.Req.RequestURI != "/" {
- c.Redirect(setting.AppSubURL + "/")
+ c.Redirect(conf.Server.Subpath + "/")
return
}
@@ -68,10 +68,10 @@ func Toggle(options *ToggleOptions) macaron.Handler {
return
}
- c.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+c.Req.RequestURI), 0, setting.AppSubURL)
- c.Redirect(setting.AppSubURL + "/user/login")
+ c.SetCookie("redirect_to", url.QueryEscape(conf.Server.Subpath+c.Req.RequestURI), 0, conf.Server.Subpath)
+ c.Redirect(conf.Server.Subpath + "/user/login")
return
- } else if !c.User.IsActive && setting.Service.RegisterEmailConfirm {
+ } else if !c.User.IsActive && conf.Service.RegisterEmailConfirm {
c.Data["Title"] = c.Tr("auth.active_your_account")
c.HTML(200, "user/auth/activate")
return
@@ -80,9 +80,9 @@ func Toggle(options *ToggleOptions) macaron.Handler {
// Redirect to log in page if auto-signin info is provided and has not signed in.
if !options.SignOutRequired && !c.IsLogged && !auth.IsAPIPath(c.Req.URL.Path) &&
- len(c.GetCookie(setting.CookieUserName)) > 0 {
- c.SetCookie("redirect_to", url.QueryEscape(setting.AppSubURL+c.Req.RequestURI), 0, setting.AppSubURL)
- c.Redirect(setting.AppSubURL + "/user/login")
+ len(c.GetCookie(conf.CookieUserName)) > 0 {
+ c.SetCookie("redirect_to", url.QueryEscape(conf.Server.Subpath+c.Req.RequestURI), 0, conf.Server.Subpath)
+ c.Redirect(conf.Server.Subpath + "/user/login")
return
}
diff --git a/internal/context/context.go b/internal/context/context.go
index de70e75c..65614362 100644
--- a/internal/context/context.go
+++ b/internal/context/context.go
@@ -21,10 +21,10 @@ import (
log "unknwon.dev/clog/v2"
"gogs.io/gogs/internal/auth"
+ "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/db/errors"
"gogs.io/gogs/internal/form"
- "gogs.io/gogs/internal/setting"
"gogs.io/gogs/internal/template"
)
@@ -151,9 +151,9 @@ func (c *Context) Redirect(location string, status ...int) {
}
// SubURLRedirect responses redirection wtih given location and status.
-// It prepends setting.AppSubURL to the location string.
+// It prepends setting.Server.Subpath to the location string.
func (c *Context) SubURLRedirect(location string, status ...int) {
- c.Redirect(setting.AppSubURL+location, status...)
+ c.Redirect(conf.Server.Subpath+location, status...)
}
// RenderWithErr used for page has form validation but need to prompt error to users.
@@ -174,7 +174,7 @@ func (c *Context) Handle(status int, msg string, err error) {
case http.StatusInternalServerError:
c.Data["Title"] = "Internal Server Error"
log.Error("%s: %v", msg, err)
- if !setting.ProdMode || (c.IsLogged && c.User.IsAdmin) {
+ if !conf.IsProdMode() || (c.IsLogged && c.User.IsAdmin) {
c.Data["ErrorMsg"] = err
}
}
@@ -233,7 +233,7 @@ func Contexter() macaron.Handler {
csrf: x,
Flash: f,
Session: sess,
- Link: setting.AppSubURL + strings.TrimSuffix(ctx.Req.URL.Path, "/"),
+ Link: conf.Server.Subpath + strings.TrimSuffix(ctx.Req.URL.Path, "/"),
Repo: &Repository{
PullRequest: &PullRequest{},
},
@@ -263,9 +263,9 @@ func Contexter() macaron.Handler {
branchName = repo.DefaultBranch
}
- prefix := setting.AppURL + path.Join(ownerName, repoName, "src", branchName)
+ prefix := conf.Server.ExternalURL + path.Join(ownerName, repoName, "src", branchName)
insecureFlag := ""
- if !strings.HasPrefix(setting.AppURL, "https://") {
+ if !strings.HasPrefix(conf.Server.ExternalURL, "https://") {
insecureFlag = "--insecure "
}
c.PlainText(http.StatusOK, []byte(com.Expand(`<!doctype html>
@@ -279,7 +279,7 @@ func Contexter() macaron.Handler {
</body>
</html>
`, map[string]string{
- "GoGetImport": path.Join(setting.HostAddress, setting.AppSubURL, repo.FullName()),
+ "GoGetImport": path.Join(conf.Server.URL.Host, conf.Server.Subpath, repo.FullName()),
"CloneLink": db.ComposeHTTPSCloneURL(ownerName, repoName),
"GoDocDirectory": prefix + "{/dir}",
"GoDocFile": prefix + "{/dir}/{file}#L{line}",
@@ -288,8 +288,8 @@ func Contexter() macaron.Handler {
return
}
- if len(setting.HTTP.AccessControlAllowOrigin) > 0 {
- c.Header().Set("Access-Control-Allow-Origin", setting.HTTP.AccessControlAllowOrigin)
+ if len(conf.HTTP.AccessControlAllowOrigin) > 0 {
+ c.Header().Set("Access-Control-Allow-Origin", conf.HTTP.AccessControlAllowOrigin)
c.Header().Set("'Access-Control-Allow-Credentials' ", "true")
c.Header().Set("Access-Control-Max-Age", "3600")
c.Header().Set("Access-Control-Allow-Headers", "Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With")
@@ -312,7 +312,7 @@ func Contexter() macaron.Handler {
// If request sends files, parse them here otherwise the Query() can't be parsed and the CsrfToken will be invalid.
if c.Req.Method == "POST" && strings.Contains(c.Req.Header.Get("Content-Type"), "multipart/form-data") {
- if err := c.Req.ParseMultipartForm(setting.AttachmentMaxSize << 20); err != nil && !strings.Contains(err.Error(), "EOF") { // 32MB max size
+ if err := c.Req.ParseMultipartForm(conf.AttachmentMaxSize << 20); err != nil && !strings.Contains(err.Error(), "EOF") { // 32MB max size
c.ServerError("ParseMultipartForm", err)
return
}
@@ -323,8 +323,8 @@ func Contexter() macaron.Handler {
log.Trace("Session ID: %s", sess.ID())
log.Trace("CSRF Token: %v", c.Data["CSRFToken"])
- c.Data["ShowRegistrationButton"] = setting.Service.ShowRegistrationButton
- c.Data["ShowFooterBranding"] = setting.ShowFooterBranding
+ c.Data["ShowRegistrationButton"] = conf.Service.ShowRegistrationButton
+ c.Data["ShowFooterBranding"] = conf.ShowFooterBranding
c.renderNoticeBanner()
diff --git a/internal/context/notice.go b/internal/context/notice.go
index dea72043..6f825fd8 100644
--- a/internal/context/notice.go
+++ b/internal/context/notice.go
@@ -6,20 +6,20 @@ package context
import (
"os"
- "path"
+ "path/filepath"
"github.com/unknwon/com"
log "unknwon.dev/clog/v2"
+ "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/markup"
- "gogs.io/gogs/internal/setting"
"gogs.io/gogs/internal/tool"
)
// renderNoticeBanner checks if a notice banner file exists and loads the message to display
// on all pages.
func (c *Context) renderNoticeBanner() {
- fpath := path.Join(setting.CustomPath, "notice", "banner.md")
+ fpath := filepath.Join(conf.CustomDir(), "notice", "banner.md")
if !com.IsExist(fpath) {
return
}
diff --git a/internal/context/org.go b/internal/context/org.go
index df9becd2..02e154ca 100644
--- a/internal/context/org.go
+++ b/internal/context/org.go
@@ -9,9 +9,9 @@ import (
"gopkg.in/macaron.v1"
+ "gogs.io/gogs/internal/conf"
"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/db/errors"
- "gogs.io/gogs/internal/setting"
)
type Organization struct {
@@ -91,7 +91,7 @@ func HandleOrgAssignment(c *Context, args ...bool) {
c.Data["IsOrganizationOwner"] = c.Org.IsOwner
c.Data["IsOrganizationMember"] = c.Org.IsMember
- c.Org.OrgLink = setting.AppSubURL + "/org/" + org.Name
+ c.Org.OrgLink = conf.Server.Subpath + "/org/" + org.Name
c.Data["OrgLink"] = c.Org.OrgLink
// Team.
diff --git a/internal/context/repo.go b/internal/context/repo.go
index 6e4a3bc1..7d030458 100644
--- a/internal/context/repo.go
+++ b/internal/context/repo.go
@@ -17,7 +17,7 @@ import (
"gogs.io/gogs/internal/db"
"gogs.io/gogs/internal/db/errors"
- "gogs.io/gogs/internal/setting"
+ "gogs.io/gogs/internal/conf"
)
type PullRequest struct {
@@ -248,8 +248,8 @@ func RepoAssignment(pages ...bool) macaron.Handler {
c.Data["IsRepositoryAdmin"] = c.Repo.IsAdmin()
c.Data["IsRepositoryWriter"] = c.Repo.IsWriter()
- c.Data["DisableSSH"] = setting.SSH.Disabled
- c.Data["DisableHTTP"] = setting.Repository.DisableHTTPGit
+ c.Data["DisableSSH"] = conf.SSH.Disabled
+ c.Data["DisableHTTP"] = conf.Repository.DisableHTTPGit
c.Data["CloneLink"] = repo.CloneLink()
c.Data["WikiCloneLink"] = repo.WikiCloneLink()