2021-11-13 07:53:26 +00:00
|
|
|
package server
|
|
|
|
|
|
|
|
import (
|
2021-11-14 06:37:26 +00:00
|
|
|
"github.com/Xhofe/alist/conf"
|
2021-11-13 07:53:26 +00:00
|
|
|
"github.com/Xhofe/alist/public"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
log "github.com/sirupsen/logrus"
|
|
|
|
"io/fs"
|
|
|
|
"io/ioutil"
|
|
|
|
"net/http"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
func init() {
|
2021-11-15 11:06:10 +00:00
|
|
|
index, err := public.Public.Open("index.html")
|
|
|
|
if err != nil {
|
|
|
|
log.Errorf(err.Error())
|
|
|
|
return
|
|
|
|
}
|
2021-11-14 06:37:26 +00:00
|
|
|
data, _ := ioutil.ReadAll(index)
|
|
|
|
conf.RawIndexHtml = string(data)
|
2021-11-13 07:53:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func Static(r *gin.Engine) {
|
|
|
|
assets, err := fs.Sub(public.Public, "assets")
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalf("can't find assets folder")
|
|
|
|
}
|
|
|
|
r.StaticFS("/assets/", http.FS(assets))
|
|
|
|
r.NoRoute(func(c *gin.Context) {
|
|
|
|
c.Status(200)
|
|
|
|
c.Header("Content-Type", "text/html")
|
2021-11-14 06:37:26 +00:00
|
|
|
_, _ = c.Writer.WriteString(conf.IndexHtml)
|
2021-11-13 07:53:26 +00:00
|
|
|
c.Writer.Flush()
|
|
|
|
})
|
|
|
|
}
|