From b6f413b9e944ec75fe2ec2e043a5ea118c6aea8b Mon Sep 17 00:00:00 2001 From: link Date: Thu, 18 Aug 2022 11:18:27 +0800 Subject: [PATCH] 0.3.5 (#464) * initial completion of the sharing function * Adjusting multi-partition disk mounts * Add file sharing function * update usb auto mount shell * update samba config * add umount disk function * update change log * update usb auto mount \ * update usb auto mount * Update periodical.go * Update periodical.go * resolve alpha.1 issues * Update UI --- .gitignore | 1 + route/init.go | 8 ++- route/v1/disk.go | 13 +++- route/v1/docker.go | 2 +- route/v1/samba.go | 5 +- route/v1/storage.go | 11 +++- service/docker.go | 11 ++-- service/model/o_disk.go | 10 +++ service/shares.go | 8 ++- web/browserconfig.xml | 18 +++--- web/favicon.svg | 28 ++++---- web/img/icon/safari-pinned-tab.svg | 50 +++++++-------- web/index.html | 13 +++- web/js/4.js | 100 +++++++++++++++++------------ web/js/7.js | 2 +- web/js/8.js | 6 +- web/js/9.js | 6 +- web/js/app.js | 64 +++++++++--------- web/robots.txt | 2 +- web/site.webmanifest | 28 ++++---- web/static.go | 12 ++-- 21 files changed, 234 insertions(+), 164 deletions(-) diff --git a/.gitignore b/.gitignore index 62ef035..3d60515 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ main CasaOS github.com .all-contributorsrc +build \ No newline at end of file diff --git a/route/init.go b/route/init.go index 19e4e20..73fa177 100644 --- a/route/init.go +++ b/route/init.go @@ -5,15 +5,18 @@ import ( "os" "strconv" "strings" + "time" "github.com/IceWhaleTech/CasaOS/pkg/config" "github.com/IceWhaleTech/CasaOS/pkg/samba" "github.com/IceWhaleTech/CasaOS/pkg/utils/command" "github.com/IceWhaleTech/CasaOS/pkg/utils/encryption" "github.com/IceWhaleTech/CasaOS/pkg/utils/file" + "github.com/IceWhaleTech/CasaOS/pkg/utils/loger" "github.com/IceWhaleTech/CasaOS/service" model2 "github.com/IceWhaleTech/CasaOS/service/model" uuid "github.com/satori/go.uuid" + "go.uber.org/zap" ) func InitFunction() { @@ -24,7 +27,8 @@ func InitFunction() { // Soon to be removed ChangeAPIUrl() MoveUserToDB() - InitNetworkMount() + go InitNetworkMount() + } func CheckSerialDiskMount() { @@ -141,12 +145,14 @@ func MoveUserToDB() { } func InitNetworkMount() { + time.Sleep(time.Second * 10) connections := service.MyService.Connections().GetConnectionsList() for _, v := range connections { connection := service.MyService.Connections().GetConnectionByID(fmt.Sprint(v.ID)) directories, err := samba.GetSambaSharesList(connection.Host, connection.Port, connection.Username, connection.Password) if err != nil { service.MyService.Connections().DeleteConnection(fmt.Sprint(connection.ID)) + loger.Error("mount samba err", zap.Any("err", err), zap.Any("info", connection)) continue } baseHostPath := "/mnt/" + connection.Host diff --git a/route/v1/disk.go b/route/v1/disk.go index f04a0b1..271c9b5 100644 --- a/route/v1/disk.go +++ b/route/v1/disk.go @@ -1,6 +1,7 @@ package v1 import ( + "fmt" "net/http" "reflect" "strconv" @@ -255,6 +256,8 @@ func DeleteDisksUmount(c *gin.Context) { service.MyService.Disk().UmountPointAndRemoveDir(v.Path) //delete data service.MyService.Disk().DeleteMountPoint(v.Path, v.MountPoint) + + service.MyService.Shares().DeleteShareByPath(v.MountPoint) } service.MyService.Disk().RemoveLSBLKCache() @@ -367,7 +370,7 @@ func PostDiskAddPartition(c *gin.Context) { js := make(map[string]interface{}) c.ShouldBind(&js) path := js["path"].(string) - //name := js["name"].(string) + name := js["name"].(string) format := js["format"].(bool) if len(path) == 0 { @@ -412,10 +415,16 @@ func PostDiskAddPartition(c *gin.Context) { // c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.DISK_NEEDS_FORMAT, Message: common_err.GetMsg(common_err.DISK_NEEDS_FORMAT)}) // return // } + fmt.Println(name) + if len(name) == 0 { + name = "Storage" + } + fmt.Println(name) for i := 0; i < len(currentDisk.Children); i++ { childrenName := currentDisk.Children[i].Label if len(childrenName) == 0 { - childrenName = "Storage_" + currentDisk.Children[i].Name + //childrenName = name + "_" + currentDisk.Children[i].Name + childrenName = name + "_" + strconv.Itoa(i+1) } mountPath := "/DATA/" + childrenName if !file.CheckNotExist(mountPath) { diff --git a/route/v1/docker.go b/route/v1/docker.go index c04cce8..6eb5344 100644 --- a/route/v1/docker.go +++ b/route/v1/docker.go @@ -1120,7 +1120,7 @@ func ContainerUpdateInfo(c *gin.Context) { showENV := info.Config.Labels["show_env"] showENVList := strings.Split(showENV, ",") showENVMap := make(map[string]string) - if len(showENVList) > 0 { + if len(showENVList) > 0 && showENVList[0] != "" { for _, name := range showENVList { showENVMap[name] = "1" } diff --git a/route/v1/samba.go b/route/v1/samba.go index 5bb3dc2..b7e88b2 100644 --- a/route/v1/samba.go +++ b/route/v1/samba.go @@ -2,7 +2,7 @@ * @Author: LinkLeong link@icewhale.com * @Date: 2022-07-26 11:08:48 * @LastEditors: LinkLeong - * @LastEditTime: 2022-08-05 12:16:39 + * @LastEditTime: 2022-08-17 18:25:42 * @FilePath: /CasaOS/route/v1/samba.go * @Description: * @Website: https://www.casaos.io @@ -85,6 +85,7 @@ func PostSambaSharesCreate(c *gin.Context) { shareDBModel.Anonymous = true shareDBModel.Path = v.Path shareDBModel.Name = filepath.Base(v.Path) + os.Chmod(v.Path, 0777) service.MyService.Shares().CreateShare(shareDBModel) } @@ -127,8 +128,8 @@ func PostSambaConnectionsCreate(c *gin.Context) { c.JSON(common_err.CLIENT_ERROR, model.Result{Success: common_err.INVALID_PARAMS, Message: common_err.GetMsg(common_err.INVALID_PARAMS)}) return } + connection.Host = strings.Split(connection.Host, "/")[0] // check is exists - connections := service.MyService.Connections().GetConnectionByHost(connection.Host) if len(connections) > 0 { c.JSON(common_err.SERVICE_ERROR, model.Result{Success: common_err.Record_ALREADY_EXIST, Message: common_err.GetMsg(common_err.Record_ALREADY_EXIST), Data: common_err.GetMsg(common_err.Record_ALREADY_EXIST)}) diff --git a/route/v1/storage.go b/route/v1/storage.go index b45e22e..b6bb3e3 100644 --- a/route/v1/storage.go +++ b/route/v1/storage.go @@ -2,7 +2,7 @@ * @Author: LinkLeong link@icewhale.com * @Date: 2022-07-11 16:02:29 * @LastEditors: LinkLeong - * @LastEditTime: 2022-08-11 14:20:02 + * @LastEditTime: 2022-08-17 19:14:50 * @FilePath: /CasaOS/route/v1/storage.go * @Description: * @Website: https://www.casaos.io @@ -11,8 +11,8 @@ package v1 import ( + "path/filepath" "reflect" - "strconv" "github.com/IceWhaleTech/CasaOS/model" "github.com/IceWhaleTech/CasaOS/pkg/utils/common_err" @@ -70,7 +70,12 @@ func GetStorageList(c *gin.Context) { stor.Type = v.FsType stor.DriveName = v.Name if len(v.Label) == 0 { - stor.Label = "Storage" + strconv.Itoa(diskNumber) + "_" + strconv.Itoa(children) + if stor.MountPoint == "/" { + stor.Label = "System" + } else { + stor.Label = filepath.Base(stor.MountPoint) + } + children += 1 } else { stor.Label = v.Label diff --git a/service/docker.go b/service/docker.go index 45bc4a8..9c8041d 100644 --- a/service/docker.go +++ b/service/docker.go @@ -535,13 +535,14 @@ func (ds *dockerService) DockerContainerCreate(m model.CustomizationPostData, id // info.NetworkSettings = &types.NetworkSettings{} hostConfig = info.HostConfig config = info.Config + } else { + config.Cmd = m.Cmd + config.Image = m.Image + config.Env = envArr + config.Hostname = m.HostName + config.ExposedPorts = ports } - config.Cmd = m.Cmd - config.Image = m.Image - config.Env = envArr - config.Hostname = m.HostName - config.ExposedPorts = ports config.Labels["origin"] = m.Origin config.Labels["casaos"] = "casaos" config.Labels["web"] = m.PortMap diff --git a/service/model/o_disk.go b/service/model/o_disk.go index c7311bf..1121e87 100644 --- a/service/model/o_disk.go +++ b/service/model/o_disk.go @@ -1,3 +1,13 @@ +/* + * @Author: LinkLeong link@icewhale.org + * @Date: 2021-12-07 17:14:41 + * @LastEditors: LinkLeong + * @LastEditTime: 2022-08-17 18:46:43 + * @FilePath: /CasaOS/service/model/o_disk.go + * @Description: + * @Website: https://www.casaos.io + * Copyright (c) 2022 by icewhale, All Rights Reserved. + */ package model //SerialAdvanced Technology Attachment (STAT) diff --git a/service/shares.go b/service/shares.go index 01ea7b0..1f8b096 100644 --- a/service/shares.go +++ b/service/shares.go @@ -2,7 +2,7 @@ * @Author: LinkLeong link@icewhale.org * @Date: 2022-07-26 11:21:14 * @LastEditors: LinkLeong - * @LastEditTime: 2022-08-11 14:04:00 + * @LastEditTime: 2022-08-18 11:16:25 * @FilePath: /CasaOS/service/shares.go * @Description: * @Website: https://www.casaos.io @@ -30,12 +30,18 @@ type SharesService interface { DeleteShare(id string) UpdateConfigFile() InitSambaConfig() + DeleteShareByPath(path string) } type sharesStruct struct { db *gorm.DB } +func (s *sharesStruct) DeleteShareByPath(path string) { + s.db.Where("path LIKE ?", path+"%").Delete(&model.SharesDBModel{}) + s.UpdateConfigFile() +} + func (s *sharesStruct) GetSharesByName(name string) (shares []model2.SharesDBModel) { s.db.Select("anonymous,path,id").Where("name = ?", name).Find(&shares) diff --git a/web/browserconfig.xml b/web/browserconfig.xml index a02d62e..a221792 100644 --- a/web/browserconfig.xml +++ b/web/browserconfig.xml @@ -1,9 +1,9 @@ - - - - - - #da532c - - - + + + + + + #da532c + + + diff --git a/web/favicon.svg b/web/favicon.svg index 8d176f0..9760ab7 100644 --- a/web/favicon.svg +++ b/web/favicon.svg @@ -1,14 +1,14 @@ - - - - - - - - + + + + + + + + diff --git a/web/img/icon/safari-pinned-tab.svg b/web/img/icon/safari-pinned-tab.svg index e750780..af12e15 100644 --- a/web/img/icon/safari-pinned-tab.svg +++ b/web/img/icon/safari-pinned-tab.svg @@ -1,25 +1,25 @@ - - - - -Created by potrace 1.14, written by Peter Selinger 2001-2017 - - - - - + + + + +Created by potrace 1.14, written by Peter Selinger 2001-2017 + + + + + diff --git a/web/index.html b/web/index.html index bb2b479..8bd1b96 100644 --- a/web/index.html +++ b/web/index.html @@ -1,3 +1,13 @@ + @@ -20,7 +30,7 @@ CasaOS - +