diff options
author | 2023-01-02 13:10:50 +0100 | |
---|---|---|
committer | 2023-01-02 12:10:50 +0000 | |
commit | 941893a774c83802afdc4cc76e1d30c59b6c5585 (patch) | |
tree | 6e7296146dedfeac8e83655157270f41e190724b /internal/web/assets.go | |
parent | [chore]: Bump github.com/abema/go-mp4 from 0.8.0 to 0.9.0 (#1287) (diff) | |
download | gotosocial-941893a774c83802afdc4cc76e1d30c59b6c5585.tar.xz |
[chore] The Big Middleware and API Refactor (tm) (#1250)
* interim commit: start refactoring middlewares into package under router
* another interim commit, this is becoming a big job
* another fucking massive interim commit
* refactor bookmarks to new style
* ambassador, wiz zeze commits you are spoiling uz
* she compiles, we're getting there
* we're just normal men; we're just innocent men
* apiutil
* whoopsie
* i'm glad noone reads commit msgs haha :blob_sweat:
* use that weirdo go-bytesize library for maxMultipartMemory
* fix media module paths
Diffstat (limited to 'internal/web/assets.go')
-rw-r--r-- | internal/web/assets.go | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/internal/web/assets.go b/internal/web/assets.go index aab4346eb..470bab752 100644 --- a/internal/web/assets.go +++ b/internal/web/assets.go @@ -22,11 +22,9 @@ import ( "fmt" "net/http" "path" - "path/filepath" "strings" "github.com/gin-gonic/gin" - "github.com/superseriousbusiness/gotosocial/internal/config" "github.com/superseriousbusiness/gotosocial/internal/log" ) @@ -53,22 +51,6 @@ func (fs fileSystem) Open(path string) (http.File, error) { return f, nil } -func (m *Module) mountAssetsFilesystem(group *gin.RouterGroup) { - webAssetsAbsFilePath, err := filepath.Abs(config.GetWebAssetBaseDir()) - if err != nil { - log.Panicf("mountAssetsFilesystem: error getting absolute path of assets dir: %s", err) - } - - fs := fileSystem{http.Dir(webAssetsAbsFilePath)} - - // use the cache middleware on all handlers in this group - group.Use(m.assetsCacheControlMiddleware(fs)) - - // serve static file system in the root of this group, - // will end up being something like "/assets/" - group.StaticFS("/", fs) -} - // getAssetFileInfo tries to fetch the ETag for the given filePath from the module's // assetsETagCache. If it can't be found there, it uses the provided http.FileSystem // to generate a new ETag to go in the cache, which it then returns. @@ -115,6 +97,9 @@ func (m *Module) getAssetETag(filePath string, fs http.FileSystem) (string, erro // // See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-None-Match // and: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control +// +// todo: move this middleware out of the 'web' package and into the 'middleware' +// package along with the other middlewares func (m *Module) assetsCacheControlMiddleware(fs http.FileSystem) gin.HandlerFunc { return func(c *gin.Context) { // set this Cache-Control header to instruct clients to validate the response with us |