Skip to content

Commit

Permalink
feat: Multiple updates
Browse files Browse the repository at this point in the history
1.Add the function of modifying the WebUI port.
2.Add the function to modify the search engine.
3.Add the multi-language function and add Chinese translation.
4.Add detailed CPU and memory statistics.
  • Loading branch information
LinkLeong committed Dec 9, 2021
1 parent 997d912 commit 6c235d3
Show file tree
Hide file tree
Showing 28 changed files with 633 additions and 302 deletions.
5 changes: 3 additions & 2 deletions middleware/gin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ package middleware

import (
"fmt"
"github.com/gin-gonic/gin"
"net/http"

"github.com/gin-gonic/gin"
)

func Cors() gin.HandlerFunc {
Expand All @@ -17,7 +18,7 @@ func Cors() gin.HandlerFunc {
//服务器支持的所有跨域请求的方法
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE,UPDATE")
//允许跨域设置可以返回其他子段,可以自定义字段
c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session")
c.Header("Access-Control-Allow-Headers", "Authorization, Content-Length, X-CSRF-Token, Token,session,Language")
// 允许浏览器(客户端)可以解析的头部 (重要)
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers")
//设置缓存时间
Expand Down
1 change: 1 addition & 0 deletions model/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ type LSBLKModel struct {
Tran string `json:"tran"`
MinIO uint64 `json:"min-io"`
UsedPercent float64 `json:"used_percent"`
Serial string `json:"serial"`
Children []LSBLKModel `json:"children"`
//详情特有
StartSector uint64 `json:"start_sector,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions model/docker.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package model

type DockerStatsModel struct {
Icon string `json:"icon"`
Title string `json:"title"`
Data interface{} `json:"data"`
Pre interface{} `json:"pre"`
}
4 changes: 4 additions & 0 deletions model/sys_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,7 @@ type SystemConfig struct {
SyncPort string `json:"sync_port"`
SyncKey string `json:"sync_key"`
}

type CasaOSGlobalVariables struct {
AddApp bool
}
2 changes: 2 additions & 0 deletions pkg/config/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ var ServerInfo = &model.ServerModel{}

var SystemConfigInfo = &model.SystemConfig{}

var CasaOSGlobalVariables = &model.CasaOSGlobalVariables{}

var Cfg *ini.File

//初始化设置,获取系统的部分信息。
Expand Down
9 changes: 9 additions & 0 deletions route/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/IceWhaleTech/CasaOS/model/system_app"
"github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/docker"
"github.com/IceWhaleTech/CasaOS/pkg/utils/command"
"github.com/IceWhaleTech/CasaOS/pkg/utils/env_helper"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
"github.com/IceWhaleTech/CasaOS/pkg/utils/port"
Expand All @@ -20,6 +21,7 @@ import (

func InitFunction() {
go checkSystemApp()
Update2_3()
}

var syncIsExistence = false
Expand Down Expand Up @@ -190,3 +192,10 @@ func checkSystemApp() {
installSyncthing("44")
}
}
func CheckSerialDiskMount() {
// 检查挂载点重新挂载
// 检查新硬盘是否有多个分区,如有多个分区需提示
}
func Update2_3() {
command.OnlyExec("source " + config.AppInfo.ProjectPath + "/shell/assist.sh")
}
9 changes: 8 additions & 1 deletion route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func InitRouter() *gin.Engine {
v1SysGroup.POST("/config", v1.PostSetSystemConfig)
v1SysGroup.GET("/widget/config", v1.GetWidgetConfig)
v1SysGroup.POST("/widget/config", v1.PostSetWidgetConfig)
v1SysGroup.GET("/port", v1.GetCasaOSPort)
v1SysGroup.PUT("/port", v1.PutCasaOSPort)
v1SysGroup.POST("/kill", v1.PostKillCasaOS)
}
Expand Down Expand Up @@ -225,14 +226,20 @@ func InitRouter() *gin.Engine {
v1DiskGroup.POST("/format", v1.FormatDisk)

//添加分区
v1DiskGroup.POST("/addpart", v1.AddPartition)
v1DiskGroup.POST("/part", v1.AddPartition)

//获取可以格式化的内容
v1DiskGroup.GET("/type", v1.FormatDiskType)

//删除分区
v1DiskGroup.DELETE("/delpart", v1.RemovePartition)

//mount SATA disk
v1DiskGroup.POST("/mount", v1.PostMountDisk)

//umount SATA disk
v1DiskGroup.POST("/umount", v1.DeleteUmountDisk)

}
v1ShareGroup := v1Group.Group("/share")
v1ShareGroup.Use()
Expand Down
41 changes: 26 additions & 15 deletions route/v1/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package v1

import (
"net/http"
"strconv"

"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
Expand Down Expand Up @@ -110,15 +109,9 @@ func FormatDisk(c *gin.Context) {
if len(path) == 0 || len(t) == 0 {
c.JSON(http.StatusOK, model.Result{Success: oasis_err.INVALID_PARAMS, Message: oasis_err.GetMsg(oasis_err.INVALID_PARAMS)})
}

//删除挂载点
service.MyService.Disk().UmountPointAndRemoveDir(path)

//格式化磁盘
service.MyService.Disk().FormatDisk(path, t)

//重新挂载

c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
}

Expand Down Expand Up @@ -155,25 +148,43 @@ func RemovePartition(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
}

// @Summary 添加分区
// @Summary serial number
// @Produce application/json
// @Accept multipart/form-data
// @Tags disk
// @Security ApiKeyAuth
// @Param path formData string true "磁盘路径 例如/dev/sda"
// @Param size formData string true "需要分区容量大小(MB)"
// @Param num formData string true "磁盘符号"
// @Param serial formData string true "serial"
// @Success 200 {string} string "ok"
// @Router /disk/addpart [post]
func AddPartition(c *gin.Context) {
path := c.PostForm("path")
size, _ := strconv.Atoi(c.DefaultPostForm("size", "0"))
num := c.DefaultPostForm("num", "9")
if len(path) == 0 {
serial := c.PostForm("serial")
if len(path) == 0 || len(serial) == 0 {
c.JSON(http.StatusOK, model.Result{Success: oasis_err.INVALID_PARAMS, Message: oasis_err.GetMsg(oasis_err.INVALID_PARAMS)})
return
}
service.MyService.Disk().AddPartition(path)
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
}

func PostMountDisk(c *gin.Context) {
// for example: path=/dev/sda1
path := c.PostForm("path")
//执行挂载目录
service.MyService.Disk().MountDisk(path, "volume")
//添加到数据库

c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
}

func DeleteUmountDisk(c *gin.Context) {

// for example: path=/dev/sda1
path := c.PostForm("path")
service.MyService.Disk().UmountPointAndRemoveDir(path)

//删除数据库记录

//size*1024*1024/512
service.MyService.Disk().AddPartition(path, num, uint64(size*1024*2))
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS)})
}
9 changes: 7 additions & 2 deletions route/v1/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"time"

"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/docker"
upnp2 "github.com/IceWhaleTech/CasaOS/pkg/upnp"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
Expand Down Expand Up @@ -420,9 +421,12 @@ func InstallApp(c *gin.Context) {
rely := model.MapStrings{}

copier.Copy(&rely, &relyMap)
for i := 0; i < len(m.Volumes); i++ {
m.Volumes[i].Path = docker.GetDir(id, m.Volumes[i].ContainerPath)
if m.Origin != "custom" {
for i := 0; i < len(m.Volumes); i++ {
m.Volumes[i].Path = docker.GetDir(id, m.Volumes[i].ContainerPath)
}
}

portsStr, _ := json2.Marshal(m.Ports)
envsStr, _ := json2.Marshal(m.Envs)
volumesStr, _ := json2.Marshal(m.Volumes)
Expand Down Expand Up @@ -462,6 +466,7 @@ func InstallApp(c *gin.Context) {
// m.PortMap = m.Port
//}
service.MyService.App().SaveContainer(md)
config.CasaOSGlobalVariables.AddApp = true

}()

Expand Down
20 changes: 18 additions & 2 deletions route/v1/system.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,30 @@ func PostSetWidgetConfig(c *gin.Context) {
})
}

// @Summary get casaos server port
// @Produce application/json
// @Accept application/json
// @Tags sys
// @Security ApiKeyAuth
// @Success 200 {string} string "ok"
// @Router /sys/port [get]
func GetCasaOSPort(c *gin.Context) {
c.JSON(http.StatusOK,
model.Result{
Success: oasis_err.SUCCESS,
Message: oasis_err.GetMsg(oasis_err.SUCCESS),
Data: config.ServerInfo.HttpPort,
})
}

// @Summary edit casaos server port
// @Produce application/json
// @Accept application/json
// @Tags sys
// @Security ApiKeyAuth
// @Param port formData file true "用户头像"
// @Param port formData string true "port"
// @Success 200 {string} string "ok"
// @Router /sys/widget/config [post]
// @Router /sys/port [put]
func PutCasaOSPort(c *gin.Context) {
port, err := strconv.Atoi(c.PostForm("port"))
if err != nil {
Expand Down
Loading

0 comments on commit 6c235d3

Please sign in to comment.