CasaOS/route/route.go

244 lines
7.8 KiB
Go
Raw Normal View History

2021-09-26 02:35:02 +00:00
package route
import (
"net/http"
2021-09-27 06:17:36 +00:00
"github.com/IceWhaleTech/CasaOS/middleware"
"github.com/IceWhaleTech/CasaOS/pkg/config"
jwt2 "github.com/IceWhaleTech/CasaOS/pkg/utils/jwt"
v1 "github.com/IceWhaleTech/CasaOS/route/v1"
"github.com/IceWhaleTech/CasaOS/web"
2022-01-28 07:34:32 +00:00
"github.com/gin-contrib/gzip"
2021-09-26 02:35:02 +00:00
"github.com/gin-gonic/gin"
)
var swagHandler gin.HandlerFunc
2021-12-01 08:25:56 +00:00
var OnlineDemo bool = false
2021-09-26 02:35:02 +00:00
func InitRouter() *gin.Engine {
2021-09-26 02:35:02 +00:00
r := gin.Default()
2022-04-06 04:10:51 +00:00
2021-09-26 02:35:02 +00:00
r.Use(middleware.Cors())
2022-01-28 07:34:32 +00:00
r.Use(gzip.Gzip(gzip.DefaultCompression))
2021-09-26 02:35:02 +00:00
gin.SetMode(config.ServerInfo.RunMode)
r.StaticFS("/ui", http.FS(web.Static))
2021-09-27 06:17:36 +00:00
r.GET("/", WebUIHome)
//r.GET("/", func(c *gin.Context) {
// c.Redirect(http.StatusMovedPermanently, "ui/")
//})
2021-09-26 02:35:02 +00:00
if swagHandler != nil {
r.GET("/swagger/*any", swagHandler)
}
r.POST("/v1/user/login", v1.Login)
r.GET("/v1/guide/check", v1.GetGuideCheck)
2021-09-26 02:35:02 +00:00
2022-01-24 09:08:28 +00:00
r.GET("/v1/debug", v1.GetSystemConfigDebug)
//set user
r.POST("/v1/user/setusernamepwd", v1.Set_Name_Pwd)
//get user info
2022-03-18 03:13:07 +00:00
r.GET("/v1/user/info", v1.GetUserInfo)
2022-05-05 05:46:55 +00:00
//get user info
r.GET("/v1/person/shareid", v1.GetPersonShareId)
r.GET("/v1/sys/socket/port", v1.GetSystemSocketPort)
2021-09-26 02:35:02 +00:00
v1Group := r.Group("/v1")
v1Group.Use(jwt2.JWT(swagHandler))
{
v1UserGroup := v1Group.Group("/user")
v1UserGroup.Use()
{
2021-09-26 02:35:02 +00:00
//chang head
2022-03-18 03:13:07 +00:00
v1UserGroup.POST("/head", v1.PostUserHead)
2021-09-26 02:35:02 +00:00
//chang user name
2022-04-06 04:10:51 +00:00
v1UserGroup.PUT("/username", v1.PutUserName)
2021-09-26 02:35:02 +00:00
//chang pwd
2022-04-06 04:10:51 +00:00
v1UserGroup.PUT("/password", v1.PutUserPwd)
2021-09-26 02:35:02 +00:00
//edit user info
2022-03-18 03:13:07 +00:00
v1UserGroup.POST("/info", v1.PostUserChangeInfo)
2022-03-18 03:40:38 +00:00
v1UserGroup.PUT("/nick", v1.PutUserChangeNick)
v1UserGroup.PUT("/desc", v1.PutUserChangeDesc)
2022-04-06 04:10:51 +00:00
v1UserGroup.POST("/person/info", v1.PostUserPersonInfo)
v1UserGroup.GET("/shareid", v1.GetUserShareID)
2021-09-26 02:35:02 +00:00
}
v1AppGroup := v1Group.Group("/app")
v1AppGroup.Use()
{
//获取我的已安装的列表
2022-05-05 05:46:55 +00:00
v1AppGroup.GET("/my/list", v1.MyAppList)
2021-12-06 09:08:36 +00:00
//
v1AppGroup.GET("/usage", v1.AppUsageList)
2021-09-26 02:35:02 +00:00
//app详情
v1AppGroup.GET("/appinfo/:id", v1.AppInfo)
//获取未安装的列表
v1AppGroup.GET("/list", v1.AppList)
//获取端口
v1AppGroup.GET("/port", v1.GetPort)
//检查端口
v1AppGroup.GET("/check/:port", v1.PortCheck)
//分类
v1AppGroup.GET("/category", v1.CategoryList)
//容器相关
v1AppGroup.GET("/terminal/:id", v1.DockerTerminal)
✨ New Feature - [Apps] This is a feature that has been highly requested by the community. Import the original Docker application into CasaOS. Now it's easy to import with just a few clicks! - [Apps] App list supports a custom sorting function! You can arrange apps in different orders by dragging the icons. - [Apps] App custom installation supports Docker Compose configuration import in YAML format. - [Files] Added thumbnail preview function for image files. - [Connect] Multiple CasaConenct devices in the LAN will be transmitted through the LAN network. - [System] Added a switch for auto-mounting USB disk devices. 🎈 Enhancement - [System] Optimized the system update alert, you will see the new version update log from the next version. - [Apps] Added live preview for icons in custom installed apps. - [Apps] Optimized the input of WebUI. - [Files] Completely updated the image preview, now it supports switching all images in the same folder, as well as dragging, zooming, rotating and resetting. - [Widgets] Added color levels for CPU and RAM charts. - [Conenct] Optimized the display of the right-click menu of the Connect friends list. 🎈 Changed - [Files] Change the initial display directory to /DATA 🐞 Fixed - [System] Fixed an issue with Raspberry Pi devices failing to boot using USB disks. (Achieved by disabling USB disk auto-mount) - [Apps] Fixed the issue that some Docker CLI commands failed to import. - [Apps] Fixed the issue that the app is not easily recognized in /DATA/AppData directory and docker command line after installation, it will be shown as the app name. (Newly installed apps only) - [Apps] Fixed the issue that Pi-hole cannot be launched after installation in the app store. - [Apps] Fixed the issue that apps cannot be updated with WatchTower. - [Files] Fixed the issue that when there is an upload task, the task status is lost after closing Files.
2022-05-13 10:12:26 +00:00
v1AppGroup.GET("/order", v1.GetAppOrder)
v1AppGroup.POST("/order", v1.PostAppOrder)
2021-09-26 02:35:02 +00:00
//app容器详情
v1AppGroup.GET("/info/:id", v1.ContainerInfo)
//app容器日志
v1AppGroup.GET("/logs/:id", v1.ContainerLog)
//暂停或启动容器
v1AppGroup.PUT("/state/:id", v1.ChangAppState)
//安装app
v1AppGroup.POST("/install", v1.InstallApp)
2021-09-26 02:35:02 +00:00
//卸载app
v1AppGroup.DELETE("/uninstall/:id", v1.UnInstallApp)
//获取进度
v1AppGroup.GET("/state/:id", v1.GetContainerState)
//更新容器配置
v1AppGroup.PUT("/update/:id/setting", v1.UpdateSetting)
//获取可能新数据
v1AppGroup.GET("/update/:id/info", v1.ContainerUpdateInfo)
v1AppGroup.GET("/rely/:id/info", v1.ContainerRelyInfo)
v1AppGroup.GET("/install/config", v1.GetDockerInstallConfig)
2022-05-05 05:46:55 +00:00
v1AppGroup.PUT("/update/:id", v1.PutAppUpdate)
2021-11-25 09:35:01 +00:00
v1AppGroup.POST("/share", v1.ShareAppFile)
2021-09-26 02:35:02 +00:00
}
v1SysGroup := v1Group.Group("/sys")
v1SysGroup.Use()
{
v1SysGroup.GET("/check", v1.CheckVersion)
✨ New Feature - [Apps] This is a feature that has been highly requested by the community. Import the original Docker application into CasaOS. Now it's easy to import with just a few clicks! - [Apps] App list supports a custom sorting function! You can arrange apps in different orders by dragging the icons. - [Apps] App custom installation supports Docker Compose configuration import in YAML format. - [Files] Added thumbnail preview function for image files. - [Connect] Multiple CasaConenct devices in the LAN will be transmitted through the LAN network. - [System] Added a switch for auto-mounting USB disk devices. 🎈 Enhancement - [System] Optimized the system update alert, you will see the new version update log from the next version. - [Apps] Added live preview for icons in custom installed apps. - [Apps] Optimized the input of WebUI. - [Files] Completely updated the image preview, now it supports switching all images in the same folder, as well as dragging, zooming, rotating and resetting. - [Widgets] Added color levels for CPU and RAM charts. - [Conenct] Optimized the display of the right-click menu of the Connect friends list. 🎈 Changed - [Files] Change the initial display directory to /DATA 🐞 Fixed - [System] Fixed an issue with Raspberry Pi devices failing to boot using USB disks. (Achieved by disabling USB disk auto-mount) - [Apps] Fixed the issue that some Docker CLI commands failed to import. - [Apps] Fixed the issue that the app is not easily recognized in /DATA/AppData directory and docker command line after installation, it will be shown as the app name. (Newly installed apps only) - [Apps] Fixed the issue that Pi-hole cannot be launched after installation in the app store. - [Apps] Fixed the issue that apps cannot be updated with WatchTower. - [Files] Fixed the issue that when there is an upload task, the task status is lost after closing Files.
2022-05-13 10:12:26 +00:00
v1SysGroup.GET("/hardware/info", v1.GetSystemHardwareInfo)
2021-09-26 02:35:02 +00:00
v1SysGroup.POST("/update", v1.SystemUpdate)
v1SysGroup.GET("/wsssh", v1.WsSsh)
v1SysGroup.GET("/config", v1.GetSystemConfig)
v1SysGroup.GET("/error/logs", v1.GetCasaOSErrorLogs)
2021-09-26 02:35:02 +00:00
v1SysGroup.POST("/config", v1.PostSetSystemConfig)
v1SysGroup.GET("/widget/config", v1.GetWidgetConfig)
v1SysGroup.POST("/widget/config", v1.PostSetWidgetConfig)
v1SysGroup.GET("/port", v1.GetCasaOSPort)
2021-12-06 09:08:36 +00:00
v1SysGroup.PUT("/port", v1.PutCasaOSPort)
v1SysGroup.POST("/kill", v1.PostKillCasaOS)
2021-12-29 08:42:20 +00:00
v1SysGroup.GET("/info", v1.Info)
2022-04-06 04:10:51 +00:00
v1SysGroup.PUT("/usb/off", v1.PutSystemOffUSBAutoMount)
✨ New Feature - [Apps] This is a feature that has been highly requested by the community. Import the original Docker application into CasaOS. Now it's easy to import with just a few clicks! - [Apps] App list supports a custom sorting function! You can arrange apps in different orders by dragging the icons. - [Apps] App custom installation supports Docker Compose configuration import in YAML format. - [Files] Added thumbnail preview function for image files. - [Connect] Multiple CasaConenct devices in the LAN will be transmitted through the LAN network. - [System] Added a switch for auto-mounting USB disk devices. 🎈 Enhancement - [System] Optimized the system update alert, you will see the new version update log from the next version. - [Apps] Added live preview for icons in custom installed apps. - [Apps] Optimized the input of WebUI. - [Files] Completely updated the image preview, now it supports switching all images in the same folder, as well as dragging, zooming, rotating and resetting. - [Widgets] Added color levels for CPU and RAM charts. - [Conenct] Optimized the display of the right-click menu of the Connect friends list. 🎈 Changed - [Files] Change the initial display directory to /DATA 🐞 Fixed - [System] Fixed an issue with Raspberry Pi devices failing to boot using USB disks. (Achieved by disabling USB disk auto-mount) - [Apps] Fixed the issue that some Docker CLI commands failed to import. - [Apps] Fixed the issue that the app is not easily recognized in /DATA/AppData directory and docker command line after installation, it will be shown as the app name. (Newly installed apps only) - [Apps] Fixed the issue that Pi-hole cannot be launched after installation in the app store. - [Apps] Fixed the issue that apps cannot be updated with WatchTower. - [Files] Fixed the issue that when there is an upload task, the task status is lost after closing Files.
2022-05-13 10:12:26 +00:00
v1SysGroup.PUT("/usb/on", v1.PutSystemOnUSBAutoMount)
2022-04-06 04:10:51 +00:00
v1SysGroup.GET("/usb", v1.GetSystemUSBAutoMount)
v1SysGroup.GET("/cpu", v1.CupInfo)
v1SysGroup.GET("/mem", v1.MemInfo)
v1SysGroup.GET("/disk", v1.DiskInfo)
v1SysGroup.GET("/network", v1.NetInfo)
2021-09-26 02:35:02 +00:00
}
v1FileGroup := v1Group.Group("/file")
v1FileGroup.Use()
{
v1FileGroup.PUT("/rename", v1.RenamePath)
v1FileGroup.GET("/read", v1.GetFilerContent)
v1FileGroup.POST("/upload", v1.PostFileUpload)
v1FileGroup.GET("/upload", v1.GetFileUpload)
2022-01-28 08:24:28 +00:00
v1FileGroup.GET("/dirpath", v1.DirPath)
2022-02-17 10:43:25 +00:00
//create folder
2021-09-26 02:35:02 +00:00
v1FileGroup.POST("/mkdir", v1.MkdirAll)
v1FileGroup.POST("/create", v1.PostCreateFile)
2021-09-26 02:35:02 +00:00
v1FileGroup.GET("/download", v1.GetDownloadFile)
v1FileGroup.GET("/download/*path", v1.GetDownloadSingleFile)
2022-02-17 10:43:25 +00:00
v1FileGroup.POST("/operate", v1.PostOperateFileOrDir)
v1FileGroup.DELETE("/delete", v1.DeleteFile)
v1FileGroup.PUT("/update", v1.PutFileContent)
2022-05-05 05:46:55 +00:00
v1FileGroup.GET("/image", v1.GetFileImage)
v1FileGroup.DELETE("/operate/:id", v1.DeleteOperateFileOrDir)
2021-09-26 02:35:02 +00:00
//v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
}
v1DiskGroup := v1Group.Group("/disk")
v1DiskGroup.Use()
{
2021-12-29 08:42:20 +00:00
v1DiskGroup.GET("/check", v1.GetDiskCheck)
v1DiskGroup.GET("/list", v1.GetDiskList)
2021-09-26 02:35:02 +00:00
//获取磁盘详情
v1DiskGroup.GET("/info", v1.GetDiskInfo)
//format storage
2021-09-26 02:35:02 +00:00
v1DiskGroup.POST("/format", v1.FormatDisk)
// add storage
v1DiskGroup.POST("/storage", v1.AddPartition)
//mount SATA disk
v1DiskGroup.POST("/mount", v1.PostMountDisk)
//umount sata disk
v1DiskGroup.POST("/umount", v1.PostDiskUmount)
2021-09-26 02:35:02 +00:00
//获取可以格式化的内容
v1DiskGroup.GET("/type", v1.FormatDiskType)
//删除分区
v1DiskGroup.DELETE("/delpart", v1.RemovePartition)
v1DiskGroup.GET("/usb", v1.GetUSBList)
2021-09-26 02:35:02 +00:00
}
v1ShareGroup := v1Group.Group("/share")
v1ShareGroup.Use()
{
v1ShareGroup.POST("/add", v1.PostShareDirAdd)
v1ShareGroup.DELETE("/del/:id", v1.DeleteShareDirDel)
v1ShareGroup.GET("/list", v1.GetShareDirList)
v1ShareGroup.GET("/info/:id", v1.GetShareDirInfo)
v1ShareGroup.PUT("/update/:id", v1.PutShareDirEdit)
}
v1TaskGroup := v1Group.Group("/task")
v1TaskGroup.Use()
{
v1TaskGroup.GET("/list", v1.GetTaskList)
v1TaskGroup.PUT("/update", v1.PutTaskUpdate)
v1TaskGroup.POST("/add", v1.PostTaskAdd)
v1TaskGroup.PUT("/completion/:id", v1.PutTaskMarkerCompletion)
}
2022-05-05 05:46:55 +00:00
2022-04-06 04:10:51 +00:00
v1PersonGroup := v1Group.Group("/person")
2022-02-17 10:43:25 +00:00
v1PersonGroup.Use()
{
✨ New Feature - [Apps] This is a feature that has been highly requested by the community. Import the original Docker application into CasaOS. Now it's easy to import with just a few clicks! - [Apps] App list supports a custom sorting function! You can arrange apps in different orders by dragging the icons. - [Apps] App custom installation supports Docker Compose configuration import in YAML format. - [Files] Added thumbnail preview function for image files. - [Connect] Multiple CasaConenct devices in the LAN will be transmitted through the LAN network. - [System] Added a switch for auto-mounting USB disk devices. 🎈 Enhancement - [System] Optimized the system update alert, you will see the new version update log from the next version. - [Apps] Added live preview for icons in custom installed apps. - [Apps] Optimized the input of WebUI. - [Files] Completely updated the image preview, now it supports switching all images in the same folder, as well as dragging, zooming, rotating and resetting. - [Widgets] Added color levels for CPU and RAM charts. - [Conenct] Optimized the display of the right-click menu of the Connect friends list. 🎈 Changed - [Files] Change the initial display directory to /DATA 🐞 Fixed - [System] Fixed an issue with Raspberry Pi devices failing to boot using USB disks. (Achieved by disabling USB disk auto-mount) - [Apps] Fixed the issue that some Docker CLI commands failed to import. - [Apps] Fixed the issue that the app is not easily recognized in /DATA/AppData directory and docker command line after installation, it will be shown as the app name. (Newly installed apps only) - [Apps] Fixed the issue that Pi-hole cannot be launched after installation in the app store. - [Apps] Fixed the issue that apps cannot be updated with WatchTower. - [Files] Fixed the issue that when there is an upload task, the task status is lost after closing Files.
2022-05-13 10:12:26 +00:00
v1PersonGroup.GET("/detection", v1.GetPersonDetection)
2022-04-06 04:10:51 +00:00
v1PersonGroup.GET("/users", v1.GetPersonFriend)
v1PersonGroup.POST("/user/:shareids", v1.PostAddPersonFriend)
v1PersonGroup.DELETE("/user/:shareid", v1.DeletePersonFriend)
v1PersonGroup.GET("/directory", v1.GetPersonDirectory)
v1PersonGroup.GET("/file", v1.GetPersonFile)
v1PersonGroup.GET("/refile/:uuid", v1.GetPersonReFile)
v1PersonGroup.PUT("/remarks/:shareid", v1.PutPersonRemarks)
v1PersonGroup.GET("/list", v1.GetPersonDownloadList)
v1PersonGroup.DELETE("/file/:uuid", v1.DeletePersonDownloadFile)
v1PersonGroup.POST("/share", v1.PostPersonShare)
2022-05-05 05:46:55 +00:00
v1PersonGroup.POST("/file/:shareid", v1.PostPersonFile)
2022-04-06 04:10:51 +00:00
v1PersonGroup.GET("/share", v1.GetPersonShare)
v1PersonGroup.POST("/down/dir", v1.PostPersonDownDir)
v1PersonGroup.GET("/down/dir", v1.GetPersonDownDir)
v1PersonGroup.PUT("/block/:shareid", v1.PutPersonBlock)
v1PersonGroup.GET("/public", v1.GetPersonPublic)
2022-05-05 05:46:55 +00:00
v1PersonGroup.PUT("/friend/:shareid", v1.PutPersonAgreeFriend)
v1PersonGroup.PUT("/write/:shareid", v1.PutPersonWrite)
v1PersonGroup.GET("/image/thumbnail/:shareid", v1.GetPersonImageThumbnail)
}
v1AnalyseGroup := v1Group.Group("/analyse")
v1AnalyseGroup.Use()
{
v1AnalyseGroup.POST("/app", v1.PostAppAnalyse)
2022-02-17 10:43:25 +00:00
}
2021-11-25 09:35:01 +00:00
v1Group.GET("/sync/config", v1.GetSyncConfig)
v1Group.Any("/syncthing/*url", v1.SyncToSyncthing)
2021-09-26 02:35:02 +00:00
}
return r
}