system.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package v1
  2. import (
  3. "fmt"
  4. "github.com/IceWhaleTech/CasaOS/model"
  5. "github.com/IceWhaleTech/CasaOS/pkg/config"
  6. "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
  7. "github.com/IceWhaleTech/CasaOS/pkg/utils/version"
  8. "github.com/IceWhaleTech/CasaOS/service"
  9. model2 "github.com/IceWhaleTech/CasaOS/service/model"
  10. "github.com/IceWhaleTech/CasaOS/types"
  11. "github.com/gin-gonic/gin"
  12. "net/http"
  13. "strconv"
  14. "time"
  15. )
  16. // @Summary 系统信息
  17. // @Produce application/json
  18. // @Accept application/json
  19. // @Tags sys
  20. // @Security ApiKeyAuth
  21. // @Success 200 {string} string "ok"
  22. // @Router /sys/chackversion [get]
  23. func CheckVersion(c *gin.Context) {
  24. need, version := version.IsNeedUpdate()
  25. if need {
  26. installLog := model2.AppNotify{}
  27. installLog.CustomId = ""
  28. installLog.State = 0
  29. installLog.Message = "New version " + version.Version + " is ready, ready to upgrade"
  30. installLog.Speed = 100
  31. installLog.Type = types.NOTIFY_TYPE_NEED_CONFIRM
  32. installLog.CreatedAt = strconv.FormatInt(time.Now().Unix(), 10)
  33. installLog.UpdatedAt = strconv.FormatInt(time.Now().Unix(), 10)
  34. service.MyService.Notify().AddLog(installLog)
  35. }
  36. data := make(map[string]interface{}, 1)
  37. data["is_need"] = need
  38. data["version"] = version
  39. data["current_version"] = types.CURRENTVERSION
  40. c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: data})
  41. return
  42. }
  43. // @Summary 系统信息
  44. // @Produce application/json
  45. // @Accept application/json
  46. // @Tags sys
  47. // @Security ApiKeyAuth
  48. // @Success 200 {string} string "ok"
  49. // @Router /sys/update [post]
  50. func SystemUpdate(c *gin.Context) {
  51. fmt.Println("开始更新")
  52. need, version := version.IsNeedUpdate()
  53. if need {
  54. fmt.Println("进入更新")
  55. service.MyService.System().UpdateSystemVersion(version.Version)
  56. }
  57. c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
  58. }
  59. //系统配置
  60. func GetSystemConfig(c *gin.Context) {
  61. c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: config.SystemConfigInfo})
  62. }
  63. // @Summary 修改配置文件
  64. // @Produce application/json
  65. // @Accept multipart/form-data
  66. // @Tags user
  67. // @Param file formData file true "用户头像"
  68. // @Security ApiKeyAuth
  69. // @Success 200 {string} string "ok"
  70. // @Router /user/changhead [post]
  71. func PostSetSystemConfig(c *gin.Context) {
  72. var systemConfig model.SystemConfig
  73. c.BindJSON(&systemConfig)
  74. service.MyService.System().UpSystemConfig(systemConfig)
  75. c.JSON(http.StatusOK,
  76. model.Result{
  77. Success: oasis_err.SUCCESS,
  78. Message: oasis_err.GetMsg(oasis_err.SUCCESS),
  79. Data: config.SystemConfigInfo,
  80. })
  81. return
  82. }
  83. //系统配置
  84. func GetSystemConfigDebug(c *gin.Context) {
  85. array := service.MyService.System().GetSystemConfigDebug()
  86. disk := service.MyService.ZiMa().GetDiskInfo()
  87. array = append(array, fmt.Sprintf("disk,totle:%v,used:%v,UsedPercent:%v", disk.Total>>20, disk.Used>>20, disk.UsedPercent))
  88. c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: array})
  89. }
  90. func Sys(c *gin.Context) {
  91. service.DockerPull()
  92. }