Skip to content

Commit

Permalink
add widget
Browse files Browse the repository at this point in the history
Add CPU RAM Status
Add Disk Info
  • Loading branch information
LinkLeong committed Oct 15, 2021
1 parent 5f5091f commit fb15695
Show file tree
Hide file tree
Showing 45 changed files with 6,749 additions and 119 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/casa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
go_version: ${{ matrix.go_version }}
dest: build
prefix: casa
targets: linux/amd64,linux/arm64
targets: linux/amd64,linux/arm64,linux/arm-7
v: true
x: false
race: false
Expand Down Expand Up @@ -125,6 +125,7 @@ jobs:
files: >
linux-amd64-casaos.tar.gz
linux-arm64-casaos.tar.gz
linux-arm-7-casaos.tar.gz
tag: v${{ env.VERSION }}
body: >
${{ env.BODY }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

# IntelliJ project files
.idea
.vscode
*.iml
out
gen
Expand Down
Binary file added __debug_bin
Binary file not shown.
11 changes: 2 additions & 9 deletions conf/conf.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ MaxActive = 30
IdleTimeout = 200

[system]
AutoUpdate = true
SearchSwitch = true
WidgetsSwitch = false
ShortcutsSwitch = true
SearchEngine = google
Background = http://google.com
BackgroundType = 1


ConfigStr =
WidgetList =

16 changes: 13 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ require (
github.com/PuerkitoBio/goquery v1.7.0
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
github.com/aquasecurity/libbpfgo v0.2.1-libbpf-0.4.0 // indirect
github.com/bits-and-blooms/bitset v1.2.1 // indirect
github.com/containerd/containerd v1.5.5
github.com/containerd/containerd v1.5.7
github.com/containerd/continuity v0.2.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/docker/docker v20.10.7+incompatible
github.com/docker/go-connections v0.4.0
github.com/forease/gotld v0.0.0-20190808124948-c50ff635576b
github.com/gin-contrib/gzip v0.0.2 // indirect
github.com/gin-gonic/gin v1.7.2
github.com/go-delve/delve v1.7.2 // indirect
github.com/go-ini/ini v1.62.0
github.com/go-ole/go-ole v1.2.5 // indirect
github.com/go-openapi/jsonreference v0.19.6 // indirect
Expand All @@ -26,6 +29,7 @@ require (
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/gomodule/redigo v1.8.5
github.com/google/go-dap v0.6.0 // indirect
github.com/google/go-github/v36 v36.0.0
github.com/google/uuid v1.3.0 // indirect
github.com/gorilla/mux v1.8.0 // indirect
Expand All @@ -35,11 +39,13 @@ require (
github.com/klauspost/compress v1.13.6 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect
github.com/mattn/go-colorable v0.1.11 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
github.com/morikuni/aec v1.0.0 // indirect
github.com/opencontainers/runc v1.0.2 // indirect
github.com/opencontainers/selinux v1.8.5 // indirect
github.com/peterh/liner v1.2.1 // indirect
github.com/pkg/errors v0.9.1
github.com/prestonTao/upnp v0.0.0-20150206124352-f4370df5e109
github.com/prometheus/procfs v0.7.3 // indirect
Expand All @@ -49,18 +55,21 @@ require (
github.com/sirupsen/logrus v1.8.1
github.com/smartystreets/assertions v1.2.0 // indirect
github.com/smartystreets/goconvey v1.6.4 // indirect
github.com/spf13/cobra v1.2.1 // indirect
github.com/swaggo/gin-swagger v1.3.0
github.com/swaggo/swag v1.7.0
github.com/tidwall/gjson v1.8.0
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tklauser/go-sysconf v0.3.6 // indirect
github.com/ugorji/go v1.2.6 // indirect
go.opencensus.io v0.23.0 // indirect
go.starlark.net v0.0.0-20210901212718-87f333178d59 // indirect
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
golang.org/x/mod v0.5.0 // indirect
golang.org/x/net v0.0.0-20210924151903-3ad01bbaa167 // indirect
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f
golang.org/x/sys v0.0.0-20210927052749-1cf2251ac284 // indirect
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
Expand All @@ -73,4 +82,5 @@ require (
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gorm.io/driver/sqlite v1.1.5
gorm.io/gorm v1.21.15
src.techknowlogick.com/xgo v1.4.1-0.20211007230901-4fb1c2d7b2ab // indirect
)
184 changes: 184 additions & 0 deletions go.sum

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package main
import (
"flag"
"fmt"
"net/http"
"time"

"github.com/IceWhaleTech/CasaOS/pkg/config"
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
Expand All @@ -11,8 +14,6 @@ import (
"github.com/gin-gonic/gin"
"github.com/robfig/cron"
"gorm.io/gorm"
"net/http"
"time"
)

var sqliteDB *gorm.DB
Expand All @@ -23,6 +24,7 @@ var configFlag = flag.String("c", "", "config address")
func init() {
flag.Parse()
config.InitSetup(*configFlag)
config.UpdateSetup()
loger2.LogSetup()
sqliteDB = sqlite.GetDb(config.AppInfo.ProjectPath)
//gredis.GetRedisConn(config.RedisInfo),
Expand Down
7 changes: 7 additions & 0 deletions model/search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package model

type SearchFileInfo struct {
Path string `json:"path"`
Name string `json:"name"`
Type int `json:"type"`
}
9 changes: 2 additions & 7 deletions model/sys_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ type RedisModel struct {
}

type SystemConfig struct {
SearchSwitch bool `json:"search_switch"` //搜索开关
SearchEngine string `json:"search_engine"` //搜索引擎
ShortcutsSwitch bool `json:"shortcuts_switch"`
WidgetsSwitch bool `json:"widgets_switch"`
BackgroundType string `json:"background_type"`
Background string `json:"background"`
AutoUpdate bool `json:"auto_update"`
ConfigStr string `json:"config_str"`
WidgetList string `json:"widget_list"`
}
5 changes: 3 additions & 2 deletions model/zima.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package model

type Path struct {
Name string `json:"name"`
Path string `json:"path"`
Name string `json:"name"`
Path string `json:"path"`
IsDir bool `json:"is_dir"`
}
15 changes: 15 additions & 0 deletions pkg/config/update.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package config

import "github.com/IceWhaleTech/CasaOS/pkg/utils/file"

//检查目录是否存在
func mkdirDATAAll() {
dirArray := [7]string{"/DATA/AppData", "/DATA/Documents", "/DATA/Downloads", "/DATA/Gallery", "/DATA/Media/Movies", "/DATA/Media/TV Shows", "/DATA/Media/Music"}
for _, v := range dirArray {
file.IsNotExistMkDir(v)
}
}

func UpdateSetup() {
mkdirDATAAll()
}
7 changes: 0 additions & 7 deletions pkg/github/github_test.go

This file was deleted.

5 changes: 3 additions & 2 deletions pkg/gredis/redis.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package gredis

import (
"github.com/gomodule/redigo/redis"
"oasis/model"
"time"

"github.com/IceWhaleTech/CasaOS/model"
"github.com/gomodule/redigo/redis"
)

func GetRedisConn(m *model.RedisModel) *redis.Pool {
Expand Down
3 changes: 2 additions & 1 deletion pkg/upnp/device_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package upnp

import (
ip_helper2 "oasis/pkg/utils/ip_helper"
"testing"

ip_helper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/ip_helper"
)

func TestGetCtrlUrl(t *testing.T) {
Expand Down
23 changes: 21 additions & 2 deletions pkg/utils/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ func MustOpen(fileName, filePath string) (*os.File, error) {
return f, nil
}


// 判断所给路径文件/文件夹是否存在
func Exists(path string) bool {
_, err := os.Stat(path) //os.Stat获取文件信息
_, err := os.Stat(path) //os.Stat获取文件信息
if err != nil {
if os.IsExist(err) {
return true
Expand All @@ -126,3 +125,23 @@ func IsDir(path string) bool {
func IsFile(path string) bool {
return !IsDir(path)
}

func CreateFile(path string) error {
file, err := os.Create(path)
if err != nil {
return err
}
defer file.Close()
return nil
}

// IsNotExistMkDir create a directory if it does not exist
func IsNotExistCreateFile(src string) error {
if notExist := CheckNotExist(src); notExist == true {
if err := CreateFile(src); err != nil {
return err
}
}

return nil
}
6 changes: 3 additions & 3 deletions pkg/utils/jwt/jwt.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package jwt

import (
jwt "github.com/golang-jwt/jwt"
"time"

jwt "github.com/golang-jwt/jwt"
)

type Claims struct {
Expand All @@ -15,8 +16,7 @@ var jwtSecret []byte

//创建token
func GenerateToken(username, password string) (string, error) {
nowTime := time.Now()
expireTime := nowTime.Add(3 * time.Hour)
expireTime := time.Now().AddDate(999, 0, 0)
clims := Claims{
username,
password,
Expand Down
11 changes: 10 additions & 1 deletion route/route.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package route

import (
"net/http"

"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"
"github.com/gin-gonic/gin"
"net/http"
)

var swagHandler gin.HandlerFunc
Expand Down Expand Up @@ -183,6 +184,8 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
v1SysGroup.GET("/wsssh", v1.WsSsh)
v1SysGroup.GET("/config", v1.GetSystemConfig)
v1SysGroup.POST("/config", v1.PostSetSystemConfig)
v1SysGroup.GET("/widget/config", v1.GetWidgetConfig)
v1SysGroup.POST("/widget/config", v1.PostSetWidgetConfig)
}
v1FileGroup := v1Group.Group("/file")
v1FileGroup.Use()
Expand All @@ -194,6 +197,7 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
v1FileGroup.GET("/dirpath", v1.DirPath)
//创建目录
v1FileGroup.POST("/mkdir", v1.MkdirAll)
v1FileGroup.POST("/create", v1.PostCreateFile)

v1FileGroup.GET("/download", v1.GetDownloadFile)
//v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
Expand Down Expand Up @@ -252,6 +256,11 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
v1NotifyGroup.GET("/ws", v1.NotifyWS)
v1NotifyGroup.PUT("/read/:id", v1.PutNotifyRead)
}
v1SearchGroup := v1Group.Group("/search")
v1SearchGroup.Use()
{
v1SearchGroup.GET("/search", v1.GetSearchList)
}
}
return r
}
30 changes: 25 additions & 5 deletions route/v1/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ import (
"bufio"
"encoding/csv"
"fmt"
"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
"github.com/IceWhaleTech/CasaOS/service"
"github.com/gin-gonic/gin"
"io"
"io/ioutil"
"net/http"
"os"
"path"

"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
"github.com/IceWhaleTech/CasaOS/service"
"github.com/gin-gonic/gin"
)

func downloadReadFile(c *gin.Context) {
Expand Down Expand Up @@ -218,6 +219,25 @@ func MkdirAll(c *gin.Context) {
c.JSON(http.StatusOK, model.Result{Success: code, Message: oasis_err2.GetMsg(code)})
}

// @Summary 创建文件
// @Produce application/json
// @Accept multipart/form-data
// @Tags file
// @Security ApiKeyAuth
// @Param path formData string false "路径"
// @Success 200 {string} string "ok"
// @Router /file/create [post]
func PostCreateFile(c *gin.Context) {
path := c.PostForm("path")
var code int
if len(path) == 0 {
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
return
}
code, _ = service.MyService.ZiMa().CreateFile(path)
c.JSON(http.StatusOK, model.Result{Success: code, Message: oasis_err2.GetMsg(code)})
}

// @Summary 上传文件
// @Produce application/json
// @Accept multipart/form-data
Expand Down
22 changes: 22 additions & 0 deletions route/v1/search.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package v1

import (
"net/http"

"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
"github.com/IceWhaleTech/CasaOS/service"
"github.com/gin-gonic/gin"
)

func GetSearchList(c *gin.Context) {
key := c.DefaultQuery("key", "")
if len(key) == 0 {
return
}
list, err := service.MyService.Search().SearchList(key)
if err != nil {

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

0 comments on commit fb15695

Please sign in to comment.