Skip to content

Commit 78535fb

Browse files
authored
Allow custom public files (#782)
* Allow custom public files * Gofmt code, lots of places not related to this pr
1 parent cc31a21 commit 78535fb

File tree

7 files changed

+26
-6
lines changed

7 files changed

+26
-6
lines changed

cmd/web.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ func newMacaron() *macaron.Macaron {
8888
if setting.Protocol == setting.FCGI {
8989
m.SetURLPrefix(setting.AppSubURL)
9090
}
91+
m.Use(public.Custom(
92+
&public.Options{
93+
SkipLogging: setting.DisableRouterLog,
94+
},
95+
))
9196
m.Use(public.Static(
9297
&public.Options{
9398
Directory: path.Join(setting.StaticRootPath, "public"),

models/attachment.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ type Attachment struct {
3131
CreatedUnix int64
3232
}
3333

34-
3534
// BeforeInsert is invoked from XORM before inserting an object of this type.
3635
func (a *Attachment) BeforeInsert() {
3736
a.CreatedUnix = time.Now().Unix()

models/pull.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ import (
1414
"time"
1515

1616
"code.gitea.io/git"
17+
"code.gitea.io/gitea/modules/base"
1718
"code.gitea.io/gitea/modules/log"
1819
"code.gitea.io/gitea/modules/process"
1920
"code.gitea.io/gitea/modules/setting"
2021
"code.gitea.io/gitea/modules/sync"
2122
api "code.gitea.io/sdk/gitea"
2223
"github.com/Unknwon/com"
2324
"github.com/go-xorm/xorm"
24-
"code.gitea.io/gitea/modules/base"
2525
)
2626

2727
var pullRequestQueue = sync.NewUniqueQueue(setting.Repository.PullRequestQueueLength)

modules/public/public.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44

55
package public
66

7+
import (
8+
"path"
9+
10+
"code.gitea.io/gitea/modules/setting"
11+
"gopkg.in/macaron.v1"
12+
)
13+
714
//go:generate go-bindata -tags "bindata" -ignore "\\.go|\\.less" -pkg "public" -o "bindata.go" ../../public/...
815
//go:generate go fmt bindata.go
916
//go:generate sed -i.bak s/..\/..\/public\/// bindata.go
@@ -14,3 +21,13 @@ type Options struct {
1421
Directory string
1522
SkipLogging bool
1623
}
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+
}

routers/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/modules/cron"
1414
"code.gitea.io/gitea/modules/highlight"
15+
"code.gitea.io/gitea/modules/indexer"
1516
"code.gitea.io/gitea/modules/log"
1617
"code.gitea.io/gitea/modules/mailer"
1718
"code.gitea.io/gitea/modules/markdown"
1819
"code.gitea.io/gitea/modules/setting"
1920
"code.gitea.io/gitea/modules/ssh"
2021
macaron "gopkg.in/macaron.v1"
21-
"code.gitea.io/gitea/modules/indexer"
2222
)
2323

2424
func checkRunMode() {

routers/repo/attachment.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,3 @@ func UploadAttachment(ctx *context.Context) {
7070
"uuid": attach.UUID,
7171
})
7272
}
73-

routers/repo/release.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ func NewRelease(ctx *context.Context) {
169169
ctx.Data["Title"] = ctx.Tr("repo.release.new_release")
170170
ctx.Data["PageIsReleaseList"] = true
171171
ctx.Data["tag_target"] = ctx.Repo.Repository.DefaultBranch
172-
renderAttachmentSettings(ctx);
172+
renderAttachmentSettings(ctx)
173173
ctx.HTML(200, tplReleaseNew)
174174
}
175175

@@ -250,7 +250,7 @@ func EditRelease(ctx *context.Context) {
250250
ctx.Data["Title"] = ctx.Tr("repo.release.edit_release")
251251
ctx.Data["PageIsReleaseList"] = true
252252
ctx.Data["PageIsEditRelease"] = true
253-
renderAttachmentSettings(ctx);
253+
renderAttachmentSettings(ctx)
254254

255255
tagName := ctx.Params("*")
256256
rel, err := models.GetRelease(ctx.Repo.Repository.ID, tagName)

0 commit comments

Comments
 (0)