update user

This commit is contained in:
a624669980@163.com 2022-07-04 18:53:32 +08:00
parent 1eb2184148
commit 9e3e7fc0f9
10 changed files with 63 additions and 468 deletions

View File

@ -1,27 +0,0 @@
/*
* @Author: LinkLeong link@icewhale.com
* @Date: 2022-03-18 11:40:55
* @LastEditors: LinkLeong
* @LastEditTime: 2022-05-13 14:48:01
* @FilePath: /CasaOS/model/app-analyse.go
* @Description:
* @Website: https://www.casaos.io
* Copyright (c) 2022 by icewhale, All Rights Reserved.
*/
package model
type AppAnalyse struct {
Name string `json:"name"`
Type string `json:"type"`
UUId string `json:"uuid"`
Language string `json:"language"`
Version string `json:"version"`
}
type ConnectionStatus struct {
From string `json:"from"`
To string `json:"to"`
Error string `json:"error"`
UUId string `json:"uuid"`
Event string `json:"event"`
}

View File

@ -1,16 +0,0 @@
/*
* @Author: LinkLeong link@icewhale.com
* @Date: 2022-05-27 18:42:42
* @LastEditors: LinkLeong
* @LastEditTime: 2022-05-27 18:43:08
* @FilePath: /CasaOS/model/notify/person.go
* @Description:
* @Website: https://www.casaos.io
* Copyright (c) 2022 by icewhale, All Rights Reserved.
*/
package notify
type Person struct {
ShareId string `json:"share_id"`
Type string `json:"type"`
}

View File

