mirror of
https://github.com/0rangebananaspy/authelia.git
synced 2024-09-14 22:47:21 +07:00
aac4c4772c
This allows overriding translation files in folders with lowercase RFC5646 / BCP47 Format language codes. This also fixes an issues where languages which don't expressly match the language code specified due to having a variant will also match the existing codes. Co-authored-by: Amir Zarrinkafsh <nightah@me.com>
29 lines
566 B
Go
29 lines
566 B
Go
package middlewares
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/valyala/fasthttp"
|
|
)
|
|
|
|
// AssetOverrideMiddleware allows overriding and serving of specific embedded assets from disk.
|
|
func AssetOverrideMiddleware(root string, strip int, next fasthttp.RequestHandler) fasthttp.RequestHandler {
|
|
return func(ctx *fasthttp.RequestCtx) {
|
|
if root == "" {
|
|
next(ctx)
|
|
|
|
return
|
|
}
|
|
|
|
_, err := os.Stat(filepath.Join(root, string(fasthttp.NewPathSlashesStripper(strip)(ctx))))
|
|
if err != nil {
|
|
next(ctx)
|
|
|
|
return
|
|
}
|
|
|
|
fasthttp.FSHandler(root, strip)(ctx)
|
|
}
|
|
}
|