Skip to content

Commit 53157fb

Browse files
authored
Merge pull request #1 from IceWhaleTech/v0.2.1
add widget
2 parents 5f5091f + fb15695 commit 53157fb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+6749
-119
lines changed

.github/workflows/casa.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ jobs:
9494
go_version: ${{ matrix.go_version }}
9595
dest: build
9696
prefix: casa
97-
targets: linux/amd64,linux/arm64
97+
targets: linux/amd64,linux/arm64,linux/arm-7
9898
v: true
9999
x: false
100100
race: false
@@ -125,6 +125,7 @@ jobs:
125125
files: >
126126
linux-amd64-casaos.tar.gz
127127
linux-arm64-casaos.tar.gz
128+
linux-arm-7-casaos.tar.gz
128129
tag: v${{ env.VERSION }}
129130
body: >
130131
${{ env.BODY }}

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
# IntelliJ project files
2222
.idea
23+
.vscode
2324
*.iml
2425
out
2526
gen

__debug_bin

42.5 MB
Binary file not shown.

conf/conf.ini.sample

+2-9
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,6 @@ MaxActive = 30
3636
IdleTimeout = 200
3737

3838
[system]
39-
AutoUpdate = true
40-
SearchSwitch = true
41-
WidgetsSwitch = false
42-
ShortcutsSwitch = true
43-
SearchEngine = google
44-
Background = http://google.com
45-
BackgroundType = 1
46-
47-
39+
ConfigStr =
40+
WidgetList =
4841

go.mod