@ -1,54 +0,0 @@
package model
import "time"
type PersionModel struct {
Token string `json:"token"`
Ips []string `json:"ips"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
//记录链接状态
type ConnectState struct {
From string `json:"from"`
To string `json:"to"`
Type string `json:"type"` //current state 1:ready 2:ok
CreatedAt time.Time `json:"created_at"`
UUId string `json:"uuid"` //对接标识
}
type MessageModel struct {
Type string `json:"type"`
Data interface{} `json:"data"`
UUId string `json:"uuid"`
From string `json:"from"`
To string `json:"to"`
}
type TranFileModel struct {
Hash string `json:"hash"` //Verify current fragment integrity
Length int `json:"length"`
Index int `json:"index"`
}
//需要获取文件详情
type FileDetailModel struct {
Path string `json:"path"`
}
//返回文件详情
type FileSummaryModel struct {
Hash string `json:"hash"` //Verify file
Name string `json:"name"`
BlockSize int `json:"block_size"`
Length int `json:"length"`
Size int64 `json:"size"`
Message string `json:"message"`
}
type FriendsModel struct {
Id uint `gorm:"column:id;primary_key" json:"id"`
NickName string `json:"nick_name"`
Desc string `json:"desc"`
ShareId string `json:"share_id"`
}

View File

@ -49,14 +49,6 @@ const (
//shortcuts
SHORTCUTS_URL_ERROR = 70001
//person
PERSON_REMOTE_ERROR = 80001
PERSON_DOWN_NOT_EXIST = 80002
PERSON_EXIST_DOWNLOAD = 80003
PERSON_NOT_EXIST_USER = 80004
PERSON_EXIST_FRIEND = 80005
PERSON_MYSELF = 80006
)
var MsgFlags = map[int]string{
@ -108,12 +100,6 @@ var MsgFlags = map[int]string{
FILE_DELETE_ERROR: "Delete error",
SHORTCUTS_URL_ERROR: "URL error",
PERSON_REMOTE_ERROR: "Remote connection error",
PERSON_DOWN_NOT_EXIST: "Download record does not exist",
PERSON_EXIST_DOWNLOAD: "The same download task exists",
PERSON_EXIST_FRIEND: "Friend already exist",
PERSON_NOT_EXIST_USER: "User does not exist",
PERSON_MYSELF: "You can not add yourself",
COMMAND_ERROR_INVALID_OPERATION: "invalid operation",
}

View File

@ -2,7 +2,7 @@
* @Author: LinkLeong link@icewhale.com
* @Date: 2021-09-30 18:18:14
* @LastEditors: LinkLeong
* @LastEditTime: 2022-06-24 10:02:46
* @LastEditTime: 2022-07-04 18:15:09
* @FilePath: /CasaOS/pkg/utils/jwt/jwt.go
* @Description:
* @Website: https://www.casaos.io
@ -16,67 +16,26 @@ import (
jwt "github.com/golang-jwt/jwt/v4"
)
// type Claims struct {
// UserName string `json:"username"`
// PassWord string `json:"password"`
// Id int `json:"id"`
// jwt.RegisteredClaims
// }
// var jwtSecret []byte
// //创建token
// func GenerateToken(username, password string, id int, issuer string, t time.Duration) (string, error) {
// clims := Claims{
// username,
// password,
// id,
// jwt.RegisteredClaims{
// ExpiresAt: jwt.NewNumericDate(time.Now().Add(t)),
// IssuedAt: jwt.NewNumericDate(time.Now()),
// NotBefore: jwt.NewNumericDate(time.Now()),
// Issuer: issuer,
// },
// }
// tokenClaims := jwt.NewWithClaims(jwt.SigningMethodHS256, clims)
// token, err := tokenClaims.SignedString(jwtSecret)
// return token, err
// }
// //解析token
// func ParseToken(token string) (*Claims, error) {
// tokenClaims, err := jwt.ParseWithClaims(token, &Claims{}, func(token *jwt.Token) (interface{}, error) {
// return jwtSecret, nil
// })
// if tokenClaims != nil {
// if clims, ok := tokenClaims.Claims.(*Claims); ok && tokenClaims.Valid {
// return clims, nil
// }
// }
// return nil, err
// }
//****************** soon to be removed ******************
type Claims struct {
UserName string `json:"username"`
PassWord string `json:"password"`
jwt.StandardClaims
Id int `json:"id"`
jwt.RegisteredClaims
}
var jwtSecret []byte
//创建token
func GenerateToken(username, password string) (string, error) {
expireTime := time.Now().AddDate(999, 0, 0)
func GenerateToken(username, password string, id int, issuer string, t time.Duration) (string, error) {
clims := Claims{
username,
password,
jwt.StandardClaims{
ExpiresAt: expireTime.Unix(),
Issuer: "gin-blog",
id,
jwt.RegisteredClaims{
ExpiresAt: jwt.NewNumericDate(time.Now().Add(t)),
IssuedAt: jwt.NewNumericDate(time.Now()),
NotBefore: jwt.NewNumericDate(time.Now()),
Issuer: issuer,
},
}

View File

@ -2,7 +2,7 @@
* @Author: LinkLeong link@icewhale.com
* @Date: 2022-06-17 14:01:25
* @LastEditors: LinkLeong
* @LastEditTime: 2022-06-24 10:13:52
* @LastEditTime: 2022-07-04 18:14:28
* @FilePath: /CasaOS/pkg/utils/jwt/jwt_helper.go
* @Description:
* @Website: https://www.casaos.io
@ -12,7 +12,8 @@ package jwt
import (
"fmt"
"net/http"
"strconv"
"time"
"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
@ -20,58 +21,6 @@ import (
"github.com/gin-gonic/gin"
)
// func JWT() gin.HandlerFunc {
// return func(c *gin.Context) {
// var code int
// code = common_err.SUCCESS
// token := c.GetHeader("Authorization")
// if len(token) == 0 {
// token = c.Query("token")
// }
// if token == "" {
// code = common_err.INVALID_PARAMS
// }
// claims, err := ParseToken(token)
// //_, err := ParseToken(token)
// if err != nil {
// code = common_err.ERROR_AUTH_TOKEN
// } else if !claims.VerifyExpiresAt(time.Now(), true) || !claims.VerifyIssuer("casaos", true) {
// code = common_err.ERROR_AUTH_TOKEN
// }
// if code != common_err.SUCCESS {
// c.JSON(code, model.Result{Success: code, Message: common_err.GetMsg(code)})
// c.Abort()
// return
// }
// c.Request.Header.Add("user_id", strconv.Itoa(claims.Id))
// c.Next()
// }
// }
// //get AccessToken
// func GetAccessToken(username, pwd string, id int) string {
// token, err := GenerateToken(username, pwd, id, "casaos", 3*time.Hour*time.Duration(1))
// if err == nil {
// return token
// } else {
// loger2.Error(fmt.Sprintf("Get Token Fail: %V", err))
// return ""
// }
// }
// func GetRefreshToken(username, pwd string, id int) string {
// token, err := GenerateToken(username, pwd, id, "fresh", 7*24*time.Hour*time.Duration(1))
// if err == nil {
// return token
// } else {
// loger2.Error(fmt.Sprintf("Get Token Fail: %V", err))
// return ""
// }
// }
//*************** soon to be removed *****************
func JWT() gin.HandlerFunc {
return func(c *gin.Context) {
var code int
@ -84,32 +33,40 @@ func JWT() gin.HandlerFunc {
code = common_err.INVALID_PARAMS
}
//claims, err := ParseToken(token)
_, err := ParseToken(token)
claims, err := ParseToken(token)
//_, err := ParseToken(token)
if err != nil {
code = common_err.ERROR_AUTH_TOKEN
} else if !claims.VerifyExpiresAt(time.Now(), true) || !claims.VerifyIssuer("casaos", true) {
code = common_err.ERROR_AUTH_TOKEN
}
//else if time.Now().Unix() > claims.ExpiresAt {
// code = oasis_err2.ERROR_AUTH_TOKEN
//}
if code != common_err.SUCCESS {
c.JSON(http.StatusOK, model.Result{Success: code, Message: common_err.GetMsg(code)})
c.JSON(code, model.Result{Success: code, Message: common_err.GetMsg(code)})
c.Abort()
return
}
c.Request.Header.Add("user_id", strconv.Itoa(claims.Id))
c.Next()
}
}
//获取token
func GetToken(username, pwd string) string {
token, err := GenerateToken(username, pwd)
//get AccessToken
func GetAccessToken(username, pwd string, id int) string {
token, err := GenerateToken(username, pwd, id, "casaos", 3*time.Hour*time.Duration(1))
if err == nil {
return token
} else {
loger2.NewOLoger().Fatal(fmt.Sprintf("Get Token Fail: %V", err))
loger2.Error(fmt.Sprintf("Get Token Fail: %V", err))
return ""
}
}
func GetRefreshToken(username, pwd string, id int) string {
token, err := GenerateToken(username, pwd, id, "fresh", 7*24*time.Hour*time.Duration(1))
if err == nil {
return token
} else {
loger2.Error(fmt.Sprintf("Get Token Fail: %V", err))
return ""
}
}

View File

@ -38,8 +38,7 @@ func InitRouter() *gin.Engine {
r.GET("/v1/sys/init/check", v1.GetSystemInitCheck)
r.GET("/v1/guide/check", v1.GetGuideCheck)
r.GET("/v1/debug", v1.GetSystemConfigDebug)
r.POST("/v1/user/setusernamepwd", v1.Set_Name_Pwd)
r.GET("/v1/user/info/:id", v1.GetUserInfo)
r.GET("/v1/user/avatar/:id", v1.GetUserAvatar)
r.GET("/v1/user/image", v1.GetUserImage)
@ -52,28 +51,18 @@ func InitRouter() *gin.Engine {
v1UserGroup := v1Group.Group("/user")
v1UserGroup.Use()
{
//****************** New version needs to be modified start ******************
//chang user name
v1UserGroup.GET("/info", v1.GetUserInfo)
v1UserGroup.PUT("/username", v1.PutUserName)
v1UserGroup.PUT("/password", v1.PutUserPwd)
v1UserGroup.PUT("/nick", v1.PutUserNick)
v1UserGroup.PUT("/desc", v1.PutUserDesc)
v1UserGroup.GET("/info", v1.GetUserInfoByUserName)
v1UserGroup.GET("/custom/:id/:key", v1.GetUserCustomConf)
v1UserGroup.POST("/custom/:id/:key", v1.PostUserCustomConf)
v1UserGroup.DELETE("/custom/:id/:key", v1.DeleteUserCustomConf)
v1UserGroup.POST("/upload/image/:id/:key", v1.PostUserUploadImage)
v1UserGroup.POST("/file/image/:id/:key", v1.PostUserFileImage)
v1UserGroup.DELETE("/image/:id", v1.DeleteUserImage)
//****************** New version needs to be modified end ******************
//****************** soon to be removed start ******************
v1UserGroup.POST("/person/info", v1.PostUserPersonInfo)
v1UserGroup.GET("/shareid", v1.GetUserShareID)
//****************** soon to be removed end ******************
//v1UserGroup.GET("/info", v1.GetUserInfo)
v1UserGroup.GET("/custom/:key", v1.GetUserCustomConf)
v1UserGroup.POST("/custom/:key", v1.PostUserCustomConf)
v1UserGroup.DELETE("/custom/:key", v1.DeleteUserCustomConf)
v1UserGroup.POST("/upload/image/:key", v1.PostUserUploadImage)
v1UserGroup.POST("/file/image/:key", v1.PostUserFileImage)
v1UserGroup.DELETE("/image", v1.DeleteUserImage)
v1UserGroup.PUT("/avatar", v1.PutUserAvatar)
v1UserGroup.GET("/avatar", v1.GetUserAvatar)

View File

@ -10,15 +10,16 @@ import (
"path/filepath"
"strconv"
"strings"
"time"
"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/model/system_model"
"github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/utils/common_err"
"github.com/IceWhaleTech/CasaOS/pkg/utils/encryption"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
"github.com/IceWhaleTech/CasaOS/pkg/utils/jwt"
model2 "github.com/IceWhaleTech/CasaOS/service/model"
"github.com/IceWhaleTech/CasaOS/types"
"github.com/tidwall/gjson"
"github.com/IceWhaleTech/CasaOS/service"
@ -106,17 +107,13 @@ func PostUserLogin(c *gin.Context) {
model.Result{Success: common_err.PWD_INVALID, Message: common_err.GetMsg(common_err.PWD_INVALID)})
return
}
token := system_model.VerifyInformation{}
token.AccessToken = jwt.GetAccessToken(user.UserName, user.Password, user.Id)
token.RefreshToken = jwt.GetRefreshToken(user.UserName, user.Password, user.Id)
token.ExpiresAt = time.Now().Add(3 * time.Hour * time.Duration(1)).Unix()
data := make(map[string]interface{}, 2)
user.Password = ""
// token := system_model.VerifyInformation{}
// token.AccessToken = jwt.GetAccessToken(user.UserName, user.Password, user.Id)
// token.RefreshToken = jwt.GetRefreshToken(user.UserName, user.Password, user.Id)
// token.ExpiresAt = time.Now().Add(3 * time.Hour * time.Duration(1)).Unix()
// data := make(map[string]interface{}, 2)
// data["token"] = token
// data["user"] = user
data := make(map[string]interface{}, 3)
data["token"] = jwt.GetToken(username, pwd)
data["version"] = types.CURRENTVERSION
data["token"] = token
data["user"] = user
c.JSON(http.StatusOK,
@ -190,13 +187,11 @@ func GetUserAvatar(c *gin.Context) {
// @Success 200 {string} string "ok"
// @Router /user/name/:id [put]
func PutUserName(c *gin.Context) {
//id := c.GetHeader("user_id")
id := c.GetHeader("user_id")
json := make(map[string]string)
c.BindJSON(&json)
//userName := json["user_name"]
username := json["username"]
id := json["user_id"]
if len(username) == 0 {
userName := json["user_name"]
if len(userName) == 0 {
c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR)})
return
}
@ -207,7 +202,7 @@ func PutUserName(c *gin.Context) {
model.Result{Success: common_err.USER_NOT_EXIST, Message: common_err.GetMsg(common_err.USER_NOT_EXIST)})
return
}
user.UserName = username
user.UserName = userName
service.MyService.User().UpdateUser(user)
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: user})
}
@ -256,11 +251,10 @@ func PutUserPwd(c *gin.Context) {
// @Router /user/nick [put]
func PutUserNick(c *gin.Context) {
//id := c.GetHeader("user_id")
id := c.GetHeader("user_id")
json := make(map[string]string)
c.BindJSON(&json)
nickName := json["nick_name"]
id := json["user_id"]
if len(nickName) == 0 {
c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return
@ -273,8 +267,6 @@ func PutUserNick(c *gin.Context) {
}
user.NickName = nickName
service.MyService.User().UpdateUser(user)
//TODO:person remove together
go service.MyService.Casa().PushUserInfo()
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: user})
}
@ -287,10 +279,9 @@ func PutUserNick(c *gin.Context) {
// @Success 200 {string} string "ok"
// @Router /user/desc [put]
func PutUserDesc(c *gin.Context) {
// id := c.GetHeader("user_id")
id := c.GetHeader("user_id")
json := make(map[string]string)
c.BindJSON(&json)
id := json["user_id"]
desc := json["description"]
if len(desc) == 0 {
c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
@ -309,39 +300,6 @@ func PutUserDesc(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: user})
}
// @Summary Modify user person information (Initialization use)
// @Produce application/json
// @Accept multipart/form-data
// @Tags user
// @Param nick_name formData string false "user nick name"
// @Param description formData string false "Description"
// @Security ApiKeyAuth
// @Success 200 {string} string "ok"
// @Router /user/person/info [post]
func PostUserPersonInfo(c *gin.Context) {
json := make(map[string]string)
c.BindJSON(&json)
desc := json["description"]
nickName := json["nick_name"]
id := json["user_id"]
if len(desc) == 0 || len(nickName) == 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().GetUserInfoById(id)
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
}
//user_service.SetUser("", "", "", "", desc, nickName)
user.NickName = nickName
user.Description = desc
service.MyService.User().UpdateUser(user)
go service.MyService.Casa().PushUserInfo()
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: user})
}
// @Summary get user info
// @Produce application/json
// @Accept application/json
@ -349,8 +307,7 @@ func PostUserPersonInfo(c *gin.Context) {
// @Success 200 {string} string "ok"
// @Router /user/info/:id [get]
func GetUserInfo(c *gin.Context) {
//id := c.GetHeader("user_id")
id := c.Param("id")
id := c.GetHeader("user_id")
user := service.MyService.User().GetUserInfoById(id)
//*****
@ -401,17 +358,6 @@ func GetUserInfoByUserName(c *gin.Context) {
})
}
// @Summary Get my shareId
// @Produce application/json
// @Accept application/json
// @Tags user
// @Security ApiKeyAuth
// @Success 200 {string} string "ok"
// @Router /user/shareid [get]
func GetUserShareID(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: config.ServerInfo.Token})
}
/**
* @description: get all user name
* @method:GET
@ -443,8 +389,8 @@ func GetUserCustomConf(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return
}
//id := c.GetHeader("user_id")
id := c.Param("id")
id := c.GetHeader("user_id")
user := service.MyService.User().GetUserInfoById(id)
// user := service.MyService.User().GetUserInfoByUserName(userName)
if user.Id == 0 {
@ -473,8 +419,7 @@ func PostUserCustomConf(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return
}
//id := c.GetHeader("user_id")
id := c.Param("id")
id := c.GetHeader("user_id")
user := service.MyService.User().GetUserInfoById(id)
if user.Id == 0 {
c.JSON(http.StatusOK,
@ -500,8 +445,7 @@ func DeleteUserCustomConf(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return
}
//id := c.GetHeader("user_id")
id := c.Param("id")
id := c.GetHeader("user_id")
user := service.MyService.User().GetUserInfoById(id)
if user.Id == 0 {
c.JSON(http.StatusOK,
@ -531,8 +475,7 @@ func DeleteUser(c *gin.Context) {
* @router:/user/file/image/:key
*/
func PostUserFileImage(c *gin.Context) {
//id := c.GetHeader("user_id")
id := c.Param("id")
id := c.GetHeader("user_id")
json := make(map[string]string)
c.BindJSON(&json)
@ -583,8 +526,7 @@ func PostUserFileImage(c *gin.Context) {
* @router:/user/upload/image/:key
*/
func PostUserUploadImage(c *gin.Context) {
//id := c.GetHeader("user_id")
id := c.Param("id")
id := c.GetHeader("user_id")
f, err := c.FormFile("file")
key := c.Param("key")
if len(key) == 0 {
@ -645,8 +587,7 @@ func GetUserImage(c *gin.Context) {
c.File(filePath)
}
func DeleteUserImage(c *gin.Context) {
// id := c.GetHeader("user_id")
id := c.Param("id")
id := c.GetHeader("user_id")
path := c.Query("path")
if len(path) == 0 {
c.JSON(http.StatusOK, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
@ -696,40 +637,3 @@ func DeleteUserImage(c *gin.Context) {
// c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: verifyInfo})
// }
//******** soon to be removed ********
// @Summary 设置用户名和密码
// @Produce application/json
// @Accept multipart/form-data
// @Tags user
// @Param username formData string true "User name"
// @Param pwd formData string true "password"
// @Security ApiKeyAuth
// @Success 200 {string} string "ok"
// @Router /user/setusernamepwd [post]
func Set_Name_Pwd(c *gin.Context) {
json := make(map[string]string)
c.BindJSON(&json)
username := json["username"]
pwd := json["pwd"]
if service.MyService.User().GetUserCount() > 0 || len(username) == 0 || len(pwd) == 0 {
c.JSON(http.StatusOK,
model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.INVALID_PARAMS)})
return
}
user := model2.UserDBModel{}
user.UserName = username
user.Password = encryption.GetMD5ByStr(pwd)
user.Role = "admin"
user = service.MyService.User().CreateUser(user)
if user.Id == 0 {
c.JSON(http.StatusOK, model.Result{Success: common_err.ERROR, Message: common_err.GetMsg(common_err.ERROR)})
return
}
file.MkDir(config.AppInfo.UserDataPath + "/" + strconv.Itoa(user.Id))
c.JSON(http.StatusOK, model.Result{Success: common_err.SUCCESS, Message: common_err.GetMsg(common_err.SUCCESS), Data: user})
}

View File

@ -23,12 +23,6 @@ type CasaService interface {
GetServerCategoryList() []model.CategoryList
GetServerAppInfo(id, t string, language string) model.ServerAppList
ShareAppFile(body []byte) string
PushHeart(id, t string, language string)
PushConnectionStatus(uuid, err string, from, to, event string)
PushUserInfo()
GetUserInfoByShareId(shareId string) model.UserInfo
GetPersonPublic() (list []model.FriendsModel)
GetCasaosVersion() model.Version
AsyncGetServerList() (collection model.ServerAppListCollection)
AsyncGetServerCategoryList() []model.CategoryList
@ -289,86 +283,6 @@ func (o *casaService) GetCasaosVersion() model.Version {
return version
}
func (o *casaService) PushHeart(id, t string, language string) {
m := model.CasaOSHeart{}
m.UuId = id
m.Type = t
b, _ := json.Marshal(m)
head := make(map[string]string)
head["Authorization"] = GetToken()
infoS := httper2.Post(config.ServerInfo.ServerApi+"/v1/analyse/heart", b, "application/json", head)
info := model.ServerAppList{}
json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info)
}
func (o *casaService) PushConnectionStatus(uuid, err string, from, to, event string) {
m := model.ConnectionStatus{}
m.UUId = uuid
m.Error = err
m.From = from
m.To = to
m.Event = event
b, _ := json.Marshal(m)
head := make(map[string]string)
head["Authorization"] = GetToken()
infoS := httper2.Post(config.ServerInfo.ServerApi+"/v1/analyse/connect", b, "application/json", head)
info := model.ServerAppList{}
json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info)
}
func (o *casaService) PushUserInfo() {
m := model.UserInfo{}
m.Desc = config.UserInfo.Description
m.Avatar = config.UserInfo.Avatar
m.NickName = config.UserInfo.NickName
m.ShareId = config.ServerInfo.Token
b, _ := json.Marshal(m)
head := make(map[string]string)
head["Authorization"] = GetToken()
infoS := httper2.Post(config.ServerInfo.ServerApi+"/v1/user/info", b, "application/json", head)
info := model.ServerAppList{}
json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info)
}
func (o *casaService) GetUserInfoByShareId(shareId string) model.UserInfo {
head := make(map[string]string)
head["Authorization"] = GetToken()
infoS := httper2.Get(config.ServerInfo.ServerApi+"/v1/user/info/"+shareId, head)
info := model.UserInfo{}
json2.Unmarshal([]byte(gjson.Get(infoS, "data").String()), &info)
return info
}
func (o *casaService) GetPersonPublic() (list []model.FriendsModel) {
head := make(map[string]string)
head["Authorization"] = GetToken()
listS := httper2.Get(config.ServerInfo.ServerApi+"/v1/person/public", head)
json2.Unmarshal([]byte(gjson.Get(listS, "data").String()), &list)
return list
}
func NewCasaService() CasaService {
return &casaService{}
}

View File

@ -33,7 +33,6 @@ type NotifyServer interface {
SendMemInfoBySocket(mem map[string]interface{})
SendUSBInfoBySocket(list []model2.DriveUSB)
SendDiskInfoBySocket(disk model2.Summary)
SendPersonStatusBySocket(status notify.Person)
SendFileOperateNotify(nowSend bool)
SendInstallAppBySocket(app notify.Application)
SendAllHardwareStatusBySocket(disk model2.Summary, list []model2.DriveUSB, mem map[string]interface{}, cpu map[string]interface{}, netList []model2.IOCountersStat)
@ -224,22 +223,6 @@ func (i *notifyServer) SendFileOperateNotify(nowSend bool) {
}
func (i *notifyServer) SendPersonStatusBySocket(status notify.Person) {
body := make(map[string]interface{})
body["data"] = status
msg := gosf.Message{}
msg.Body = body
msg.Success = true
msg.Text = "person_status"
notify := notify.Message{}
notify.Path = "person_status"
notify.Msg = msg
NotifyMsg <- notify
}
func (i *notifyServer) SendDiskInfoBySocket(disk model2.Summary) {
body := make(map[string]interface{})
body["data"] = disk