Skip to content

Commit 8df63c6

Browse files
authored
Merge pull request #60 from IceWhaleTech/dev
New App Store
2 parents bdcbae6 + 1d17d27 commit 8df63c6

25 files changed

+690
-228
lines changed

model/app.go

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type ServerAppList struct {
1515
Icon string `json:"icon"`
1616
ScreenshotLink Strings `gorm:"type:json" json:"screenshot_link"`
1717
Category string `json:"category"`
18+
CategoryFont string `json:"category_font"`
1819
PortMap string `json:"port_map"`
1920
ImageVersion string `json:"image_version"`
2021
Tip string `json:"tip"`
@@ -36,6 +37,8 @@ type ServerAppList struct {
3637
Healthy string `json:"healthy"`
3738
Plugins Strings `json:"plugins"`
3839
Origin string `json:"origin"`
40+
Type int `json:"type"`
41+
Developer string `json:"developer"`
3942
}
4043

4144
type Ports struct {

model/category.go

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type ServerCategoryList struct {
55
//CreatedAt time.Time `json:"created_at"`
66
//
77
//UpdatedAt time.Time `json:"updated_at"`
8+
Font string `json:"font"`
89
Name string `json:"name"`
910
Count uint `json:"count"`
1011
}

pkg/docker/volumes.go

+3-27
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,9 @@ package docker
33
import "strings"
44

55
func GetDir(id, envName string) string {
6-
var path string
76

8-
if len(id) == 0 {
9-
id = "$AppID"
7+
if strings.Contains(envName, "$AppID") && len(id) > 0 {
8+
return strings.ReplaceAll(envName, "$AppID", id)
109
}
11-
12-
switch {
13-
case strings.Contains(strings.ToLower(envName), "config") || strings.Contains(strings.ToLower(envName), "photoprism/storage") || strings.Contains(strings.ToLower(envName), "config"):
14-
path = "/DATA/AppData/" + id + "/"
15-
case strings.Contains(strings.ToLower(envName), "media"):
16-
path = "/DATA/Media/"
17-
case strings.Contains(strings.ToLower(envName), "movie"):
18-
path = "/DATA/Media/Movies/"
19-
case strings.Contains(strings.ToLower(envName), "music"):
20-
path = "/DATA/Media/Music/"
21-
case strings.Contains(strings.ToLower(envName), "photoprism/originals"):
22-
path = "/DATA/Gallery"
23-
case strings.Contains(strings.ToLower(envName), "download"):
24-
path = "/DATA/Downloads/"
25-
case strings.Contains(strings.ToLower(envName), "photo") || strings.Contains(strings.ToLower(envName), "pictures"):
26-
path = "/DATA/Downloads/"
27-
case strings.ToLower(envName) == "/srv":
28-
path = "/DATA/"
29-
case strings.ToLower(envName) == "/tv":
30-
path = "/DATA/Media/TV Shows"
31-
default:
32-
//path = "/media"
33-
}
34-
return path
10+
return envName
3511
}

pkg/sqlite/db.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ package sqlite
22

33
import (
44
"fmt"
5+
"time"
6+
57
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
68
model2 "github.com/IceWhaleTech/CasaOS/service/model"
79
"gorm.io/driver/sqlite"
810
"gorm.io/gorm"
9-
"time"
1011
)
1112

1213
var gdb *gorm.DB
@@ -30,7 +31,7 @@ func GetDb(projectPath string) *gorm.DB {
3031
return nil
3132
}
3233
gdb = db
33-
err = db.AutoMigrate(&model2.TaskDBModel{}, &model2.AppNotify{}, &model2.AppListDBModel{})
34+
err = db.AutoMigrate(&model2.TaskDBModel{}, &model2.AppNotify{}, &model2.AppListDBModel{}, &model2.SerialDisk{})
3435
if err != nil {
3536
fmt.Println("检查和创建数据库出错", err)
3637
}

pkg/utils/command/command_helper.go

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ func ExecResultStr(cmdStr string) string {
7575
func ExecLSBLK() []byte {
7676
output, err := exec.Command("lsblk", "-O", "-J", "-b").Output()
7777
if err != nil {
78+
fmt.Println("lsblk", err)
7879
return nil
7980
}
8081
return output

pkg/utils/env_helper/env.go

+9-2
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@ package env_helper
22

33
import "strings"
44

5-
func ReplaceDefaultENV(key string) string {
5+
func ReplaceDefaultENV(key, tz string) string {
66
temp := ""
77
switch key {
88
case "$DefaultPassword":
99
temp = "casaos"
1010
case "$DefaultUserName":
1111
temp = "admin"
12+
13+
case "$PUID":
14+
temp = "1000"
15+
case "$PGID":
16+
temp = "1000"
17+
case "$TZ":
18+
temp = tz
1219
}
1320
return temp
1421
}
1522

1623
//replace env default setting
1724
func ReplaceStringDefaultENV(str string) string {
18-
return strings.ReplaceAll(strings.ReplaceAll(str, "$DefaultPassword", ReplaceDefaultENV("$DefaultPassword")), "$DefaultUserName", ReplaceDefaultENV("$DefaultUserName"))
25+
return strings.ReplaceAll(strings.ReplaceAll(str, "$DefaultPassword", ReplaceDefaultENV("$DefaultPassword", "")), "$DefaultUserName", ReplaceDefaultENV("$DefaultUserName", ""))
1926
}

route/init.go

+25-7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
func InitFunction() {
2323
go checkSystemApp()
2424
Update2_3()
25+
CheckSerialDiskMount()
26+
2527
}
2628

2729
var syncIsExistence = false
@@ -72,9 +74,6 @@ func installSyncthing(appId string) {
7274
appInfo.Tip = env_helper.ReplaceStringDefaultENV(appInfo.Tip)
7375
}
7476

75-
for i := 0; i < len(appInfo.Volumes); i++ {
76-
appInfo.Volumes[i].Path = docker.GetDir("", appInfo.Volumes[i].ContainerPath)
77-
}
7877
appInfo.MaxMemory = service.MyService.ZiMa().GetMemInfo().Total >> 20
7978

8079
id := uuid.NewV4().String()
@@ -171,7 +170,7 @@ func checkSystemApp() {
171170
path := ""
172171
for _, i := range paths {
173172
if i.ContainerPath == "/config" {
174-
path = docker.GetDir(v.CustomId, i.ContainerPath) + "config.xml"
173+
path = docker.GetDir(v.CustomId, i.Path) + "config.xml"
175174
for i := 0; i < 10; i++ {
176175
if file.CheckNotExist(path) {
177176
time.Sleep(1 * time.Second)
@@ -189,12 +188,31 @@ func checkSystemApp() {
189188
}
190189
}
191190
if !syncIsExistence {
192-
installSyncthing("44")
191+
installSyncthing("74")
193192
}
194193
}
195194
func CheckSerialDiskMount() {
196-
// 检查挂载点重新挂载
197-
// 检查新硬盘是否有多个分区,如有多个分区需提示
195+
// check mount point
196+
dbList := service.MyService.Disk().GetSerialAll()
197+
198+
list := service.MyService.Disk().LSBLK()
199+
mountPoint := make(map[string]string, len(dbList))
200+
201+
for _, v := range list {
202+
if v.Children != nil {
203+
for _, h := range v.Children {
204+
mountPoint[h.MountPoint] = "1"
205+
}
206+
}
207+
}
208+
209+
//remount
210+
for _, item := range dbList {
211+
if _, ok := mountPoint[item.MountPoint]; !ok {
212+
service.MyService.Disk().MountDisk(item.Path, item.MountPoint)
213+
}
214+
}
215+
198216
}
199217
func Update2_3() {
200218
command.OnlyExec("source " + config.AppInfo.ProjectPath + "/shell/assist.sh")

route/route.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,7 @@ func InitRouter() *gin.Engine {
7070

7171
//获取网络信息
7272
v1ZiMaGroup.GET("/getnetinfo", v1.NetInfo)
73-
//获取网络信息
74-
v1ZiMaGroup.GET("/getinfo", v1.Info)
73+
7574
//获取系统信息
7675
v1ZiMaGroup.GET("/sysinfo", v1.SysInfo)
7776
}
@@ -197,6 +196,7 @@ func InitRouter() *gin.Engine {
197196
v1SysGroup.GET("/port", v1.GetCasaOSPort)
198197
v1SysGroup.PUT("/port", v1.PutCasaOSPort)
199198
v1SysGroup.POST("/kill", v1.PostKillCasaOS)
199+
v1SysGroup.GET("/info", v1.Info)
200200
}
201201
v1FileGroup := v1Group.Group("/file")
202202
v1FileGroup.Use()
@@ -211,11 +211,13 @@ func InitRouter() *gin.Engine {
211211
v1FileGroup.POST("/create", v1.PostCreateFile)
212212

213213
v1FileGroup.GET("/download", v1.GetDownloadFile)
214+
v1FileGroup.PUT("/move", v1.PutFileMove)
214215
//v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
215216
}
216217
v1DiskGroup := v1Group.Group("/disk")
217218
v1DiskGroup.Use()
218219
{
220+
v1DiskGroup.GET("/check", v1.GetDiskCheck)
219221
//获取磁盘列表
220222
v1DiskGroup.GET("/list", v1.GetPlugInDisk)
221223

@@ -238,8 +240,8 @@ func InitRouter() *gin.Engine {
238240
v1DiskGroup.POST("/mount", v1.PostMountDisk)
239241

240242
//umount SATA disk
241-
v1DiskGroup.POST("/umount", v1.DeleteUmountDisk)
242-
243+
v1DiskGroup.POST("/umount", v1.PostDiskUmount)
244+
v1DiskGroup.DELETE("/remove/:id", v1.DeleteDisk)
243245
}
244246
v1ShareGroup := v1Group.Group("/share")
245247
v1ShareGroup.Use()

route/v1/app.go

+29-14
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import (
77
"strconv"
88

99
"github.com/IceWhaleTech/CasaOS/model"
10-
"github.com/IceWhaleTech/CasaOS/pkg/docker"
11-
"github.com/IceWhaleTech/CasaOS/pkg/utils/env_helper"
1210
"github.com/IceWhaleTech/CasaOS/pkg/utils/file"
1311
oasis_err2 "github.com/IceWhaleTech/CasaOS/pkg/utils/oasis_err"
1412
port2 "github.com/IceWhaleTech/CasaOS/pkg/utils/port"
@@ -33,20 +31,33 @@ func AppList(c *gin.Context) {
3331
//service.MyService.Docker().DockerContainerCommit("test2")
3432

3533
index := c.DefaultQuery("index", "1")
36-
size := c.DefaultQuery("size", "10")
34+
size := c.DefaultQuery("size", "10000")
3735
t := c.DefaultQuery("type", "rank")
3836
categoryId := c.DefaultQuery("category_id", "0")
3937
key := c.DefaultQuery("key", "")
40-
list, count := service.MyService.OAPI().GetServerList(index, size, t, categoryId, key)
38+
recommend, list, community := service.MyService.OAPI().GetServerList(index, size, t, categoryId, key)
39+
for i := 0; i < len(recommend); i++ {
40+
ct, _ := service.MyService.Docker().DockerListByImage(recommend[i].Image, recommend[i].ImageVersion)
41+
if ct != nil {
42+
list[i].State = ct.State
43+
}
44+
}
4145
for i := 0; i < len(list); i++ {
4246
ct, _ := service.MyService.Docker().DockerListByImage(list[i].Image, list[i].ImageVersion)
4347
if ct != nil {
4448
list[i].State = ct.State
4549
}
4650
}
47-
data := make(map[string]interface{}, 2)
48-
data["count"] = count
49-
data["items"] = list
51+
for i := 0; i < len(community); i++ {
52+
ct, _ := service.MyService.Docker().DockerListByImage(community[i].Image, community[i].ImageVersion)
53+
if ct != nil {
54+
list[i].State = ct.State
55+
}
56+
}
57+
data := make(map[string]interface{}, 3)
58+
data["recommend"] = recommend
59+
data["list"] = list
60+
data["community"] = community
5061

5162
c.JSON(http.StatusOK, &model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: data})
5263
}
@@ -147,20 +158,24 @@ func AppInfo(c *gin.Context) {
147158
info.PortMap = info.Ports[i].CommendPort
148159
}
149160
}
161+
} else {
162+
for i := 0; i < len(info.Ports); i++ {
163+
if info.Ports[i].Type == 0 {
164+
info.PortMap = info.Ports[i].ContainerPort
165+
break
166+
}
167+
}
150168
}
151169

152170
for i := 0; i < len(info.Devices); i++ {
153171
if !file.CheckNotExist(info.Devices[i].ContainerPath) {
154172
info.Devices[i].Path = info.Devices[i].ContainerPath
155173
}
156174
}
157-
if len(info.Tip) > 0 {
158-
info.Tip = env_helper.ReplaceStringDefaultENV(info.Tip)
159-
}
175+
// if len(info.Tip) > 0 {
176+
// info.Tip = env_helper.ReplaceStringDefaultENV(info.Tip)
177+
// }
160178

161-
for i := 0; i < len(info.Volumes); i++ {
162-
info.Volumes[i].Path = docker.GetDir("", info.Volumes[i].ContainerPath)
163-
}
164179
// portOrder := func(c1, c2 *model.Ports) bool {
165180
// return c1.Type < c2.Type
166181
// }
@@ -207,7 +222,7 @@ func CategoryList(c *gin.Context) {
207222
}
208223

209224
rear := append([]model.ServerCategoryList{}, list[0:]...)
210-
list = append(list[:0], model.ServerCategoryList{Count: count, Name: "All"})
225+
list = append(list[:0], model.ServerCategoryList{Count: count, Name: "All", Font: "apps"})
211226
list = append(list, rear...)
212227
c.JSON(http.StatusOK, &model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS), Data: list})
213228
}

0 commit comments

Comments
 (0)