+13-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,17 @@ require (
88
github.com/PuerkitoBio/goquery v1.7.0
99
github.com/StackExchange/wmi v0.0.0-20210224194228-fe8f1750fd46 // indirect
1010
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751
11+
github.com/aquasecurity/libbpfgo v0.2.1-libbpf-0.4.0 // indirect
1112
github.com/bits-and-blooms/bitset v1.2.1 // indirect
12-
github.com/containerd/containerd v1.5.5
13+
github.com/containerd/containerd v1.5.7
1314
github.com/containerd/continuity v0.2.0 // indirect
15+
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
1416
github.com/docker/docker v20.10.7+incompatible
1517
github.com/docker/go-connections v0.4.0
1618
github.com/forease/gotld v0.0.0-20190808124948-c50ff635576b
1719
github.com/gin-contrib/gzip v0.0.2 // indirect
1820
github.com/gin-gonic/gin v1.7.2
21+
github.com/go-delve/delve v1.7.2 // indirect
1922
github.com/go-ini/ini v1.62.0
2023
github.com/go-ole/go-ole v1.2.5 // indirect
2124
github.com/go-openapi/jsonreference v0.19.6 // indirect
@@ -26,6 +29,7 @@ require (
2629
github.com/golang-jwt/jwt v3.2.2+incompatible
2730
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
2831
github.com/gomodule/redigo v1.8.5
32+
github.com/google/go-dap v0.6.0 // indirect
2933
github.com/google/go-github/v36 v36.0.0
3034
github.com/google/uuid v1.3.0 // indirect
3135
github.com/gorilla/mux v1.8.0 // indirect
@@ -35,11 +39,13 @@ require (
3539
github.com/klauspost/compress v1.13.6 // indirect
3640
github.com/leodido/go-urn v1.2.1 // indirect
3741
github.com/mailru/easyjson v0.7.7 // indirect
38-
github.com/mattn/go-isatty v0.0.13 // indirect
42+
github.com/mattn/go-colorable v0.1.11 // indirect
43+
github.com/mattn/go-runewidth v0.0.13 // indirect
3944
github.com/moby/term v0.0.0-20210619224110-3f7ff695adc6 // indirect
4045
github.com/morikuni/aec v1.0.0 // indirect
4146
github.com/opencontainers/runc v1.0.2 // indirect
4247
github.com/opencontainers/selinux v1.8.5 // indirect
48+
github.com/peterh/liner v1.2.1 // indirect
4349
github.com/pkg/errors v0.9.1
4450
github.com/prestonTao/upnp v0.0.0-20150206124352-f4370df5e109
4551
github.com/prometheus/procfs v0.7.3 // indirect
@@ -49,18 +55,21 @@ require (
4955
github.com/sirupsen/logrus v1.8.1
5056
github.com/smartystreets/assertions v1.2.0 // indirect
5157
github.com/smartystreets/goconvey v1.6.4 // indirect
58+
github.com/spf13/cobra v1.2.1 // indirect
5259
github.com/swaggo/gin-swagger v1.3.0
5360
github.com/swaggo/swag v1.7.0
5461
github.com/tidwall/gjson v1.8.0
5562
github.com/tidwall/pretty v1.2.0 // indirect
5663
github.com/tklauser/go-sysconf v0.3.6 // indirect
5764
github.com/ugorji/go v1.2.6 // indirect
5865
go.opencensus.io v0.23.0 // indirect
66+
go.starlark.net v0.0.0-20210901212718-87f333178d59 // indirect
67+
golang.org/x/arch v0.0.0-20210923205945-b76863e36670 // indirect
5968
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5
6069
golang.org/x/mod v0.5.0 // indirect
6170
golang.org/x/net v0.0.0-20210924151903-3ad01bbaa167 // indirect
6271
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f
63-
golang.org/x/sys v0.0.0-20210927052749-1cf2251ac284 // indirect
72+
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
6473
golang.org/x/term v0.0.0-20210615171337-6886f2dfbf5b // indirect
6574
golang.org/x/text v0.3.7 // indirect
6675
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac // indirect
@@ -73,4 +82,5 @@ require (
7382
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
7483
gorm.io/driver/sqlite v1.1.5
7584
gorm.io/gorm v1.21.15
85+
src.techknowlogick.com/xgo v1.4.1-0.20211007230901-4fb1c2d7b2ab // indirect
7686
)

go.sum

+184
Large diffs are not rendered by default.

main.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@ package main
33
import (
44
"flag"
55
"fmt"
6+
"net/http"
7+
"time"
8+
69
"github.com/IceWhaleTech/CasaOS/pkg/config"
710
"github.com/IceWhaleTech/CasaOS/pkg/sqlite"
811
loger2 "github.com/IceWhaleTech/CasaOS/pkg/utils/loger"
@@ -11,8 +14,6 @@ import (
1114
"github.com/gin-gonic/gin"
1215
"github.com/robfig/cron"
1316
"gorm.io/gorm"
14-
"net/http"
15-
"time"
1617
)
1718

1819
var sqliteDB *gorm.DB
@@ -23,6 +24,7 @@ var configFlag = flag.String("c", "", "config address")
2324
func init() {
2425
flag.Parse()
2526
config.InitSetup(*configFlag)
27+
config.UpdateSetup()
2628
loger2.LogSetup()
2729
sqliteDB = sqlite.GetDb(config.AppInfo.ProjectPath)
2830
//gredis.GetRedisConn(config.RedisInfo),

model/search.go

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package model
2+
3+
type SearchFileInfo struct {
4+
Path string `json:"path"`
5+
Name string `json:"name"`
6+
Type int `json:"type"`
7+
}

model/sys_common.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,6 @@ type RedisModel struct {
6060
}
6161

6262
type SystemConfig struct {
63-
SearchSwitch bool `json:"search_switch"` //搜索开关
64-
SearchEngine string `json:"search_engine"` //搜索引擎
65-
ShortcutsSwitch bool `json:"shortcuts_switch"`
66-
WidgetsSwitch bool `json:"widgets_switch"`
67-
BackgroundType string `json:"background_type"`
68-
Background string `json:"background"`
69-
AutoUpdate bool `json:"auto_update"`
63+
ConfigStr string `json:"config_str"`
64+
WidgetList string `json:"widget_list"`
7065
}

model/zima.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package model
22

33
type Path struct {
4-
Name string `json:"name"`
5-
Path string `json:"path"`
4+
Name string `json:"name"`
5+
Path string `json:"path"`
6+
IsDir bool `json:"is_dir"`
67
}

pkg/config/update.go

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package config
2+
3+
import "github.com/IceWhaleTech/CasaOS/pkg/utils/file"
4+
5+
//检查目录是否存在
6+
func mkdirDATAAll() {
7+
dirArray := [7]string{"/DATA/AppData", "/DATA/Documents", "/DATA/Downloads", "/DATA/Gallery", "/DATA/Media/Movies", "/DATA/Media/TV Shows", "/DATA/Media/Music"}
8+
for _, v := range dirArray {
9+
file.IsNotExistMkDir(v)
10+
}
11+
}
12+
13+
func UpdateSetup() {
14+
mkdirDATAAll()
15+
}

pkg/github/github_test.go

-7
This file was deleted.

pkg/gredis/redis.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package gredis
22

33
import (
4-
"github.com/gomodule/redigo/redis"
5-
"oasis/model"
64
"time"
5+
6+
"github.com/IceWhaleTech/CasaOS/model"
7+
"github.com/gomodule/redigo/redis"
78
)
89

910
func GetRedisConn(m *model.RedisModel) *redis.Pool {

pkg/upnp/device_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package upnp
22

33
import (
4-
ip_helper2 "oasis/pkg/utils/ip_helper"
54
"testing"
5+
6+
ip_helper2 "github.com/IceWhaleTech/CasaOS/pkg/utils/ip_helper"
67
)
78

89
func TestGetCtrlUrl(t *testing.T) {

pkg/utils/file/file.go

+21-2
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,9 @@ func MustOpen(fileName, filePath string) (*os.File, error) {
100100
return f, nil
101101
}
102102

103-
104103
// 判断所给路径文件/文件夹是否存在
105104
func Exists(path string) bool {
106-
_, err := os.Stat(path) //os.Stat获取文件信息
105+
_, err := os.Stat(path) //os.Stat获取文件信息
107106
if err != nil {
108107
if os.IsExist(err) {
109108
return true
@@ -126,3 +125,23 @@ func IsDir(path string) bool {
126125
func IsFile(path string) bool {
127126
return !IsDir(path)
128127
}
128+
129+
func CreateFile(path string) error {
130+
file, err := os.Create(path)
131+
if err != nil {
132+
return err
133+
}
134+
defer file.Close()
135+
return nil
136+
}
137+
138+
// IsNotExistMkDir create a directory if it does not exist
139+
func IsNotExistCreateFile(src string) error {
140+
if notExist := CheckNotExist(src); notExist == true {
141+
if err := CreateFile(src); err != nil {
142+
return err
143+
}
144+
}
145+
146+
return nil
147+
}

pkg/utils/jwt/jwt.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package jwt
22

33
import (
4-
jwt "github.com/golang-jwt/jwt"
54
"time"
5+
6+
jwt "github.com/golang-jwt/jwt"
67
)
78

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

1617
//创建token
1718
func GenerateToken(username, password string) (string, error) {
18-
nowTime := time.Now()
19-
expireTime := nowTime.Add(3 * time.Hour)
19+
expireTime := time.Now().AddDate(999, 0, 0)
2020
clims := Claims{
2121
username,
2222
password,

route/route.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package route
22

33
import (
4+
"net/http"
5+
46
"github.com/IceWhaleTech/CasaOS/middleware"
57
"github.com/IceWhaleTech/CasaOS/pkg/config"
68
jwt2 "github.com/IceWhaleTech/CasaOS/pkg/utils/jwt"
79
v1 "github.com/IceWhaleTech/CasaOS/route/v1"
810
"github.com/IceWhaleTech/CasaOS/web"
911
"github.com/gin-gonic/gin"
10-
"net/http"
1112
)
1213

1314
var swagHandler gin.HandlerFunc
@@ -183,6 +184,8 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
183184
v1SysGroup.GET("/wsssh", v1.WsSsh)
184185
v1SysGroup.GET("/config", v1.GetSystemConfig)
185186
v1SysGroup.POST("/config", v1.PostSetSystemConfig)
187+
v1SysGroup.GET("/widget/config", v1.GetWidgetConfig)
188+
v1SysGroup.POST("/widget/config", v1.PostSetWidgetConfig)
186189
}
187190
v1FileGroup := v1Group.Group("/file")
188191
v1FileGroup.Use()
@@ -194,6 +197,7 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
194197
v1FileGroup.GET("/dirpath", v1.DirPath)
195198
//创建目录
196199
v1FileGroup.POST("/mkdir", v1.MkdirAll)
200+
v1FileGroup.POST("/create", v1.PostCreateFile)
197201

198202
v1FileGroup.GET("/download", v1.GetDownloadFile)
199203
//v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
@@ -252,6 +256,11 @@ func InitRouter(swagHandler gin.HandlerFunc) *gin.Engine {
252256
v1NotifyGroup.GET("/ws", v1.NotifyWS)
253257
v1NotifyGroup.PUT("/read/:id", v1.PutNotifyRead)
254258
}
259+
v1SearchGroup := v1Group.Group("/search")
260+
v1SearchGroup.Use()
261+
{
262+
v1SearchGroup.GET("/search", v1.GetSearchList)
263+
}
255264
}
256265
return r
257266
}

route/v1/file.go

+25-5
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,17 @@ import (
44
"bufio"
55
"encoding/csv"
66
"fmt"
7-
"github.com/IceWhaleTech/CasaOS/model"
8-
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
9-
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
10-
"github.com/IceWhaleTech/CasaOS/service"
11-
"github.com/gin-gonic/gin"
127
"io"
138
"io/ioutil"
149
"net/http"
1510
"os"
1611
"path"
12+
13+
"github.com/IceWhaleTech/CasaOS/model"
14+
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
15+
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
16+
"github.com/IceWhaleTech/CasaOS/service"
17+
"github.com/gin-gonic/gin"
1718
)
1819

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

222+
// @Summary 创建文件
223+
// @Produce application/json
224+
// @Accept multipart/form-data
225+
// @Tags file
226+
// @Security ApiKeyAuth
227+
// @Param path formData string false "路径"
228+
// @Success 200 {string} string "ok"
229+
// @Router /file/create [post]
230+
func PostCreateFile(c *gin.Context) {
231+
path := c.PostForm("path")
232+
var code int
233+
if len(path) == 0 {
234+
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
235+
return
236+
}
237+
code, _ = service.MyService.ZiMa().CreateFile(path)
238+
c.JSON(http.StatusOK, model.Result{Success: code, Message: oasis_err2.GetMsg(code)})
239+
}
240+
221241
// @Summary 上传文件
222242
// @Produce application/json
223243
// @Accept multipart/form-data

route/v1/search.go

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package v1
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/IceWhaleTech/CasaOS/model"
7+
"github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
8+
"github.com/IceWhaleTech/CasaOS/service"
9+
"github.com/gin-gonic/gin"
10+
)
11+
12+
func GetSearchList(c *gin.Context) {
13+
key := c.DefaultQuery("key", "")
14+
if len(key) == 0 {
15+
return
16+
}
17+
list, err := service.MyService.Search().SearchList(key)
18+
if err != nil {
19+
20+
}
21+
c.JSON(http.StatusOK, model.Result{Success: oasis_err.SUCCESS, Message: oasis_err.GetMsg(oasis_err.SUCCESS), Data: list})
22+
}

0 commit comments

Comments
 (0)