change branch

This commit is contained in:
a624669980@163.com 2022-07-13 10:12:30 +08:00
parent 0bb624debc
commit 4ee1c81ea7
8 changed files with 60 additions and 64 deletions

View File

@ -86,29 +86,26 @@ func InitRouter() *gin.Engine {
v1AppsGroup.Use()
{
v1AppsGroup.GET("/", v1.AppList) //list
v1AppsGroup.GET("/usage", v1.AppUsageList)
}
v1ContainerGroup := v1Group.Group("/container")
v1ContainerGroup.Use()
{
v1ContainerGroup.GET("/", v1.MyAppList) ///my/list
v1ContainerGroup.POST("/", v1.InstallApp) //app/install
v1ContainerGroup.DELETE("/:id", v1.UnInstallApp) //app/uninstall/:id
//v1ContainerGroup.GET("/:id", v1.ContainerInfo) // /app/info/:id
v1ContainerGroup.GET("/:id", v1.ContainerUpdateInfo) ///update/:id/info
v1ContainerGroup.PUT("/:id", v1.UpdateSetting) ///update/:id/setting
v1ContainerGroup.GET("/:id/logs", v1.ContainerLog) // /app/logs/:id
// there are problems, temporarily do not deal with
v1ContainerGroup.GET("/:id/terminal", v1.DockerTerminal) //app/terminal/:id
v1ContainerGroup.PUT("/:id/state", v1.ChangAppState) // /app/state/:id
v1ContainerGroup.GET("/", v1.MyAppList) ///my/list
v1ContainerGroup.GET("/usage", v1.AppUsageList)
v1ContainerGroup.GET("/:id", v1.ContainerUpdateInfo) ///update/:id/info
v1ContainerGroup.GET("/:id/logs", v1.ContainerLog) // /app/logs/:id
v1ContainerGroup.GET("/networks", v1.GetDockerNetworks) //app/install/config
v1ContainerGroup.GET("/:id/state", v1.GetContainerState) //app/state/:id ?state=install_progress
// there are problems, temporarily do not deal with
v1ContainerGroup.GET("/:id/terminal", v1.DockerTerminal) //app/terminal/:id
v1ContainerGroup.POST("/", v1.InstallApp) //app/install
//v1ContainerGroup.GET("/:id", v1.ContainerInfo) // /app/info/:id
v1ContainerGroup.PUT("/:id", v1.UpdateSetting) ///update/:id/setting
v1ContainerGroup.PUT("/:id/state", v1.ChangAppState) // /app/state/:id
v1ContainerGroup.DELETE("/:id", v1.UnInstallApp) //app/uninstall/:id
//Not used
v1ContainerGroup.PUT("/:id/latest", v1.PutAppUpdate)
//Not used
@ -162,8 +159,8 @@ func InitRouter() *gin.Engine {
v1FileGroup.GET("/", v1.GetDownloadSingleFile) //download/:path
v1FileGroup.POST("/", v1.PostCreateFile)
v1FileGroup.PUT("/", v1.PutFileContent)
v1FileGroup.PUT("/name", v1.RenamePath) //file/rename
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
@ -174,12 +171,14 @@ func InitRouter() *gin.Engine {
v1FolderGroup := v1Group.Group("/folder")
v1FolderGroup.Use()
{
v1FolderGroup.PUT("/name", v1.RenamePath)
v1FolderGroup.GET("/", v1.DirPath) ///file/dirpath
v1FolderGroup.POST("/", v1.MkdirAll) ///file/mkdir
}
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

View File

@ -28,9 +28,7 @@ var diskMap = make(map[string]string)
// @Success 200 {string} string "ok"
// @Router /disk/list [get]
func GetDiskList(c *gin.Context) {
js := make(map[string]string)
c.BindJSON(&js)
t := js["type"]
t := c.DefaultQuery("type", "")
list := service.MyService.Disk().LSBLK(false)
if t == "usb" {
data := []model.DriveUSB{}

View File

@ -114,25 +114,6 @@ func WsSsh(c *gin.Context) {
}
//安装进度推送
func SpeedPush(c *gin.Context) {
//token := c.Query("token")
//if len(token) == 0 || token != config.UserInfo.Token {
// c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR_AUTH_TOKEN, Message: common_err.GetMsg(common_err.ERROR_AUTH_TOKEN)})
// return
//}
//ws, _ := upgrader.Upgrade(c.Writer, c.Request, nil)
//defer ws.Close()
//
//for {
// select {
// case msg := <-WSMSG:
// ws.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintln(msg)))
// }
//}
}
// @Summary 安装app(该接口需要post json数据)
// @Produce application/json
// @Accept application/json
@ -764,7 +745,7 @@ func ContainerLog(c *gin.Context) {
// @Router /app/state/{id} [get]
func GetContainerState(c *gin.Context) {
id := c.Param("id")
t := c.DefaultQuery("type", "0")
//t := c.DefaultQuery("type", "0")
containerInfo, e := service.MyService.App().GetSimpleContainerInfo(id)
if e != nil {
c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: e.Error()})
@ -775,10 +756,10 @@ func GetContainerState(c *gin.Context) {
data["state"] = containerInfo.State
if t == "1" {
appInfo := service.MyService.App().GetAppDBInfo(id)
data["app"] = appInfo
}
// if t == "1" {
// appInfo := service.MyService.App().GetAppDBInfo(id)
// data["app"] = appInfo
// }
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: data})
}

View File

@ -92,13 +92,13 @@ func GetLocalFile(c *gin.Context) {
// @Accept application/json
// @Tags file
// @Security ApiKeyAuth
// @Param t query string false "Compression format" Enums(zip,tar,targz)
// @Param format query string false "Compression format" Enums(zip,tar,targz)
// @Param files query string true "file list eg: filename1,filename2,filename3 "
// @Success 200 {string} string "ok"
// @Router /file/download [get]
func GetDownloadFile(c *gin.Context) {
t := c.Query("t")
t := c.Query("format")
files := c.Query("files")
@ -184,8 +184,22 @@ func GetDownloadFile(c *gin.Context) {
}
func GetDownloadSingleFile(c *gin.Context) {
filePath := c.Param("path")
fileTmp, _ := os.Open(filePath)
filePath := c.Query("path")
if len(filePath) == 0 {
c.JSON(http.StatusOK, model.Result{
Success: common_err.INVALID_PARAMS,
Message: common_err.GetMsg(common_err.INVALID_PARAMS),
})
return
}
fileTmp, err := os.Open(filePath)
if err != nil {
c.JSON(http.StatusOK, model.Result{
Success: common_err.FILE_DOES_NOT_EXIST,
Message: common_err.GetMsg(common_err.FILE_DOES_NOT_EXIST),
})
return
}
defer fileTmp.Close()
fileName := path.Base(filePath)

View File

@ -230,7 +230,7 @@ func PostKillCasaOS(c *gin.Context) {
// @Success 200 {string} string "ok"
// @Router /sys/usb/off [put]
func PutSystemUSBAutoMount(c *gin.Context) {
status := c.Param("state")
status := c.Query("state")
if status == "on" {
service.MyService.System().UpdateUSBAutoMount("True")
service.MyService.System().ExecUSBAutoMountShell("True")

View File

@ -197,6 +197,9 @@ func PutUserInfo(c *gin.Context) {
user.Password = encryption.GetMD5ByStr(json.Password)
service.MyService.User().UpdateUserPassword(user)
}
if len(json.Email) == 0 {
json.Email = user.Email
}
if len(json.Avatar) == 0 {
json.Avatar = user.Avatar
}
@ -206,7 +209,7 @@ func PutUserInfo(c *gin.Context) {
if len(json.Description) == 0 {
json.Description = user.Description
}
if len(user.Nickname) == 0 {
if len(json.Nickname) == 0 {
json.Nickname = user.Nickname
}
service.MyService.User().UpdateUser(json)
@ -333,12 +336,12 @@ func GetUserInfo(c *gin.Context) {
* @router:
*/
func GetUserInfoByUsername(c *gin.Context) {
Username := c.Param("Username")
if len(Username) == 0 {
username := c.Param("username")
if len(username) == 0 {
c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return
}
user := service.MyService.User().GetUserInfoByUserName(Username)
user := service.MyService.User().GetUserInfoByUserName(username)
if user.Id == 0 {
c.JSON(http.StatusOK, model.Result{Success: common_err.USER_NOT_EXIST, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)})
return
@ -550,10 +553,11 @@ func PostUserUploadImage(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: common_err.USER_NOT_EXIST, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)})
return
}
path := config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id) + "/" + key + ext
if t == "avatar" {
path = config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id) + "/avatar" + ext
key = "avatar"
}
path := config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id) + "/" + key + ext
c.SaveUploadedFile(f, path)
data := make(map[string]string, 3)
data["path"] = path

View File

@ -30,10 +30,10 @@ type AppService interface {
SaveContainer(m model2.AppListDBModel)
GetUninstallInfo(id string) model2.AppListDBModel
DeleteApp(id string)
GetContainerInfo(name string) (types.Container, error)
GetContainerInfo(id string) (types.Container, error)
GetAppDBInfo(id string) model2.AppListDBModel
UpdateApp(m model2.AppListDBModel)
GetSimpleContainerInfo(name string) (types.Container, error)
GetSimpleContainerInfo(id string) (types.Container, error)
DelAppConfigDir(path string)
GetSystemAppList() []types.Container
GetHardwareUsageStream()
@ -271,14 +271,14 @@ func (a *appStruct) GetAllDBApps() []model2.AppListDBModel {
}
//获取我的应用列表
func (a *appStruct) GetContainerInfo(name string) (types.Container, error) {
func (a *appStruct) GetContainerInfo(id string) (types.Container, error) {
//获取docker应用
cli, err := client2.NewClientWithOpts(client2.FromEnv)
if err != nil {
loger.Error("Failed to init client", zap.Any("err", err))
}
filters := filters.NewArgs()
filters.Add("name", name)
filters.Add("id", id)
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{All: true, Filters: filters})
if err != nil {
loger.Error("Failed to get container_list", zap.Any("err", err))
@ -291,7 +291,7 @@ func (a *appStruct) GetContainerInfo(name string) (types.Container, error) {
}
func (a *appStruct) GetSimpleContainerInfo(name string) (types.Container, error) {
func (a *appStruct) GetSimpleContainerInfo(id string) (types.Container, error) {
//获取docker应用
cli, err := client2.NewClientWithOpts(client2.FromEnv)
if err != nil {
@ -299,7 +299,7 @@ func (a *appStruct) GetSimpleContainerInfo(name string) (types.Container, error)
}
defer cli.Close()
filters := filters.NewArgs()
filters.Add("name", name)
filters.Add("id", id)
containers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{All: true, Filters: filters})
if err != nil {
return types.Container{}, err

View File

@ -2,7 +2,7 @@
* @Author: LinkLeong link@icewhale.com
* @Date: 2022-03-18 11:40:55
* @LastEditors: LinkLeong
* @LastEditTime: 2022-07-11 18:36:43
* @LastEditTime: 2022-07-12 10:05:37
* @FilePath: /CasaOS/service/user.go
* @Description:
* @Website: https://www.casaos.io
@ -76,12 +76,12 @@ func (u *userService) GetUserAllInfoByName(userName string) (m model.UserDBModel
return
}
func (u *userService) GetUserInfoById(id string) (m model.UserDBModel) {
u.db.Select("username", "id", "role", "nickname", "description", "avatar").Where("id= ?", id).First(&m)
u.db.Select("username", "id", "role", "nickname", "description", "avatar", "email").Where("id= ?", id).First(&m)
return
}
func (u *userService) GetUserInfoByUserName(userName string) (m model.UserDBModel) {
u.db.Select("username", "id", "role", "nickname", "description", "avatar").Where("username= ?", userName).First(&m)
u.db.Select("username", "id", "role", "nickname", "description", "avatar", "email").Where("username= ?", userName).First(&m)
return
}