1
1
mirror of https://github.com/go-gitea/gitea synced 2024-06-02 17:35:49 +00:00

add /assets as root dir of public files (#15219)

* add `/assets` as root dir of public files

Signed-off-by: a1012112796 <1012112796@qq.com>

* move serviceworker.js

* make fmt

* fix some link

* fix test

* Apply suggestions from code review

Co-authored-by: silverwind <me@silverwind.io>

* Apply suggestions from code review

Co-authored-by: silverwind <me@silverwind.io>

Co-authored-by: silverwind <me@silverwind.io>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: zeripath <art27@cantab.net>
This commit is contained in:
a1012112796 2021-04-28 20:35:06 +08:00 committed by GitHub
parent cc7d118b12
commit 1e877613bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 29 additions and 26 deletions

View File

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

View File

@ -32,7 +32,7 @@ func DefaultAvatarLink() string {
return "" return ""
} }
u.Path = path.Join(u.Path, "/img/avatar_default.png") u.Path = path.Join(u.Path, "/assets/img/avatar_default.png")
return u.String() return u.String()
} }

View File

@ -41,7 +41,7 @@ func TestHashEmail(t *testing.T) {
func TestSizedAvatarLink(t *testing.T) { func TestSizedAvatarLink(t *testing.T) {
disableGravatar() disableGravatar()
assert.Equal(t, "/suburl/img/avatar_default.png", assert.Equal(t, "/suburl/assets/img/avatar_default.png",
SizedAvatarLink("gitea@example.com", 100)) SizedAvatarLink("gitea@example.com", 100))
enableGravatar(t) enableGravatar(t)

View File

@ -23,11 +23,11 @@ type OAuth2Provider struct {
// key is used to map the OAuth2Provider with the goth provider type (also in LoginSource.OAuth2Config.Provider) // key is used to map the OAuth2Provider with the goth provider type (also in LoginSource.OAuth2Config.Provider)
// value is used to store display data // value is used to store display data
var OAuth2Providers = map[string]OAuth2Provider{ var OAuth2Providers = map[string]OAuth2Provider{
"bitbucket": {Name: "bitbucket", DisplayName: "Bitbucket", Image: "/img/auth/bitbucket.png"}, "bitbucket": {Name: "bitbucket", DisplayName: "Bitbucket", Image: "/assets/img/auth/bitbucket.png"},
"dropbox": {Name: "dropbox", DisplayName: "Dropbox", Image: "/img/auth/dropbox.png"}, "dropbox": {Name: "dropbox", DisplayName: "Dropbox", Image: "/assets/img/auth/dropbox.png"},
"facebook": {Name: "facebook", DisplayName: "Facebook", Image: "/img/auth/facebook.png"}, "facebook": {Name: "facebook", DisplayName: "Facebook", Image: "/assets/img/auth/facebook.png"},
"github": { "github": {
Name: "github", DisplayName: "GitHub", Image: "/img/auth/github.png", Name: "github", DisplayName: "GitHub", Image: "/assets/img/auth/github.png",
CustomURLMapping: &oauth2.CustomURLMapping{ CustomURLMapping: &oauth2.CustomURLMapping{
TokenURL: oauth2.GetDefaultTokenURL("github"), TokenURL: oauth2.GetDefaultTokenURL("github"),
AuthURL: oauth2.GetDefaultAuthURL("github"), AuthURL: oauth2.GetDefaultAuthURL("github"),
@ -36,19 +36,19 @@ var OAuth2Providers = map[string]OAuth2Provider{
}, },
}, },
"gitlab": { "gitlab": {
Name: "gitlab", DisplayName: "GitLab", Image: "/img/auth/gitlab.png", Name: "gitlab", DisplayName: "GitLab", Image: "/assets/img/auth/gitlab.png",
CustomURLMapping: &oauth2.CustomURLMapping{ CustomURLMapping: &oauth2.CustomURLMapping{
TokenURL: oauth2.GetDefaultTokenURL("gitlab"), TokenURL: oauth2.GetDefaultTokenURL("gitlab"),
AuthURL: oauth2.GetDefaultAuthURL("gitlab"), AuthURL: oauth2.GetDefaultAuthURL("gitlab"),
ProfileURL: oauth2.GetDefaultProfileURL("gitlab"), ProfileURL: oauth2.GetDefaultProfileURL("gitlab"),
}, },
}, },
"gplus": {Name: "gplus", DisplayName: "Google", Image: "/img/auth/google.png"}, "gplus": {Name: "gplus", DisplayName: "Google", Image: "/assets/img/auth/google.png"},
"openidConnect": {Name: "openidConnect", DisplayName: "OpenID Connect", Image: "/img/auth/openid_connect.svg"}, "openidConnect": {Name: "openidConnect", DisplayName: "OpenID Connect", Image: "/assets/img/auth/openid_connect.svg"},
"twitter": {Name: "twitter", DisplayName: "Twitter", Image: "/img/auth/twitter.png"}, "twitter": {Name: "twitter", DisplayName: "Twitter", Image: "/assets/img/auth/twitter.png"},
"discord": {Name: "discord", DisplayName: "Discord", Image: "/img/auth/discord.png"}, "discord": {Name: "discord", DisplayName: "Discord", Image: "/assets/img/auth/discord.png"},
"gitea": { "gitea": {
Name: "gitea", DisplayName: "Gitea", Image: "/img/auth/gitea.png", Name: "gitea", DisplayName: "Gitea", Image: "/assets/img/auth/gitea.png",
CustomURLMapping: &oauth2.CustomURLMapping{ CustomURLMapping: &oauth2.CustomURLMapping{
TokenURL: oauth2.GetDefaultTokenURL("gitea"), TokenURL: oauth2.GetDefaultTokenURL("gitea"),
AuthURL: oauth2.GetDefaultAuthURL("gitea"), AuthURL: oauth2.GetDefaultAuthURL("gitea"),
@ -56,16 +56,16 @@ var OAuth2Providers = map[string]OAuth2Provider{
}, },
}, },
"nextcloud": { "nextcloud": {
Name: "nextcloud", DisplayName: "Nextcloud", Image: "/img/auth/nextcloud.png", Name: "nextcloud", DisplayName: "Nextcloud", Image: "/assets/img/auth/nextcloud.png",
CustomURLMapping: &oauth2.CustomURLMapping{ CustomURLMapping: &oauth2.CustomURLMapping{
TokenURL: oauth2.GetDefaultTokenURL("nextcloud"), TokenURL: oauth2.GetDefaultTokenURL("nextcloud"),
AuthURL: oauth2.GetDefaultAuthURL("nextcloud"), AuthURL: oauth2.GetDefaultAuthURL("nextcloud"),
ProfileURL: oauth2.GetDefaultProfileURL("nextcloud"), ProfileURL: oauth2.GetDefaultProfileURL("nextcloud"),
}, },
}, },
"yandex": {Name: "yandex", DisplayName: "Yandex", Image: "/img/auth/yandex.png"}, "yandex": {Name: "yandex", DisplayName: "Yandex", Image: "/assets/img/auth/yandex.png"},
"mastodon": { "mastodon": {
Name: "mastodon", DisplayName: "Mastodon", Image: "/img/auth/mastodon.png", Name: "mastodon", DisplayName: "Mastodon", Image: "/assets/img/auth/mastodon.png",
CustomURLMapping: &oauth2.CustomURLMapping{ CustomURLMapping: &oauth2.CustomURLMapping{
AuthURL: oauth2.GetDefaultAuthURL("mastodon"), AuthURL: oauth2.GetDefaultAuthURL("mastodon"),
}, },

View File

@ -25,7 +25,6 @@ import (
"code.gitea.io/gitea/modules/generate" "code.gitea.io/gitea/modules/generate"
"code.gitea.io/gitea/modules/git" "code.gitea.io/gitea/modules/git"
"code.gitea.io/gitea/modules/log" "code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/storage" "code.gitea.io/gitea/modules/storage"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
@ -772,7 +771,7 @@ func (u *User) IsGhost() bool {
} }
var ( var (
reservedUsernames = append([]string{ reservedUsernames = []string{
".", ".",
"..", "..",
".well-known", ".well-known",
@ -807,7 +806,8 @@ var (
"stars", "stars",
"template", "template",
"user", "user",
}, public.KnownPublicEntries...) "favicon.ico",
}
reservedUserPatterns = []string{"*.keys", "*.gpg"} reservedUserPatterns = []string{"*.keys", "*.gpg"}
) )

View File

@ -32,7 +32,6 @@ var KnownPublicEntries = []string{
"js", "js",
"serviceworker.js", "serviceworker.js",
"vendor", "vendor",
"favicon.ico",
} }
// Custom implements the static handler for serving custom assets. // Custom implements the static handler for serving custom assets.

View File

@ -110,5 +110,5 @@ func newRepoAvatarService() {
RepoAvatar.Storage = getStorage("repo-avatars", storageType, repoAvatarSec) RepoAvatar.Storage = getStorage("repo-avatars", storageType, repoAvatarSec)
RepoAvatar.Fallback = sec.Key("REPOSITORY_AVATAR_FALLBACK").MustString("none") RepoAvatar.Fallback = sec.Key("REPOSITORY_AVATAR_FALLBACK").MustString("none")
RepoAvatar.FallbackImage = sec.Key("REPOSITORY_AVATAR_FALLBACK_IMAGE").MustString("/img/repo_default.png") RepoAvatar.FallbackImage = sec.Key("REPOSITORY_AVATAR_FALLBACK_IMAGE").MustString("/assets/img/repo_default.png")
} }

View File

@ -1139,12 +1139,12 @@ func MakeManifestData(appName string, appURL string, absoluteAssetURL string) []
StartURL: appURL, StartURL: appURL,
Icons: []manifestIcon{ Icons: []manifestIcon{
{ {
Src: absoluteAssetURL + "/img/logo.png", Src: absoluteAssetURL + "/assets/img/logo.png",
Type: "image/png", Type: "image/png",
Sizes: "512x512", Sizes: "512x512",
}, },
{ {
Src: absoluteAssetURL + "/img/logo.svg", Src: absoluteAssetURL + "/assets/img/logo.svg",
Type: "image/svg+xml", Type: "image/svg+xml",
Sizes: "512x512", Sizes: "512x512",
}, },

View File

@ -61,7 +61,7 @@ func NewFuncMap() []template.FuncMap {
return setting.AppSubURL return setting.AppSubURL
}, },
"StaticUrlPrefix": func() string { "StaticUrlPrefix": func() string {
return setting.StaticURLPrefix return setting.StaticURLPrefix + "/assets"
}, },
"AppUrl": func() string { "AppUrl": func() string {
return setting.AppURL return setting.AppURL

View File

@ -152,6 +152,7 @@ func WebRoutes() *web.Route {
&public.Options{ &public.Options{
Directory: path.Join(setting.StaticRootPath, "public"), Directory: path.Join(setting.StaticRootPath, "public"),
SkipLogging: setting.DisableRouterLog, SkipLogging: setting.DisableRouterLog,
Prefix: "/assets",
}, },
)) ))

View File

@ -46,11 +46,14 @@ func GetUserByParams(ctx *context.Context) *models.User {
// Profile render user's profile page // Profile render user's profile page
func Profile(ctx *context.Context) { func Profile(ctx *context.Context) {
uname := ctx.Params(":username") uname := ctx.Params(":username")
// Special handle for FireFox requests favicon.ico. // Special handle for FireFox requests favicon.ico.
if uname == "favicon.ico" { if uname == "favicon.ico" {
ctx.ServeFile(path.Join(setting.StaticRootPath, "public/img/favicon.png")) ctx.ServeFile(path.Join(setting.StaticRootPath, "public/img/favicon.png"))
return return
} else if strings.HasSuffix(uname, ".png") { }
if strings.HasSuffix(uname, ".png") {
ctx.Error(http.StatusNotFound) ctx.Error(http.StatusNotFound)
return return
} }

View File

@ -35,7 +35,7 @@ export default async function initServiceWorker() {
// the spec strictly requires it to be same-origin so it has to be AppSubUrl to work // the spec strictly requires it to be same-origin so it has to be AppSubUrl to work
await Promise.all([ await Promise.all([
checkCacheValidity(), checkCacheValidity(),
navigator.serviceWorker.register(`${AppSubUrl}/serviceworker.js`), navigator.serviceWorker.register(`${AppSubUrl}/assets/serviceworker.js`),
]); ]);
} catch (err) { } catch (err) {
console.error(err); console.error(err);