Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add /assets as root dir of public files #15219

Merged
merged 22 commits into from
Apr 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"code.gitea.io/gitea/modules/generate"
"code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/structs"
Expand Down Expand Up @@ -780,7 +779,7 @@ func (u *User) IsGhost() bool {
}

var (
reservedUsernames = append([]string{
reservedUsernames = []string{
".",
"..",
".well-known",
Expand Down Expand Up @@ -815,7 +814,9 @@ var (
"stars",
"template",
"user",
}, public.KnownPublicEntries...)
"favicon.ico",
"serviceworker.js",
}

reservedUserPatterns = []string{"*.keys", "*.gpg"}
)
Expand Down
1 change: 0 additions & 1 deletion modules/public/public.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ var KnownPublicEntries = []string{
"js",
"serviceworker.js",
"vendor",
"favicon.ico",
}

// Custom implements the static handler for serving custom assets.
Expand Down
4 changes: 2 additions & 2 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -1144,12 +1144,12 @@ func MakeManifestData(appName string, appURL string, absoluteAssetURL string) []
StartURL: appURL,
Icons: []manifestIcon{
{
Src: absoluteAssetURL + "/img/logo.png",
Src: absoluteAssetURL + "/assets/img/logo.png",
Type: "image/png",
Sizes: "512x512",
},
{
Src: absoluteAssetURL + "/img/logo.svg",
Src: absoluteAssetURL + "/assets/img/logo.svg",
Type: "image/svg+xml",
Sizes: "512x512",
},
Expand Down
2 changes: 1 addition & 1 deletion modules/templates/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func NewFuncMap() []template.FuncMap {
return setting.AppSubURL
},
"StaticUrlPrefix": func() string {
return setting.StaticURLPrefix
return setting.StaticURLPrefix + "/assets"
},
"AppUrl": func() string {
return setting.AppURL
Expand Down
1 change: 1 addition & 0 deletions routers/routes/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func WebRoutes() *web.Route {
&public.Options{
Directory: path.Join(setting.StaticRootPath, "public"),
SkipLogging: setting.DisableRouterLog,
Prefix: "/assets",
},
))

Expand Down
12 changes: 10 additions & 2 deletions routers/user/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,19 @@ func GetUserByParams(ctx *context.Context) *models.User {
// Profile render user's profile page
func Profile(ctx *context.Context) {
uname := ctx.Params(":username")
// Special handle for FireFox requests favicon.ico.

// Special handle for requests `favicon.ico` and `serviceworker.js`.
if uname == "favicon.ico" {
ctx.ServeFile(path.Join(setting.StaticRootPath, "public/img/favicon.png"))
return
} else if strings.HasSuffix(uname, ".png") {
}

if uname == "serviceworker.js" {
ctx.ServeFile(path.Join(setting.StaticRootPath, "public/serviceworker.js"))
return
}

if strings.HasSuffix(uname, ".png") {
ctx.Error(404)
return
}
Expand Down