2021-05-09 22:07:23 +07:00
|
|
|
package app
|
|
|
|
|
|
|
|
import (
|
2025-02-23 18:50:12 +00:00
|
|
|
"io/fs"
|
2021-05-09 22:07:23 +07:00
|
|
|
"net/http"
|
2021-05-11 19:21:11 +07:00
|
|
|
"os"
|
2021-05-09 22:07:23 +07:00
|
|
|
|
|
|
|
"github.com/Damillora/Shioriko/pkg/config"
|
|
|
|
"github.com/Damillora/Shioriko/pkg/database"
|
2025-02-23 18:50:12 +00:00
|
|
|
"github.com/Damillora/Shioriko/pkg/web"
|
2021-05-09 22:07:23 +07:00
|
|
|
"github.com/gin-contrib/cors"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Initialize() {
|
|
|
|
config.InitializeConfig()
|
2021-05-11 19:21:11 +07:00
|
|
|
|
|
|
|
previewDir := config.CurrentConfig.DataDirectory + "/preview"
|
|
|
|
thumbnailDir := config.CurrentConfig.DataDirectory + "/thumbnail"
|
|
|
|
|
|
|
|
if _, err := os.Stat(previewDir); os.IsNotExist(err) {
|
|
|
|
os.Mkdir(previewDir, 0755)
|
|
|
|
}
|
|
|
|
if _, err := os.Stat(thumbnailDir); os.IsNotExist(err) {
|
|
|
|
os.Mkdir(thumbnailDir, 0755)
|
|
|
|
}
|
|
|
|
|
2021-05-09 22:07:23 +07:00
|
|
|
database.Initialize()
|
|
|
|
}
|
|
|
|
|
|
|
|
func Start() {
|
|
|
|
g := gin.Default()
|
|
|
|
|
2025-02-23 18:50:12 +00:00
|
|
|
webFS := web.WebAssets()
|
|
|
|
webAssets, _ := fs.Sub(webFS, "_app")
|
|
|
|
|
|
|
|
g.StaticFileFS("/", "./app.html", http.FS(webFS))
|
|
|
|
// g.StaticFile("/", "./pkg/web/build/index.html")
|
|
|
|
g.StaticFS("/_app", http.FS(webAssets))
|
2021-05-09 22:07:23 +07:00
|
|
|
g.Static("/data", config.CurrentConfig.DataDirectory)
|
2025-02-23 18:50:12 +00:00
|
|
|
|
2021-05-09 22:07:23 +07:00
|
|
|
g.Use(cors.Default())
|
|
|
|
|
|
|
|
InitializeRoutes(g)
|
|
|
|
|
|
|
|
g.Run()
|
|
|
|
}
|