Skip to content

Commit 1e87761

Browse files
a1012112796silverwindlunnyzeripath
authored
add /assets as root dir of public files (#15219)
* add `/assets` as root dir of public files Signed-off-by: a1012112796 <[email protected]> * move serviceworker.js * make fmt * fix some link * fix test * Apply suggestions from code review Co-authored-by: silverwind <[email protected]> * Apply suggestions from code review Co-authored-by: silverwind <[email protected]> Co-authored-by: silverwind <[email protected]> Co-authored-by: Lunny Xiao <[email protected]> Co-authored-by: zeripath <[email protected]>
1 parent cc7d118 commit 1e87761

File tree

12 files changed

+29
-26
lines changed

12 files changed

+29
-26
lines changed

integrations/links_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func TestRedirectsNoLogin(t *testing.T) {
5151
"/user2/repo1/src/master": "/user2/repo1/src/branch/master",
5252
"/user2/repo1/src/master/file.txt": "/user2/repo1/src/branch/master/file.txt",
5353
"/user2/repo1/src/master/directory/file.txt": "/user2/repo1/src/branch/master/directory/file.txt",
54-
"/user/avatar/Ghost/-1": "/img/avatar_default.png",
54+
"/user/avatar/Ghost/-1": "/assets/img/avatar_default.png",
5555
"/api/v1/swagger": "/api/swagger",
5656
}
5757
for link, redirectLink := range redirects {

models/avatar.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func DefaultAvatarLink() string {
3232
return ""
3333
}
3434

35-
u.Path = path.Join(u.Path, "/img/avatar_default.png")
35+
u.Path = path.Join(u.Path, "/assets/img/avatar_default.png")
3636
return u.String()
3737
}
3838

models/avatar_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestHashEmail(t *testing.T) {
4141

4242
func TestSizedAvatarLink(t *testing.T) {
4343
disableGravatar()
44-
assert.Equal(t, "/suburl/img/avatar_default.png",
44+
assert.Equal(t, "/suburl/assets/img/avatar_default.png",
4545
SizedAvatarLink("[email protected]", 100))
4646

4747
enableGravatar(t)

models/oauth2.go

+13-13
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ type OAuth2Provider struct {
2323
// key is used to map the OAuth2Provider with the goth provider type (also in LoginSource.OAuth2Config.Provider)
2424
// value is used to store display data
2525
var OAuth2Providers = map[string]OAuth2Provider{
26-
"bitbucket": {Name: "bitbucket", DisplayName: "Bitbucket", Image: "/img/auth/bitbucket.png"},
27-
"dropbox": {Name: "dropbox", DisplayName: "Dropbox", Image: "/img/auth/dropbox.png"},
28-
"facebook": {Name: "facebook", DisplayName: "Facebook", Image: "/img/auth/facebook.png"},
26+
"bitbucket": {Name: "bitbucket", DisplayName: "Bitbucket", Image: "/assets/img/auth/bitbucket.png"},
27+
"dropbox": {Name: "dropbox", DisplayName: "Dropbox", Image: "/assets/img/auth/dropbox.png"},
28+
"facebook": {Name: "facebook", DisplayName: "Facebook", Image: "/assets/img/auth/facebook.png"},
2929
"github": {
30-
Name: "github", DisplayName: "GitHub", Image: "/img/auth/github.png",
30+
Name: "github", DisplayName: "GitHub", Image: "/assets/img/auth/github.png",
3131
CustomURLMapping: &oauth2.CustomURLMapping{
3232
TokenURL: oauth2.GetDefaultTokenURL("github"),
3333
AuthURL: oauth2.GetDefaultAuthURL("github"),
@@ -36,36 +36,36 @@ var OAuth2Providers = map[string]OAuth2Provider{
3636
},
3737
},
3838
"gitlab": {
39-
Name: "gitlab", DisplayName: "GitLab", Image: "/img/auth/gitlab.png",
39+
Name: "gitlab", DisplayName: "GitLab", Image: "/assets/img/auth/gitlab.png",
4040
CustomURLMapping: &oauth2.CustomURLMapping{
4141
TokenURL: oauth2.GetDefaultTokenURL("gitlab"),
4242
AuthURL: oauth2.GetDefaultAuthURL("gitlab"),
4343
ProfileURL: oauth2.GetDefaultProfileURL("gitlab"),
4444
},
4545
},
46-
"gplus": {Name: "gplus", DisplayName: "Google", Image: "/img/auth/google.png"},
47-
"openidConnect": {Name: "openidConnect", DisplayName: "OpenID Connect", Image: "/img/auth/openid_connect.svg"},
48-
"twitter": {Name: "twitter", DisplayName: "Twitter", Image: "/img/auth/twitter.png"},
49-
"discord": {Name: "discord", DisplayName: "Discord", Image: "/img/auth/discord.png"},
46+
"gplus": {Name: "gplus", DisplayName: "Google", Image: "/assets/img/auth/google.png"},
47+
"openidConnect": {Name: "openidConnect", DisplayName: "OpenID Connect", Image: "/assets/img/auth/openid_connect.svg"},
48+
"twitter": {Name: "twitter", DisplayName: "Twitter", Image: "/assets/img/auth/twitter.png"},
49+
"discord": {Name: "discord", DisplayName: "Discord", Image: "/assets/img/auth/discord.png"},
5050
"gitea": {
51-
Name: "gitea", DisplayName: "Gitea", Image: "/img/auth/gitea.png",
51+
Name: "gitea", DisplayName: "Gitea", Image: "/assets/img/auth/gitea.png",
5252
CustomURLMapping: &oauth2.CustomURLMapping{
5353
TokenURL: oauth2.GetDefaultTokenURL("gitea"),
5454
AuthURL: oauth2.GetDefaultAuthURL("gitea"),
5555
ProfileURL: oauth2.GetDefaultProfileURL("gitea"),
5656
},
5757
},
5858
"nextcloud": {
59-
Name: "nextcloud", DisplayName: "Nextcloud", Image: "/img/auth/nextcloud.png",
59+
Name: "nextcloud", DisplayName: "Nextcloud", Image: "/assets/img/auth/nextcloud.png",
6060
CustomURLMapping: &oauth2.CustomURLMapping{
6161
TokenURL: oauth2.GetDefaultTokenURL("nextcloud"),
6262
AuthURL: oauth2.GetDefaultAuthURL("nextcloud"),
6363
ProfileURL: oauth2.GetDefaultProfileURL("nextcloud"),
6464
},
6565
},
66-
"yandex": {Name: "yandex", DisplayName: "Yandex", Image: "/img/auth/yandex.png"},
66+
"yandex": {Name: "yandex", DisplayName: "Yandex", Image: "/assets/img/auth/yandex.png"},
6767
"mastodon": {
68-
Name: "mastodon", DisplayName: "Mastodon", Image: "/img/auth/mastodon.png",
68+
Name: "mastodon", DisplayName: "Mastodon", Image: "/assets/img/auth/mastodon.png",
6969
CustomURLMapping: &oauth2.CustomURLMapping{
7070
AuthURL: oauth2.GetDefaultAuthURL("mastodon"),
7171
},

models/user.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"code.gitea.io/gitea/modules/generate"
2626
"code.gitea.io/gitea/modules/git"
2727
"code.gitea.io/gitea/modules/log"
28-
"code.gitea.io/gitea/modules/public"
2928
"code.gitea.io/gitea/modules/setting"
3029
"code.gitea.io/gitea/modules/storage"
3130
"code.gitea.io/gitea/modules/structs"
@@ -772,7 +771,7 @@ func (u *User) IsGhost() bool {
772771
}
773772

774773
var (
775-
reservedUsernames = append([]string{
774+
reservedUsernames = []string{
776775
".",
777776
"..",
778777
".well-known",
@@ -807,7 +806,8 @@ var (
807806
"stars",
808807
"template",
809808
"user",
810-
}, public.KnownPublicEntries...)
809+
"favicon.ico",
810+
}
811811

812812
reservedUserPatterns = []string{"*.keys", "*.gpg"}
813813
)

modules/public/public.go

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ var KnownPublicEntries = []string{
3232
"js",
3333
"serviceworker.js",
3434
"vendor",
35-
"favicon.ico",
3635
}
3736

3837
// Custom implements the static handler for serving custom assets.

modules/setting/picture.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,5 @@ func newRepoAvatarService() {
110110
RepoAvatar.Storage = getStorage("repo-avatars", storageType, repoAvatarSec)
111111

112112
RepoAvatar.Fallback = sec.Key("REPOSITORY_AVATAR_FALLBACK").MustString("none")
113-
RepoAvatar.FallbackImage = sec.Key("REPOSITORY_AVATAR_FALLBACK_IMAGE").MustString("/img/repo_default.png")
113+
RepoAvatar.FallbackImage = sec.Key("REPOSITORY_AVATAR_FALLBACK_IMAGE").MustString("/assets/img/repo_default.png")
114114
}

modules/setting/setting.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1139,12 +1139,12 @@ func MakeManifestData(appName string, appURL string, absoluteAssetURL string) []
11391139
StartURL: appURL,
11401140
Icons: []manifestIcon{
11411141
{
1142-
Src: absoluteAssetURL + "/img/logo.png",
1142+
Src: absoluteAssetURL + "/assets/img/logo.png",
11431143
Type: "image/png",
11441144
Sizes: "512x512",
11451145
},
11461146
{
1147-
Src: absoluteAssetURL + "/img/logo.svg",
1147+
Src: absoluteAssetURL + "/assets/img/logo.svg",
11481148
Type: "image/svg+xml",
11491149
Sizes: "512x512",
11501150
},

modules/templates/helper.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func NewFuncMap() []template.FuncMap {
6161
return setting.AppSubURL
6262
},
6363
"StaticUrlPrefix": func() string {
64-
return setting.StaticURLPrefix
64+
return setting.StaticURLPrefix + "/assets"
6565
},
6666
"AppUrl": func() string {
6767
return setting.AppURL

routers/routes/web.go

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func WebRoutes() *web.Route {
152152
&public.Options{
153153
Directory: path.Join(setting.StaticRootPath, "public"),
154154
SkipLogging: setting.DisableRouterLog,
155+
Prefix: "/assets",
155156
},
156157
))
157158

routers/user/profile.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,14 @@ func GetUserByParams(ctx *context.Context) *models.User {
4646
// Profile render user's profile page
4747
func Profile(ctx *context.Context) {
4848
uname := ctx.Params(":username")
49+
4950
// Special handle for FireFox requests favicon.ico.
5051
if uname == "favicon.ico" {
5152
ctx.ServeFile(path.Join(setting.StaticRootPath, "public/img/favicon.png"))
5253
return
53-
} else if strings.HasSuffix(uname, ".png") {
54+
}
55+
56+
if strings.HasSuffix(uname, ".png") {
5457
ctx.Error(http.StatusNotFound)
5558
return
5659
}

web_src/js/features/serviceworker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export default async function initServiceWorker() {
3535
// the spec strictly requires it to be same-origin so it has to be AppSubUrl to work
3636
await Promise.all([
3737
checkCacheValidity(),
38-
navigator.serviceWorker.register(`${AppSubUrl}/serviceworker.js`),
38+
navigator.serviceWorker.register(`${AppSubUrl}/assets/serviceworker.js`),
3939
]);
4040
} catch (err) {
4141
console.error(err);

0 commit comments

Comments
 (0)