mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-09-18 01:25:54 +00:00
add entry file
This commit is contained in:
parent
79db93ec02
commit
7b3120a5e9
2
main.go
2
main.go
@ -80,7 +80,7 @@ func init() {
|
||||
service.GetCPUThermalZone()
|
||||
|
||||
route.InitFunction()
|
||||
|
||||
service.MyService.System().GenreateSystemEntry()
|
||||
///
|
||||
// service.MountLists = make(map[string]*mountlib.MountPoint)
|
||||
// configfile.Install()
|
||||
|
130
route/v1.go
130
route/v1.go
@ -73,6 +73,7 @@ func InitV1Router() *gin.Engine {
|
||||
// v1SysGroup.PUT("/port", v1.PutCasaOSPort)
|
||||
v1SysGroup.GET("/proxy", v1.GetSystemProxy)
|
||||
v1SysGroup.PUT("/state/:state", v1.PutSystemState)
|
||||
v1SysGroup.GET("/entry", v1.GetSystemEntry)
|
||||
}
|
||||
v1PortGroup := v1Group.Group("/port")
|
||||
v1PortGroup.Use()
|
||||
@ -80,79 +81,78 @@ func InitV1Router() *gin.Engine {
|
||||
v1PortGroup.GET("/", v1.GetPort) // app/port
|
||||
v1PortGroup.GET("/state/:port", v1.PortCheck) // app/check/:port
|
||||
}
|
||||
// v1FileGroup := v1Group.Group("/file")
|
||||
// v1FileGroup.Use()
|
||||
// {
|
||||
// v1FileGroup.GET("", v1.GetDownloadSingleFile) // download/:path
|
||||
// v1FileGroup.POST("", v1.PostCreateFile)
|
||||
// v1FileGroup.PUT("", v1.PutFileContent)
|
||||
// v1FileGroup.PUT("/name", v1.RenamePath)
|
||||
// // file/rename
|
||||
// v1FileGroup.GET("/content", v1.GetFilerContent) // file/read
|
||||
|
||||
v1FileGroup := v1Group.Group("/file")
|
||||
v1FileGroup.Use()
|
||||
{
|
||||
v1FileGroup.GET("", v1.GetDownloadSingleFile) // download/:path
|
||||
v1FileGroup.POST("", v1.PostCreateFile)
|
||||
v1FileGroup.PUT("", v1.PutFileContent)
|
||||
v1FileGroup.PUT("/name", v1.RenamePath)
|
||||
// file/rename
|
||||
v1FileGroup.GET("/content", v1.GetFilerContent) // file/read
|
||||
// // File uploads need to be handled separately, and will not be modified here
|
||||
// //v1FileGroup.POST("/upload", v1.PostFileUpload)
|
||||
// v1FileGroup.POST("/upload", v1.PostFileUpload)
|
||||
// v1FileGroup.GET("/upload", v1.GetFileUpload)
|
||||
// // v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
|
||||
// v1FileGroup.GET("/ws", v1.ConnectWebSocket)
|
||||
// v1FileGroup.GET("/peers", v1.GetPeers)
|
||||
// }
|
||||
// v1CloudGroup := v1Group.Group("/cloud")
|
||||
// v1CloudGroup.Use()
|
||||
// {
|
||||
// v1CloudGroup.GET("", v1.ListStorages)
|
||||
// v1CloudGroup.DELETE("", v1.UmountStorage)
|
||||
// }
|
||||
// v1DriverGroup := v1Group.Group("/driver")
|
||||
// v1DriverGroup.Use()
|
||||
// {
|
||||
// v1DriverGroup.GET("", v1.ListDriverInfo)
|
||||
// }
|
||||
|
||||
// File uploads need to be handled separately, and will not be modified here
|
||||
//v1FileGroup.POST("/upload", v1.PostFileUpload)
|
||||
v1FileGroup.POST("/upload", v1.PostFileUpload)
|
||||
v1FileGroup.GET("/upload", v1.GetFileUpload)
|
||||
// v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
|
||||
v1FileGroup.GET("/ws", v1.ConnectWebSocket)
|
||||
v1FileGroup.GET("/peers", v1.GetPeers)
|
||||
}
|
||||
v1CloudGroup := v1Group.Group("/cloud")
|
||||
v1CloudGroup.Use()
|
||||
{
|
||||
v1CloudGroup.GET("", v1.ListStorages)
|
||||
v1CloudGroup.DELETE("", v1.UmountStorage)
|
||||
}
|
||||
v1DriverGroup := v1Group.Group("/driver")
|
||||
v1DriverGroup.Use()
|
||||
{
|
||||
v1DriverGroup.GET("", v1.ListDriverInfo)
|
||||
}
|
||||
// v1FolderGroup := v1Group.Group("/folder")
|
||||
// v1FolderGroup.Use()
|
||||
// {
|
||||
// v1FolderGroup.PUT("/name", v1.RenamePath)
|
||||
// v1FolderGroup.GET("", v1.DirPath) ///file/dirpath
|
||||
// v1FolderGroup.POST("", v1.MkdirAll) ///file/mkdir
|
||||
// v1FolderGroup.GET("/size", v1.GetSize)
|
||||
// v1FolderGroup.GET("/count", v1.GetFileCount)
|
||||
// }
|
||||
// v1BatchGroup := v1Group.Group("/batch")
|
||||
// v1BatchGroup.Use()
|
||||
// {
|
||||
|
||||
v1FolderGroup := v1Group.Group("/folder")
|
||||
v1FolderGroup.Use()
|
||||
{
|
||||
v1FolderGroup.PUT("/name", v1.RenamePath)
|
||||
v1FolderGroup.GET("", v1.DirPath) ///file/dirpath
|
||||
v1FolderGroup.POST("", v1.MkdirAll) ///file/mkdir
|
||||
v1FolderGroup.GET("/size", v1.GetSize)
|
||||
v1FolderGroup.GET("/count", v1.GetFileCount)
|
||||
}
|
||||
v1BatchGroup := v1Group.Group("/batch")
|
||||
v1BatchGroup.Use()
|
||||
{
|
||||
|
||||
v1BatchGroup.DELETE("", v1.DeleteFile) // file/delete
|
||||
v1BatchGroup.DELETE("/:id/task", v1.DeleteOperateFileOrDir)
|
||||
v1BatchGroup.POST("/task", v1.PostOperateFileOrDir) // file/operate
|
||||
v1BatchGroup.GET("", v1.GetDownloadFile)
|
||||
}
|
||||
// v1BatchGroup.DELETE("", v1.DeleteFile) // file/delete
|
||||
// v1BatchGroup.DELETE("/:id/task", v1.DeleteOperateFileOrDir)
|
||||
// v1BatchGroup.POST("/task", v1.PostOperateFileOrDir) // file/operate
|
||||
// v1BatchGroup.GET("", v1.GetDownloadFile)
|
||||
// }
|
||||
v1ImageGroup := v1Group.Group("/image")
|
||||
v1ImageGroup.Use()
|
||||
{
|
||||
v1ImageGroup.GET("", v1.GetFileImage)
|
||||
}
|
||||
v1SambaGroup := v1Group.Group("/samba")
|
||||
v1SambaGroup.Use()
|
||||
{
|
||||
v1ConnectionsGroup := v1SambaGroup.Group("/connections")
|
||||
v1ConnectionsGroup.Use()
|
||||
{
|
||||
v1ConnectionsGroup.GET("", v1.GetSambaConnectionsList)
|
||||
v1ConnectionsGroup.POST("", v1.PostSambaConnectionsCreate)
|
||||
v1ConnectionsGroup.DELETE("/:id", v1.DeleteSambaConnections)
|
||||
}
|
||||
v1SharesGroup := v1SambaGroup.Group("/shares")
|
||||
v1SharesGroup.Use()
|
||||
{
|
||||
v1SharesGroup.GET("", v1.GetSambaSharesList)
|
||||
v1SharesGroup.POST("", v1.PostSambaSharesCreate)
|
||||
v1SharesGroup.DELETE("/:id", v1.DeleteSambaShares)
|
||||
v1SharesGroup.GET("/status", v1.GetSambaStatus)
|
||||
}
|
||||
}
|
||||
// v1SambaGroup := v1Group.Group("/samba")
|
||||
// v1SambaGroup.Use()
|
||||
// {
|
||||
// v1ConnectionsGroup := v1SambaGroup.Group("/connections")
|
||||
// v1ConnectionsGroup.Use()
|
||||
// {
|
||||
// v1ConnectionsGroup.GET("", v1.GetSambaConnectionsList)
|
||||
// v1ConnectionsGroup.POST("", v1.PostSambaConnectionsCreate)
|
||||
// v1ConnectionsGroup.DELETE("/:id", v1.DeleteSambaConnections)
|
||||
// }
|
||||
// v1SharesGroup := v1SambaGroup.Group("/shares")
|
||||
// v1SharesGroup.Use()
|
||||
// {
|
||||
// v1SharesGroup.GET("", v1.GetSambaSharesList)
|
||||
// v1SharesGroup.POST("", v1.PostSambaSharesCreate)
|
||||
// v1SharesGroup.DELETE("/:id", v1.DeleteSambaShares)
|
||||
// v1SharesGroup.GET("/status", v1.GetSambaStatus)
|
||||
// }
|
||||
// }
|
||||
v1NotifyGroup := v1Group.Group("/notify")
|
||||
v1NotifyGroup.Use()
|
||||
{
|
||||
|
@ -24,6 +24,7 @@ import (
|
||||
model2 "github.com/IceWhaleTech/CasaOS/service/model"
|
||||
"github.com/IceWhaleTech/CasaOS/types"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/tidwall/gjson"
|
||||
)
|
||||
|
||||
// @Summary check version
|
||||
@ -371,3 +372,12 @@ func PortCheck(c *gin.Context) {
|
||||
t := c.DefaultQuery("type", "tcp")
|
||||
c.JSON(common_err.SUCCESS, &model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: port.IsPortAvailable(p, t)})
|
||||
}
|
||||
|
||||
func GetSystemEntry(c *gin.Context) {
|
||||
entry := service.MyService.System().GetSystemEntry()
|
||||
if !gjson.Valid(entry) {
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: ""})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: entry})
|
||||
}
|
||||
|
@ -57,9 +57,53 @@ type SystemService interface {
|
||||
GetMacAddress() (string, error)
|
||||
SystemReboot() error
|
||||
SystemShutdown() error
|
||||
GetSystemEntry() string
|
||||
GenreateSystemEntry()
|
||||
}
|
||||
type systemService struct{}
|
||||
|
||||
func (c *systemService) GenreateSystemEntry() {
|
||||
modelsPath := "/var/lib/casaos/www/modules"
|
||||
entryFileName := "entry.json"
|
||||
entryFilePath := filepath.Join(config.AppInfo.DBPath, "db", entryFileName)
|
||||
file.IsNotExistCreateFile(entryFilePath)
|
||||
|
||||
dir, err := os.ReadDir(modelsPath)
|
||||
if err != nil {
|
||||
logger.Error("read dir error", zap.Error(err))
|
||||
return
|
||||
}
|
||||
json := "["
|
||||
for _, v := range dir {
|
||||
data, err := os.ReadFile(filepath.Join(modelsPath, v.Name(), entryFileName))
|
||||
if err != nil {
|
||||
logger.Error("read entry file error", zap.Error(err))
|
||||
continue
|
||||
}
|
||||
json += string(data) + ","
|
||||
}
|
||||
json = strings.TrimRight(json, ",")
|
||||
json += "]"
|
||||
err = os.WriteFile(entryFilePath, []byte(json), 0666)
|
||||
if err != nil {
|
||||
logger.Error("write entry file error", zap.Error(err))
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
func (c *systemService) GetSystemEntry() string {
|
||||
entryFilePath := filepath.Join(config.AppInfo.DBPath, "db", "entry.json")
|
||||
_, err := os.Open(entryFilePath)
|
||||
if os.IsNotExist(err) {
|
||||
return ""
|
||||
}
|
||||
by, err := os.ReadFile(entryFilePath)
|
||||
if err != nil {
|
||||
logger.Error("read entry file error", zap.Error(err))
|
||||
return ""
|
||||
}
|
||||
return string(by)
|
||||
}
|
||||
func (c *systemService) GetMacAddress() (string, error) {
|
||||
interfaces, err := net.Interfaces()
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user