1
0
mirror of https://gitcode.com/gitea/gitea.git synced 2025-06-30 01:04:19 +08:00

Move public asset files to the proper directory ()

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

Some old PRs (like ) 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:
* 
*  
* 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
417 changed files with 125 additions and 123 deletions
.dockerignore.gitattributes.gitignoreMakefileREADME.mdREADME_ZH.md
build
custom/conf
docs/content/doc
modules
public/assets/img
404.png500.pngapple-touch-icon.pngavatar_default.pngcheckmark.pngdingtalk.icodiscord.png
emoji
failed.pngfavicon.pngfavicon.svgfeishu.pnggitea.svggogs.icoloading.pnglogo.pnglogo.svgmsteams.pngopenid-16x16.pngpackagist.pngrepo_default.pngslack.png
svg
fontawesome-openid.svgfontawesome-save.svgfontawesome-send.svgfontawesome-windows.svggitea-alpine.svggitea-azuread.svggitea-azureadv2.svggitea-bitbucket.svggitea-cargo.svggitea-chef.svggitea-codebase.svggitea-composer.svggitea-conan.svggitea-conda.svggitea-cran.svggitea-debian.svggitea-discord.svggitea-double-chevron-left.svggitea-double-chevron-right.svggitea-dropbox.svggitea-empty-checkbox.svggitea-exclamation.svggitea-facebook.svggitea-git.svggitea-gitbucket.svggitea-gitea.svggitea-gitlab.svggitea-go.svggitea-gogs.svggitea-google.svggitea-helm.svggitea-join.svggitea-lock-cog.svggitea-lock.svggitea-mastodon.svggitea-matrix.svggitea-maven.svggitea-microsoftonline.svggitea-nextcloud.svggitea-npm.svggitea-nuget.svggitea-onedev.svggitea-openid.svggitea-pub.svggitea-python.svggitea-rpm.svggitea-rubygems.svggitea-split.svggitea-swift.svggitea-twitter.svggitea-unlock.svggitea-vagrant.svggitea-vscode.svggitea-whitespace.svggitea-yandex.svgmaterial-invert-colors.svgmaterial-palette.svgocticon-accessibility-inset.svgocticon-accessibility.svgocticon-alert-fill.svgocticon-alert.svgocticon-apps.svgocticon-archive.svgocticon-arrow-both.svgocticon-arrow-down-left.svgocticon-arrow-down-right.svgocticon-arrow-down.svgocticon-arrow-left.svgocticon-arrow-right.svgocticon-arrow-switch.svgocticon-arrow-up-left.svgocticon-arrow-up-right.svgocticon-arrow-up.svgocticon-beaker.svgocticon-bell-fill.svgocticon-bell-slash.svgocticon-bell.svgocticon-blocked.svgocticon-bold.svgocticon-book.svgocticon-bookmark-slash.svgocticon-bookmark.svgocticon-briefcase.svgocticon-broadcast.svgocticon-browser.svgocticon-bug.svgocticon-cache.svgocticon-calendar.svgocticon-check-circle-fill.svgocticon-check-circle.svgocticon-check.svgocticon-checkbox.svgocticon-checklist.svgocticon-chevron-down.svgocticon-chevron-left.svgocticon-chevron-right.svgocticon-chevron-up.svgocticon-circle-slash.svgocticon-circle.svgocticon-clock-fill.svgocticon-clock.svgocticon-cloud-offline.svgocticon-cloud.svgocticon-code-of-conduct.svgocticon-code-review.svgocticon-code-square.svgocticon-code.svgocticon-codescan-checkmark.svgocticon-codescan.svgocticon-codespaces.svgocticon-columns.svgocticon-command-palette.svgocticon-comment-discussion.svgocticon-comment.svgocticon-container.svgocticon-copilot-error.svgocticon-copilot-warning.svgocticon-copilot.svgocticon-copy.svgocticon-cpu.svgocticon-credit-card.svgocticon-cross-reference.svgocticon-dash.svgocticon-database.svgocticon-dependabot.svgocticon-desktop-download.svgocticon-device-camera-video.svgocticon-device-camera.svgocticon-device-desktop.svgocticon-device-mobile.svgocticon-devices.svgocticon-diamond.svgocticon-diff-added.svgocticon-diff-ignored.svgocticon-diff-modified.svgocticon-diff-removed.svgocticon-diff-renamed.svgocticon-diff.svgocticon-discussion-closed.svgocticon-discussion-duplicate.svgocticon-discussion-outdated.svgocticon-dot-fill.svgocticon-dot.svgocticon-download.svgocticon-duplicate.svgocticon-ellipsis.svgocticon-eye-closed.svgocticon-eye.svgocticon-feed-discussion.svgocticon-feed-forked.svgocticon-feed-heart.svgocticon-feed-merged.svgocticon-feed-person.svgocticon-feed-repo.svgocticon-feed-rocket.svgocticon-feed-star.svgocticon-feed-tag.svgocticon-feed-trophy.svgocticon-file-added.svgocticon-file-badge.svgocticon-file-binary.svgocticon-file-code.svgocticon-file-diff.svgocticon-file-directory-fill.svgocticon-file-directory-open-fill.svgocticon-file-directory-symlink.svgocticon-file-directory.svgocticon-file-moved.svgocticon-file-removed.svgocticon-file-submodule.svgocticon-file-symlink-file.svgocticon-file-zip.svgocticon-file.svgocticon-filter.svgocticon-fiscal-host.svgocticon-flame.svgocticon-fold-down.svgocticon-fold-up.svgocticon-fold.svgocticon-gear.svgocticon-gift.svgocticon-git-branch.svgocticon-git-commit.svgocticon-git-compare.svgocticon-git-merge-queue.svgocticon-git-merge.svgocticon-git-pull-request-closed.svgocticon-git-pull-request-draft.svgocticon-git-pull-request.svgocticon-globe.svgocticon-goal.svgocticon-grabber.svgocticon-graph.svgocticon-hash.svgocticon-heading.svgocticon-heart-fill.svgocticon-heart.svgocticon-history.svgocticon-home.svgocticon-horizontal-rule.svgocticon-hourglass.svgocticon-hubot.svgocticon-id-badge.svgocticon-image.svgocticon-inbox.svgocticon-infinity.svgocticon-info.svgocticon-issue-closed.svgocticon-issue-draft.svgocticon-issue-opened.svgocticon-issue-reopened.svgocticon-issue-tracked-by.svgocticon-issue-tracks.svgocticon-italic.svgocticon-iterations.svgocticon-kebab-horizontal.svgocticon-key-asterisk.svgocticon-key.svgocticon-law.svgocticon-light-bulb.svgocticon-link-external.svgocticon-link.svgocticon-list-ordered.svgocticon-list-unordered.svgocticon-location.svgocticon-lock.svgocticon-log.svgocticon-logo-gist.svgocticon-logo-github.svgocticon-mail.svgocticon-mark-github.svgocticon-markdown.svgocticon-megaphone.svgocticon-mention.svgocticon-meter.svgocticon-milestone.svgocticon-mirror.svgocticon-moon.svgocticon-mortar-board.svgocticon-move-to-bottom.svgocticon-move-to-end.svgocticon-move-to-start.svgocticon-move-to-top.svgocticon-multi-select.svgocticon-mute.svgocticon-no-entry.svgocticon-north-star.svgocticon-note.svgocticon-number.svgocticon-organization.svgocticon-package-dependencies.svgocticon-package-dependents.svgocticon-package.svgocticon-paintbrush.svgocticon-paper-airplane.svgocticon-paperclip.svgocticon-passkey-fill.svgocticon-paste.svgocticon-pencil.svgocticon-people.svgocticon-person-add.svgocticon-person-fill.svgocticon-person.svgocticon-pin-slash.svgocticon-pin.svgocticon-pivot-column.svgocticon-play.svgocticon-plug.svgocticon-plus-circle.svgocticon-plus.svgocticon-project-roadmap.svgocticon-project-symlink.svgocticon-project-template.svgocticon-project.svgocticon-pulse.svgocticon-question.svgocticon-quote.svgocticon-read.svgocticon-redo.svgocticon-rel-file-path.svgocticon-reply.svgocticon-repo-clone.svgocticon-repo-deleted.svgocticon-repo-forked.svgocticon-repo-locked.svgocticon-repo-pull.svgocticon-repo-push.svgocticon-repo-template.svgocticon-repo.svgocticon-report.svgocticon-rocket.svgocticon-rows.svgocticon-rss.svgocticon-ruby.svgocticon-screen-full.svgocticon-screen-normal.svgocticon-search.svgocticon-server.svgocticon-share-android.svgocticon-share.svgocticon-shield-check.svgocticon-shield-lock.svgocticon-shield-slash.svgocticon-shield-x.svgocticon-shield.svgocticon-sidebar-collapse.svgocticon-sidebar-expand.svgocticon-sign-in.svgocticon-sign-out.svgocticon-single-select.svgocticon-skip-fill.svgocticon-skip.svgocticon-sliders.svgocticon-smiley.svgocticon-sort-asc.svgocticon-sort-desc.svgocticon-sparkle-fill.svgocticon-sponsor-tiers.svgocticon-square-fill.svgocticon-square.svgocticon-squirrel.svgocticon-stack.svgocticon-star-fill.svgocticon-star.svgocticon-stop.svgocticon-stopwatch.svgocticon-strikethrough.svgocticon-sun.svgocticon-sync.svgocticon-tab-external.svgocticon-table.svgocticon-tag.svgocticon-tasklist.svgocticon-telescope-fill.svgocticon-telescope.svgocticon-terminal.svgocticon-three-bars.svgocticon-thumbsdown.svgocticon-thumbsup.svgocticon-tools.svgocticon-tracked-by-closed-completed.svgocticon-tracked-by-closed-not-planned.svgocticon-trash.svgocticon-triangle-down.svgocticon-triangle-left.svgocticon-triangle-right.svgocticon-triangle-up.svgocticon-trophy.svgocticon-typography.svgocticon-undo.svgocticon-unfold.svgocticon-unlink.svgocticon-unlock.svgocticon-unmute.svgocticon-unread.svgocticon-unverified.svgocticon-upload.svgocticon-verified.svgocticon-versions.svgocticon-video.svgocticon-webhook.svgocticon-workflow.svgocticon-x-circle-fill.svgocticon-x-circle.svgocticon-x.svgocticon-zap.svgocticon-zoom-in.svgocticon-zoom-out.svg
telegram.pngwechatwork.png
snap
web_src/js
webpack.config.js

@ -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

@ -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 {