Browse Source

Allow custom public files (#782)

* Allow custom public files

* Gofmt code, lots of places not related to this pr
Thomas Boerger 3 years ago
parent
commit
78535fb08e
7 changed files with 26 additions and 6 deletions
  1. 5 0
      cmd/web.go
  2. 0 1
      models/attachment.go
  3. 1 1
      models/pull.go
  4. 17 0
      modules/public/public.go
  5. 1 1
      routers/init.go
  6. 0 1
      routers/repo/attachment.go
  7. 2 2
      routers/repo/release.go

+ 5 - 0
cmd/web.go

@@ -88,6 +88,11 @@ func newMacaron() *macaron.Macaron {
88 88
 	if setting.Protocol == setting.FCGI {
89 89
 		m.SetURLPrefix(setting.AppSubURL)
90 90
 	}
91
+	m.Use(public.Custom(
92
+		&public.Options{
93
+			SkipLogging: setting.DisableRouterLog,
94
+		},
95
+	))
91 96
 	m.Use(public.Static(
92 97
 		&public.Options{
93 98
 			Directory:   path.Join(setting.StaticRootPath, "public"),

+ 0 - 1
models/attachment.go

@@ -31,7 +31,6 @@ type Attachment struct {
31 31
 	CreatedUnix int64
32 32
 }
33 33
 
34
-
35 34
 // BeforeInsert is invoked from XORM before inserting an object of this type.
36 35
 func (a *Attachment) BeforeInsert() {
37 36
 	a.CreatedUnix = time.Now().Unix()

+ 1 - 1
models/pull.go

@@ -14,6 +14,7 @@ import (
14 14
 	"time"
15 15
 
16 16
 	"code.gitea.io/git"
17
+	"code.gitea.io/gitea/modules/base"
17 18
 	"code.gitea.io/gitea/modules/log"
18 19
 	"code.gitea.io/gitea/modules/process"
19 20
 	"code.gitea.io/gitea/modules/setting"
@@ -21,7 +22,6 @@ import (
21 22
 	api "code.gitea.io/sdk/gitea"
22 23
 	"github.com/Unknwon/com"
23 24
 	"github.com/go-xorm/xorm"
24
-	"code.gitea.io/gitea/modules/base"
25 25
 )
26 26
 
27 27
 var pullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLength)

+ 17 - 0
modules/public/public.go

@@ -4,6 +4,13 @@
4 4
 
5 5
 package public
6 6
 
7
+import (
8
+	"path"
9
+
10
+	"code.gitea.io/gitea/modules/setting"
11
+	"gopkg.in/macaron.v1"
12
+)
13
+
7 14
 //go:generate go-bindata -tags "bindata" -ignore "\\.go|\\.less" -pkg "public" -o "bindata.go" ../../public/...
8 15
 //go:generate go fmt bindata.go
9 16
 //go:generate sed -i.bak s/..\/..\/public\/// bindata.go
@@ -14,3 +21,13 @@ type Options struct {
14 21
 	Directory   string
15 22
 	SkipLogging bool
16 23
 }
24
+
25
+// Custom implements the macaron static handler for serving custom assets.
26
+func Custom(opts *Options) macaron.Handler {
27
+	return macaron.Static(
28
+		path.Join(setting.CustomPath, "public"),
29
+		macaron.StaticOptions{
30
+			SkipLogging: opts.SkipLogging,
31
+		},
32
+	)
33
+}

+ 1 - 1
routers/init.go

@@ -12,13 +12,13 @@ import (
12 12
 	"code.gitea.io/gitea/models"
13 13
 	"code.gitea.io/gitea/modules/cron"
14 14
 	"code.gitea.io/gitea/modules/highlight"
15
+	"code.gitea.io/gitea/modules/indexer"
15 16
 	"code.gitea.io/gitea/modules/log"
16 17
 	"code.gitea.io/gitea/modules/mailer"
17 18
 	"code.gitea.io/gitea/modules/markdown"
18 19
 	"code.gitea.io/gitea/modules/setting"
19 20
 	"code.gitea.io/gitea/modules/ssh"
20 21
 	macaron "gopkg.in/macaron.v1"
21
-	"code.gitea.io/gitea/modules/indexer"
22 22
 )
23 23
 
24 24
 func checkRunMode() {

+ 0 - 1
routers/repo/attachment.go

@@ -70,4 +70,3 @@ func UploadAttachment(ctx *context.Context) {
70 70
 		"uuid": attach.UUID,
71 71
 	})
72 72
 }
73
-

+ 2 - 2
routers/repo/release.go

@@ -169,7 +169,7 @@ func NewRelease(ctx *context.Context) {
169 169
 	ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
170 170
 	ctx.Data["PageIsReleaseList"] = true
171 171
 	ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
172
-	renderAttachmentSettings(ctx);
172
+	renderAttachmentSettings(ctx)
173 173
 	ctx.HTML(200, tplReleaseNew)
174 174
 }
175 175
 
@@ -250,7 +250,7 @@ func EditRelease(ctx *context.Context) {
250 250
 	ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
251 251
 	ctx.Data["PageIsReleaseList"] = true
252 252
 	ctx.Data["PageIsEditRelease"] = true
253
-	renderAttachmentSettings(ctx);
253
+	renderAttachmentSettings(ctx)
254 254
 
255 255
 	tagName := ctx.Params("*")
256 256
 	rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)