Skip to content

Commit 50a1757

Browse files
committed
fix
1 parent 3e044d2 commit 50a1757

16 files changed

+75
-159
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ WEBPACK_CONFIGS := webpack.config.js
119119
WEBPACK_DEST := public/assets/js/index.js public/assets/css/index.css
120120
WEBPACK_DEST_ENTRIES := public/assets/js public/assets/css public/assets/fonts public/assets/img/webpack
121121

122-
BINDATA_DEST := modules/public/bindata.go modules/options/bindata.go modules/templates/bindata.go
122+
BINDATA_DEST :=
123123
BINDATA_HASH := $(addsuffix .hash,$(BINDATA_DEST))
124124

125125
GENERATED_GO_DEST := modules/charset/invisible_gen.go modules/charset/ambiguous_gen.go

build.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,6 @@ package main
99
// These libraries will not be included in a normal compilation.
1010

1111
import (
12-
// for embed
13-
_ "github.com/shurcooL/vfsgen"
14-
1512
// for cover merge
1613
_ "golang.org/x/tools/cover"
1714

build/generate-bindata.go

Lines changed: 0 additions & 92 deletions
This file was deleted.

go.mod

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ require (
9393
github.com/santhosh-tekuri/jsonschema/v5 v5.3.0
9494
github.com/sassoftware/go-rpmutils v0.2.0
9595
github.com/sergi/go-diff v1.3.1
96-
github.com/shurcooL/vfsgen v0.0.0-20230704071429-0000e147ea92
9796
github.com/stretchr/testify v1.8.4
9897
github.com/syndtr/goleveldb v1.0.0
9998
github.com/tstranex/u2f v1.0.0
@@ -259,7 +258,6 @@ require (
259258
github.com/russross/blackfriday/v2 v2.1.0 // indirect
260259
github.com/segmentio/asm v1.2.0 // indirect
261260
github.com/shopspring/decimal v1.3.1 // indirect
262-
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c // indirect
263261
github.com/sirupsen/logrus v1.9.3 // indirect
264262
github.com/skeema/knownhosts v1.2.0 // indirect
265263
github.com/spf13/afero v1.9.5 // indirect
@@ -300,8 +298,6 @@ require (
300298

301299
replace github.com/hashicorp/go-version => github.com/6543/go-version v1.3.1
302300

303-
replace github.com/shurcooL/vfsgen => github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0
304-
305301
replace github.com/nektos/act => gitea.com/gitea/act v0.243.4
306302

307303
exclude github.com/gofrs/uuid v3.2.0+incompatible

go.sum

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,6 @@ github.com/libdns/libdns v0.2.1 h1:Wu59T7wSHRgtA0cfxC+n1c/e+O3upJGWytknkmFEDis=
728728
github.com/libdns/libdns v0.2.1/go.mod h1:yQCXzk1lEZmmCPa857bnk4TsOiqYasqpyOEeSObbb40=
729729
github.com/lunny/log v0.0.0-20160921050905-7887c61bf0de/go.mod h1:3q8WtuPQsoRbatJuy3nvq/hRSvuBJrHHr+ybPPiNvHQ=
730730
github.com/lunny/nodb v0.0.0-20160621015157-fc1ef06ad4af/go.mod h1:Cqz6pqow14VObJ7peltM+2n3PWOz7yTrfUuGbVFkzN0=
731-
github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0 h1:F/3FfGmKdiKFa8kL3YrpZ7pe9H4l4AzA1pbaOUnRvPI=
732-
github.com/lunny/vfsgen v0.0.0-20220105142115-2c99e1ffdfa0/go.mod h1:JEfTc3+2DF9Z4PXhLLvXL42zexJyh8rIq3OzUj/0rAk=
733731
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
734732
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
735733
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
@@ -923,8 +921,6 @@ github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24/go.mod h1:M+9Nz
923921
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
924922
github.com/shopspring/decimal v1.3.1 h1:2Usl1nmF/WZucqkFZhnfFYxxxu8LG21F6nPQBE5gKV8=
925923
github.com/shopspring/decimal v1.3.1/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
926-
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c h1:aqg5Vm5dwtvL+YgDpBcK1ITf3o96N/K7/wsRXQnUTEs=
927-
github.com/shurcooL/httpfs v0.0.0-20230704072500-f1e31cf0ba5c/go.mod h1:owqhoLW1qZoYLZzLnBw+QkPP9WZnjlSWihhxAJC1+/M=
928924
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
929925
github.com/siddontang/go-snappy v0.0.0-20140704025258-d8f7bb82a96d/go.mod h1:vq0tzqLRu6TS7Id0wMo2N5QzJoKedVeovOpHjnykSzY=
930926
github.com/siddontang/ledisdb v0.0.0-20190202134119-8ceb77e66a92/go.mod h1:mF1DpOSOUiJRMR+FDqaqu3EBqrybQtrDDszLUZ6oxPg=

main_bindata.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
//go:build bindata
5+
6+
package main
7+
8+
import (
9+
"embed"
10+
"io/fs"
11+
12+
"code.gitea.io/gitea/modules/migration"
13+
"code.gitea.io/gitea/modules/options"
14+
"code.gitea.io/gitea/modules/public"
15+
"code.gitea.io/gitea/modules/templates"
16+
)
17+
18+
//go:embed options public templates modules/migration/schemas
19+
var bindata embed.FS
20+
21+
func init() {
22+
migration.Assets, _ = fs.Sub(bindata, "modules/migration/schemas")
23+
options.Assets, _ = fs.Sub(bindata, "options")
24+
public.Assets, _ = fs.Sub(bindata, "public")
25+
templates.Assets, _ = fs.Sub(bindata, "templates")
26+
}

modules/assetfs/layered.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ func Local(name, base string, sub ...string) *Layer {
5151
}
5252

5353
// Bindata returns a new Layer with the given name, it serves files from the given bindata asset.
54-
func Bindata(name string, fs http.FileSystem) *Layer {
55-
return &Layer{name: name, fs: fs}
54+
func Bindata(name string, fs fs.FS) *Layer {
55+
return &Layer{name: name, fs: http.FS(fs)}
5656
}
5757

5858
// LayeredFS is a layered asset file-system. It works like http.FileSystem, but it can have multiple layers.

modules/migration/schemas_bindata.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

modules/migration/schemas_static.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ package migration
77

88
import (
99
"io"
10+
"io/fs"
1011
"path"
1112
)
1213

14+
var Assets fs.FS
15+
1316
func openSchema(filename string) (io.ReadCloser, error) {
1417
return Assets.Open(path.Base(filename))
1518
}

modules/options/options_bindata.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

modules/options/static.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66
package options
77

88
import (
9+
"io/fs"
10+
911
"code.gitea.io/gitea/modules/assetfs"
1012
)
1113

14+
var Assets fs.FS
15+
1216
func BuiltinAssets() *assetfs.Layer {
1317
return assetfs.Bindata("builtin(bindata)", Assets)
1418
}

modules/public/public.go

Lines changed: 34 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ package public
55

66
import (
77
"bytes"
8+
"compress/gzip"
89
"io"
910
"net/http"
1011
"os"
1112
"path"
1213
"strings"
14+
"sync"
1315
"time"
1416

1517
"code.gitea.io/gitea/modules/assetfs"
@@ -28,15 +30,20 @@ func AssetFS() *assetfs.LayeredFS {
2830
return assetfs.Layered(CustomAssets(), BuiltinAssets())
2931
}
3032

33+
type fileHandler struct {
34+
gzipContent sync.Map
35+
}
36+
3137
// FileHandlerFunc implements the static handler for serving files in "public" assets
3238
func FileHandlerFunc() http.HandlerFunc {
3339
assetFS := AssetFS()
40+
fh := fileHandler{}
3441
return func(resp http.ResponseWriter, req *http.Request) {
3542
if req.Method != "GET" && req.Method != "HEAD" {
3643
resp.WriteHeader(http.StatusNotFound)
3744
return
3845
}
39-
handleRequest(resp, req, assetFS, req.URL.Path)
46+
fh.handleRequest(resp, req, assetFS, req.URL.Path)
4047
}
4148
}
4249

@@ -59,7 +66,7 @@ func setWellKnownContentType(w http.ResponseWriter, file string) {
5966
}
6067
}
6168

62-
func handleRequest(w http.ResponseWriter, req *http.Request, fs http.FileSystem, file string) {
69+
func (fh *fileHandler) handleRequest(w http.ResponseWriter, req *http.Request, fs http.FileSystem, file string) {
6370
// actually, fs (http.FileSystem) is designed to be a safe interface, relative paths won't bypass its parent directory, it's also fine to do a clean here
6471
f, err := fs.Open(util.PathJoinRelX(file))
6572
if err != nil {
@@ -86,31 +93,38 @@ func handleRequest(w http.ResponseWriter, req *http.Request, fs http.FileSystem,
8693
return
8794
}
8895

89-
serveContent(w, req, fi, fi.ModTime(), f)
90-
}
91-
92-
type GzipBytesProvider interface {
93-
GzipBytes() []byte
96+
fh.serveContent(w, req, fi, fi.ModTime(), f)
9497
}
9598

9699
// serveContent serve http content
97-
func serveContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) {
100+
func (fh *fileHandler) serveContent(w http.ResponseWriter, req *http.Request, fi os.FileInfo, modtime time.Time, content io.ReadSeeker) {
98101
setWellKnownContentType(w, fi.Name())
99102

100103
encodings := parseAcceptEncoding(req.Header.Get("Accept-Encoding"))
101-
if encodings.Contains("gzip") {
102-
// try to provide gzip content directly from bindata (provided by vfsgen۰CompressedFileInfo)
103-
if compressed, ok := fi.(GzipBytesProvider); ok {
104-
rdGzip := bytes.NewReader(compressed.GzipBytes())
105-
// all gzipped static files (from bindata) are managed by Gitea, so we can make sure every file has the correct ext name
106-
// then we can get the correct Content-Type, we do not need to do http.DetectContentType on the decompressed data
107-
if w.Header().Get("Content-Type") == "" {
108-
w.Header().Set("Content-Type", "application/octet-stream")
109-
}
110-
w.Header().Set("Content-Encoding", "gzip")
111-
httpcache.ServeContentWithCacheControl(w, req, fi.Name(), modtime, rdGzip)
112-
return
104+
fileName := fi.Name()
105+
compressible := strings.HasSuffix(fileName, ".txt") || strings.HasSuffix(fileName, ".js") || strings.HasSuffix(fileName, ".css") || strings.HasSuffix(fileName, ".svg")
106+
compressible = compressible && fi.Size() > 512
107+
if encodings.Contains("gzip") && compressible {
108+
var compressedBytes []byte
109+
if compressed, ok := fh.gzipContent.Load(fileName); !ok {
110+
buf := &bytes.Buffer{}
111+
c := gzip.NewWriter(buf)
112+
_, _ = io.Copy(c, content)
113+
_ = c.Close()
114+
compressedBytes = buf.Bytes()
115+
fh.gzipContent.Store(fileName, compressedBytes)
116+
} else {
117+
compressedBytes = compressed.([]byte)
118+
}
119+
rdGzip := bytes.NewReader(compressedBytes)
120+
// all gzipped static files (from bindata) are managed by Gitea, so we can make sure every file has the correct ext name
121+
// then we can get the correct Content-Type, we do not need to do http.DetectContentType on the decompressed data
122+
if w.Header().Get("Content-Type") == "" {
123+
w.Header().Set("Content-Type", "application/octet-stream")
113124
}
125+
w.Header().Set("Content-Encoding", "gzip")
126+
httpcache.ServeContentWithCacheControl(w, req, fi.Name(), modtime, rdGzip)
127+
return
114128
}
115129

116130
httpcache.ServeContentWithCacheControl(w, req, fi.Name(), modtime, content)

modules/public/public_bindata.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

modules/public/serve_static.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
package public
77

88
import (
9+
"io/fs"
910
"time"
1011

1112
"code.gitea.io/gitea/modules/assetfs"
1213
"code.gitea.io/gitea/modules/timeutil"
1314
)
1415

15-
var _ GzipBytesProvider = (*vfsgen۰CompressedFileInfo)(nil)
16+
var Assets fs.FS
1617

1718
// GlobalModTime provide a global mod time for embedded asset files
1819
func GlobalModTime(filename string) time.Time {

modules/templates/static.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
package templates
77

88
import (
9+
"io/fs"
910
"time"
1011

1112
"code.gitea.io/gitea/modules/assetfs"
1213
"code.gitea.io/gitea/modules/timeutil"
1314
)
1415

16+
var Assets fs.FS
17+
1518
// GlobalModTime provide a global mod time for embedded asset files
1619
func GlobalModTime(filename string) time.Time {
1720
return timeutil.GetExecutableModTime()

modules/templates/templates_bindata.go

Lines changed: 0 additions & 8 deletions
This file was deleted.

0 commit comments

Comments
 (0)