2022-08-11 21:32:33 +08:00
|
|
|
package middlewares
|
|
|
|
|
|
|
|
import (
|
2022-12-12 20:17:58 +08:00
|
|
|
"strings"
|
|
|
|
|
2025-07-01 09:54:50 +08:00
|
|
|
"github.com/OpenListTeam/OpenList/v4/internal/conf"
|
|
|
|
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
|
|
|
"github.com/OpenListTeam/OpenList/v4/server/common"
|
2022-08-11 21:32:33 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func StoragesLoaded(c *gin.Context) {
|
2025-06-30 15:48:05 +08:00
|
|
|
if !conf.StoragesLoaded {
|
2022-12-12 20:17:58 +08:00
|
|
|
if utils.SliceContains([]string{"", "/", "/favicon.ico"}, c.Request.URL.Path) {
|
|
|
|
c.Next()
|
|
|
|
return
|
|
|
|
}
|
2022-12-19 13:34:06 +08:00
|
|
|
paths := []string{"/assets", "/images", "/streamer", "/static"}
|
2022-12-12 20:17:58 +08:00
|
|
|
for _, path := range paths {
|
|
|
|
if strings.HasPrefix(c.Request.URL.Path, path) {
|
|
|
|
c.Next()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2022-08-11 21:32:33 +08:00
|
|
|
common.ErrorStrResp(c, "Loading storage, please wait", 500)
|
|
|
|
c.Abort()
|
2025-06-30 15:48:05 +08:00
|
|
|
return
|
2022-08-11 21:32:33 +08:00
|
|
|
}
|
2025-06-30 15:48:05 +08:00
|
|
|
c.Set(conf.ApiUrlKey, common.GetApiUrlFormRequest(c.Request))
|
|
|
|
c.Next()
|
2022-08-11 21:32:33 +08:00
|
|
|
}
|