Move public asset files to the proper directory (#25907)

Move `public/*` to `public/assets/*`

Some old PRs (like #15219) introduced inconsistent directory system.

For example: why the local directory "public" is accessed by
`http://site/assets`? How to serve the ".well-known" files properly in
the public directory?

For convention rules, the "public" directory is widely used for the
website's root directory. It shouldn't be an exception for Gitea.

So, this PR makes the things consistent:

* `http://site/assets/foo` means `{CustomPath}/public/assets/foo`.
* `{CustomPath}/public/.well-known` and `{CustomPath}/public/robots.txt`
can be used in the future.

This PR is also a prerequisite for a clear solution for:
* #21942
* #25892 
* discourse.gitea.io: [.well-known path serving custom files behind
proxy?](https://discourse.gitea.io/t/well-known-path-serving-custom-files-behind-proxy/5445/1)

This PR is breaking for users who have custom "public" files (CSS/JS).
After getting approvals, I will update the documents.

----

## ⚠️ BREAKING ⚠️

If you have files in your "custom/public/" folder, please move them to
"custom/public/assets/".

---------

Co-authored-by: 6543 <6543@obermui.de>
Co-authored-by: Giteabot <teabot@gitea.io>
This commit is contained in:
wxiaoguang 2023-07-19 00:06:43 +08:00 committed by GitHub
parent 8af96f585f
commit faa28b5a44
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
417 changed files with 125 additions and 123 deletions

View file

@ -73,7 +73,7 @@ func setWellKnownContentType(w http.ResponseWriter, file string) {
func handleRequest(w http.ResponseWriter, req *http.Request, fs http.FileSystem, file string) bool {
// 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
f, err := fs.Open(util.PathJoinRelX(file))
f, err := fs.Open(util.PathJoinRelX("assets", file))
if err != nil {
if os.IsNotExist(err) {
return false

View file

@ -27,7 +27,7 @@ const defaultSize = 16
// Init discovers SVGs and populates the `SVGs` variable
func Init() error {
files, err := public.AssetFS().ListFiles("img/svg")
files, err := public.AssetFS().ListFiles("assets/img/svg")
if err != nil {
return err
}
@ -38,7 +38,7 @@ func Init() error {
if path.Ext(file) != ".svg" {
continue
}
bs, err := public.AssetFS().ReadFile("img/svg", file)
bs, err := public.AssetFS().ReadFile("assets/img/svg", file)
if err != nil {
log.Error("Failed to read SVG file %s: %v", file, err)
} else {