diff --git a/go.mod b/go.mod index 4b21ac65a..e81fadcd8 100644 --- a/go.mod +++ b/go.mod @@ -1,45 +1,56 @@ module github.com/bakape/meguca -go 1.13 +go 1.24 replace github.com/Sirupsen/logrus => github.com/sirupsen/logrus v1.4.0 require ( github.com/Masterminds/squirrel v1.5.1 github.com/abh/geoip v0.0.0-20160510155516-07cea4480daa - github.com/adl-golang/quicktemplate v1.0.3 // indirect github.com/aquilax/tripcode v1.0.0 github.com/badoux/goscraper v0.0.0-20190827161153-36995ce6b19f github.com/bakape/captchouli/v2 v2.2.2 github.com/bakape/thumbnailer/v2 v2.7.1 github.com/chai2010/webp v1.1.0 github.com/dimfeld/httptreemux v5.0.1+incompatible + github.com/facebookgo/grace v0.0.0-20180706040059-75cf19382434 + github.com/fsnotify/fsnotify v1.4.9 + github.com/go-playground/log v6.3.0+incompatible + github.com/gorilla/websocket v1.4.2 + github.com/lib/pq v1.8.0 + github.com/rakyll/statik v0.1.7 + github.com/ulikunitz/xz v0.5.7 + github.com/valyala/quicktemplate v1.7.0 + go.etcd.io/bbolt v1.3.5 + golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a + gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df +) + +require ( + github.com/bakape/boorufetch v1.1.6 // indirect github.com/facebookgo/clock v0.0.0-20150410010913-600d898af40a // indirect github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c // indirect github.com/facebookgo/freeport v0.0.0-20150612182905-d4adf43b75b9 // indirect - github.com/facebookgo/grace v0.0.0-20180706040059-75cf19382434 github.com/facebookgo/httpdown v0.0.0-20180706035922-5979d39b15c2 // indirect github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 // indirect github.com/facebookgo/stats v0.0.0-20151006221625-1b76add642e4 // indirect github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 // indirect - github.com/fsnotify/fsnotify v1.4.9 github.com/go-playground/ansi v2.1.0+incompatible // indirect github.com/go-playground/errors v3.3.0+incompatible // indirect - github.com/go-playground/log v6.3.0+incompatible - github.com/gorilla/websocket v1.4.2 - github.com/lib/pq v1.8.0 + github.com/julienschmidt/httprouter v1.3.0 // indirect + github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect + github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect github.com/mattn/go-sqlite3 v1.14.9 // indirect github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e // indirect github.com/nwaples/rardecode v1.1.2 // indirect - github.com/rakyll/statik v0.1.7 github.com/stretchr/testify v1.6.1 // indirect - github.com/ulikunitz/xz v0.5.7 - github.com/valyala/quicktemplate v1.7.0 - go.etcd.io/bbolt v1.3.5 - golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a + github.com/valyala/bytebufferpool v1.0.0 // indirect + gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b // indirect + golang.org/x/net v0.0.0-20221002022538-bcab6841153b // indirect + golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10 // indirect + golang.org/x/text v0.3.7 // indirect gopkg.in/alexcesaro/quotedprintable.v3 v3.0.0-20150716171945-2caba252f4dc // indirect gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f // indirect - gopkg.in/gomail.v2 v2.0.0-20160411212932-81ebce5c23df ) replace github.com/bakape/thumbnailer/v2 v2.7.1 => github.com/zkm2/thumbnailer/v2 v2.7.2 diff --git a/go.sum b/go.sum index e86e82581..6bdd432e2 100644 --- a/go.sum +++ b/go.sum @@ -3,8 +3,6 @@ github.com/Masterminds/squirrel v1.5.1 h1:kWAKlLLJFxZG7N2E0mBMNWVp5AuUX+JUrnhFN7 github.com/Masterminds/squirrel v1.5.1/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10= github.com/abh/geoip v0.0.0-20160510155516-07cea4480daa h1:o7+BnQZpdqHPCc9F2fTWPCM9Y9AyUHBWbTL+pCrCdb0= github.com/abh/geoip v0.0.0-20160510155516-07cea4480daa/go.mod h1:N2q9pP3q4thAewFqmOB/DL8EsWimMuDOx4KduwXMT5A= -github.com/adl-golang/quicktemplate v1.0.3 h1:Jk6nisekPAPLn0EWdjj83HW8gA/FvBc9IxA16Vqj1+o= -github.com/adl-golang/quicktemplate v1.0.3/go.mod h1:TAbPIaVNmjvWIJCperDHh4dl0Rbrn65U9K4gyUAUE+c= github.com/andybalholm/brotli v1.0.0/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/andybalholm/brotli v1.0.2/go.mod h1:loMXtMfwqflxFJPmdbJO0a3KNoPuLBgiu3qAvBg8x/Y= github.com/andybalholm/brotli v1.0.3/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= @@ -52,12 +50,10 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE= github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U= github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM= -github.com/klauspost/compress v1.4.0/go.mod h1:RyIbtBH6LamlWaDj8nUwkbUhJ87Yi3uG0guNDohfE1A= github.com/klauspost/compress v1.10.7/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.11.0/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdYsUV+/s2qKfXs= github.com/klauspost/compress v1.13.4/go.mod h1:8dP1Hq4DHOhN9w426knH3Rhby4rFm6D8eO+e+Dq5Gzg= github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= -github.com/klauspost/cpuid v0.0.0-20180405133222-e7e905edc00e/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= @@ -93,7 +89,6 @@ github.com/ulikunitz/xz v0.5.7 h1:YvTNdFzX6+W5m9msiYg/zpkSURPPtOlzbqYjrFn7Yt4= github.com/ulikunitz/xz v0.5.7/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v0.0.0-20180905170723-c6fd90e432cc/go.mod h1:+g/po7GqyG5E+1CNgquiIxJnsXEi5vwFn5weFujbO78= github.com/valyala/fasthttp v1.16.0/go.mod h1:YOKImeEosDdBPnxc0gy7INqi3m1zK6A+xl6TwOBhHCA= github.com/valyala/fasthttp v1.30.0/go.mod h1:2rsYD01CKFrjjsvFxx75KlEUNpWNBY9JWD3K/7o2Cus= github.com/valyala/quicktemplate v1.6.3/go.mod h1:fwPzK2fHuYEODzJ9pkw0ipCPNHZ2tD5KW4lOuSdPKzY= @@ -101,8 +96,8 @@ github.com/valyala/quicktemplate v1.7.0 h1:LUPTJmlVcb46OOUY3IeD9DojFpAVbsG+5WFTc github.com/valyala/quicktemplate v1.7.0/go.mod h1:sqKJnoaOF88V07vkO+9FL8fb9uZg/VPSJnLYn+LmLk8= github.com/valyala/tcplisten v0.0.0-20161114210144-ceec8f93295a/go.mod h1:v3UYOV9WzVtRmSR+PDvWpU/qWl4Wa5LApYYX4ZtKbio= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= -github.com/zkm2/thumbnailer/v2 v2.7.1 h1:1rmbjNU2cIoTFl4i/mywVgnHOLrLqY1JIBVb9qnTVd4= -github.com/zkm2/thumbnailer/v2 v2.7.1/go.mod h1:+yOYrfZmQ3VO7uqVHxTr3p5J74WRjP5MeQQXaU6GBjY= +github.com/zkm2/thumbnailer/v2 v2.7.2 h1:wrK2r648jSrvbGdDMfSJ9hviCjG51yAiAV6lwoJERtg= +github.com/zkm2/thumbnailer/v2 v2.7.2/go.mod h1:+yOYrfZmQ3VO7uqVHxTr3p5J74WRjP5MeQQXaU6GBjY= gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b h1:7gd+rd8P3bqcn/96gOZa3F5dpJr/vEiDQYlNb/y2uNs= gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b/go.mod h1:T3BPAOm2cqquPa0MKWeNkmOM5RQsRhkrwMWonFMN7fE= go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0= diff --git a/server/assets.go b/server/assets.go index a7c10a375..f3a531236 100644 --- a/server/assets.go +++ b/server/assets.go @@ -8,6 +8,7 @@ import ( "os" "path/filepath" "strconv" + "testing" "time" "github.com/bakape/meguca/assets" @@ -25,13 +26,36 @@ var ( } // For overriding during tests - imageWebRoot = "images" + imageRoot *os.Root + wwwRoot *os.Root ) type fileError struct { name, msg string } +func init() { + exe, err := os.Executable() + if err != nil { + panic(err) + } + exeDir := filepath.Dir(exe) + + if testing.Testing() == true { + return + } + + imageRoot, err = os.OpenRoot(filepath.Join(exeDir, "images")) + if err != nil { + panic(err) + } + + wwwRoot, err = os.OpenRoot(filepath.Join(exeDir, "www")) + if err != nil { + panic(err) + } +} + func (e fileError) Error() string { return fmt.Sprintf("invalid file %s: %s", e.name, e.msg) } @@ -47,7 +71,7 @@ func newFileError(h *multipart.FileHeader, msg string) error { // (except deletion), so we can also set separate caching policies for them. func serveImages(w http.ResponseWriter, r *http.Request) { path := extractParam(r, "path") - file, err := os.Open(cleanJoin(imageWebRoot, path)) + file, err := imageRoot.Open(path) if err != nil { text404(w) return @@ -62,18 +86,11 @@ func serveImages(w http.ResponseWriter, r *http.Request) { http.ServeContent(w, r, path, time.Time{}, file) } -func cleanJoin(a, b string) string { - return filepath.Clean(filepath.Join(a, b)) -} - -// Server static assets +// Serve static assets func serveAssets(w http.ResponseWriter, r *http.Request) { w.Header().Set("Service-Worker-Allowed", "/") - serveFile(w, r, cleanJoin(webRoot, extractParam(r, "path"))) -} - -func serveFile(w http.ResponseWriter, r *http.Request, path string) { - file, err := os.Open(path) + path := extractParam(r, "path") + file, err := wwwRoot.Open(path) if err != nil { text404(w) return @@ -95,6 +112,7 @@ func serveFile(w http.ResponseWriter, r *http.Request, path string) { head := w.Header() head.Set("Cache-Control", "no-cache") head.Set("ETag", etag) + http.ServeContent(w, r, path, modTime, file) } diff --git a/server/router.go b/server/router.go index 6c66db33f..7e084b392 100644 --- a/server/router.go +++ b/server/router.go @@ -26,9 +26,6 @@ var ( healthCheckMsg = []byte("God's in His heaven, all's right with the world") ) -// Used for overriding during tests -var webRoot = "www" - func startWebServer() (err error) { go func() { // Bind pprof to random localhost-only address diff --git a/server/router_test.go b/server/router_test.go index 2a8815c27..b570ff5cf 100644 --- a/server/router_test.go +++ b/server/router_test.go @@ -33,8 +33,11 @@ func TestMain(m *testing.M) { log.AddHandler(con, log.AllLevels...) router = createRouter() - webRoot = "testdata" - imageWebRoot = "testdata" + imageRoot, err = os.OpenRoot("testdata") + if err != nil { + panic(err) + } + wwwRoot = imageRoot config.Set(config.Configs{ Public: config.Public{