Sfoglia il codice sorgente

Dev (#262)

* fix bug

* updata UI

* 0.3.2

### Added

- [Files] Files can now be selected multiple files and downloaded, deleted, moved, etc.
- [Apps] Support to modify the application opening address.([#204](https://github.com/IceWhaleTech/CasaOS/issues/204))

### Changed

- [Apps] Hide the display of non-essential environment variables in the application.
- [System] Network, disk, cpu, memory, etc. information is modified to be pushed via socket.
- [System] Optimize opening speed.([#214](https://github.com/IceWhaleTech/CasaOS/issues/214))
### Fixed

- [System] Fixed the problem that sync data cannot submit the device ID ([#68](https://github.com/IceWhaleTech/CasaOS/issues/68))
- [Files] Fixed the code editor center alignment display problem.([#210](https://github.com/IceWhaleTech/CasaOS/issues/210))
- [Files] Fixed the problem of wrong name when downloading files.([#240](https://github.com/IceWhaleTech/CasaOS/issues/240))
- [System] Fixed the network display as a negative number problem.([#224](https://github.com/IceWhaleTech/CasaOS/issues/224))

* Modify log help class

* Fix some bugs in 0.3.2

* Solve the operation file queue problem

* Exclude web folders

* update UI

* add cancel file operate
link 3 anni fa
parent
commit
eaf2341a2a
4 ha cambiato i file con 120 aggiunte e 9 eliminazioni
  1. 1 1
      CHANGELOG.md
  2. 1 0
      route/route.go
  3. 27 1
      route/v1/file.go
  4. 91 7
      service/notify.go

+ 1 - 1
CHANGELOG.md

@@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
 
 
 ### Fixed
 ### Fixed
 
 
-## [0.3.2-pre]
+## [0.3.2-pre] - 2022-06-08
 
 
 ### Added
 ### Added
 
 

+ 1 - 0
route/route.go

@@ -152,6 +152,7 @@ func InitRouter() *gin.Engine {
 			v1FileGroup.DELETE("/delete", v1.DeleteFile)
 			v1FileGroup.DELETE("/delete", v1.DeleteFile)
 			v1FileGroup.PUT("/update", v1.PutFileContent)
 			v1FileGroup.PUT("/update", v1.PutFileContent)
 			v1FileGroup.GET("/image", v1.GetFileImage)
 			v1FileGroup.GET("/image", v1.GetFileImage)
+			v1FileGroup.DELETE("/operate/:id", v1.DeleteOperateFileOrDir)
 
 
 			//v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
 			//v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
 		}
 		}

+ 27 - 1
route/v1/file.go

@@ -15,6 +15,7 @@ import (
 	"path/filepath"
 	"path/filepath"
 	"strconv"
 	"strconv"
 	"strings"
 	"strings"
+	"sync"
 
 
 	"github.com/IceWhaleTech/CasaOS/model"
 	"github.com/IceWhaleTech/CasaOS/model"
 	"github.com/IceWhaleTech/CasaOS/pkg/config"
 	"github.com/IceWhaleTech/CasaOS/pkg/config"
@@ -198,6 +199,7 @@ func GetDownloadFile(c *gin.Context) {
 	defer ar.Close()
 	defer ar.Close()
 	commonDir := file.CommonPrefix(filepath.Separator, list...)
 	commonDir := file.CommonPrefix(filepath.Separator, list...)
 
 
+
 	currentPath := filepath.Base(commonDir)
 	currentPath := filepath.Base(commonDir)
 
 
 	name := "_" + currentPath
 	name := "_" + currentPath
@@ -514,7 +516,9 @@ func PostOperateFileOrDir(c *gin.Context) {
 	if len(service.OpStrArr) == 1 {
 	if len(service.OpStrArr) == 1 {
 		go service.ExecOpFile()
 		go service.ExecOpFile()
 		go service.CheckFileStatus()
 		go service.CheckFileStatus()
-		go service.MyService.Notify().SendFileOperateNotify()
+
+		go service.MyService.Notify().SendFileOperateNotify(false)
+
 	}
 	}
 
 
 	c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
 	c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
@@ -623,3 +627,25 @@ func GetFileImage(c *gin.Context) {
 	}
 	}
 	c.Writer.WriteString(string(data))
 	c.Writer.WriteString(string(data))
 }
 }
+
+func DeleteOperateFileOrDir(c *gin.Context) {
+	id := c.Param("id")
+	if id == "0" {
+		service.FileQueue = sync.Map{}
+		service.OpStrArr = []string{}
+	} else {
+
+		service.FileQueue.Delete(id)
+		tempList := []string{}
+		for _, v := range service.OpStrArr {
+			if v != id {
+				tempList = append(tempList, v)
+			}
+		}
+		service.OpStrArr = tempList
+
+	}
+
+	go service.MyService.Notify().SendFileOperateNotify(true)
+	c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
+}

+ 91 - 7
service/notify.go

@@ -35,7 +35,7 @@ type NotifyServer interface {
 	SendUSBInfoBySocket(list []model2.DriveUSB)
 	SendUSBInfoBySocket(list []model2.DriveUSB)
 	SendDiskInfoBySocket(disk model2.Summary)
 	SendDiskInfoBySocket(disk model2.Summary)
 	SendPersonStatusBySocket(status notify.Person)
 	SendPersonStatusBySocket(status notify.Person)
-	SendFileOperateNotify()
+	SendFileOperateNotify(nowSend bool)
 	SendInstallAppBySocket(app notify.Application)
 	SendInstallAppBySocket(app notify.Application)
 }
 }
 
 
@@ -44,19 +44,34 @@ type notifyServer struct {
 }
 }
 
 
 // Send periodic broadcast messages
 // Send periodic broadcast messages
-func (i *notifyServer) SendFileOperateNotify() {
-	for {
+func (i *notifyServer) SendFileOperateNotify(nowSend bool) {
+
+	if nowSend {
 
 
 		len := 0
 		len := 0
 		FileQueue.Range(func(k, v interface{}) bool {
 		FileQueue.Range(func(k, v interface{}) bool {
 			len++
 			len++
 			return true
 			return true
 		})
 		})
+
+		model := notify.NotifyModel{}
+		listMsg := make(map[string]interface{})
 		if len == 0 {
 		if len == 0 {
+			model.Data = []string{}
+
+			listMsg["file_operate"] = model
+			msg := gosf.Message{}
+			msg.Success = true
+			msg.Body = listMsg
+			msg.Text = "file_operate"
+
+			notify := notify.Message{}
+			notify.Path = "file_operate"
+			notify.Msg = msg
+			NotifyMsg <- notify
 			return
 			return
 		}
 		}
-		listMsg := make(map[string]interface{})
-		model := notify.NotifyModel{}
+
 		model.State = "NORMAL"
 		model.State = "NORMAL"
 		list := []notify.File{}
 		list := []notify.File{}
 		OpStrArrbak := OpStrArr
 		OpStrArrbak := OpStrArr
@@ -78,7 +93,9 @@ func (i *notifyServer) SendFileOperateNotify() {
 			} else {
 			} else {
 				task.Status = "PROCESSING"
 				task.Status = "PROCESSING"
 			}
 			}
-			if temp.ProcessedSize == temp.TotalSize {
+
+			if temp.ProcessedSize >= temp.TotalSize {
+
 				task.Finished = true
 				task.Finished = true
 				task.Status = "FINISHED"
 				task.Status = "FINISHED"
 				FileQueue.Delete(v)
 				FileQueue.Delete(v)
@@ -109,8 +126,75 @@ func (i *notifyServer) SendFileOperateNotify() {
 		notify.Path = "file_operate"
 		notify.Path = "file_operate"
 		notify.Msg = msg
 		notify.Msg = msg
 		NotifyMsg <- notify
 		NotifyMsg <- notify
-		time.Sleep(time.Second * 3)
+	} else {
+		for {
+
+			len := 0
+			FileQueue.Range(func(k, v interface{}) bool {
+				len++
+				return true
+			})
+			if len == 0 {
+				return
+			}
+			listMsg := make(map[string]interface{})
+			model := notify.NotifyModel{}
+			model.State = "NORMAL"
+			list := []notify.File{}
+			OpStrArrbak := OpStrArr
+
+			for _, v := range OpStrArrbak {
+				tempItem, ok := FileQueue.Load(v)
+				temp := tempItem.(model2.FileOperate)
+				if !ok {
+					continue
+				}
+				task := notify.File{}
+				task.Id = v
+				task.ProcessedSize = temp.ProcessedSize
+				task.TotalSize = temp.TotalSize
+				task.To = temp.To
+				task.Type = temp.Type
+				if task.ProcessedSize == 0 {
+					task.Status = "STARTING"
+				} else {
+					task.Status = "PROCESSING"
+				}
+				if temp.ProcessedSize >= temp.TotalSize {
+					task.Finished = true
+					task.Status = "FINISHED"
+					FileQueue.Delete(v)
+					OpStrArr = OpStrArr[1:]
+					go ExecOpFile()
+					list = append(list, task)
+					continue
+				}
+				for _, v := range temp.Item {
+					if v.Size != v.ProcessedSize {
+						task.ProcessingPath = v.From
+						break
+					}
+				}
+
+				list = append(list, task)
+			}
+			model.Data = list
+
+			listMsg["file_operate"] = model
+
+			msg := gosf.Message{}
+			msg.Success = true
+			msg.Body = listMsg
+			msg.Text = "file_operate"
+
+			notify := notify.Message{}
+			notify.Path = "file_operate"
+			notify.Msg = msg
+			NotifyMsg <- notify
+			time.Sleep(time.Second * 3)
+		}
 	}
 	}
+
 }
 }
 
 
 func (i *notifyServer) SendPersonStatusBySocket(status notify.Person) {
 func (i *notifyServer) SendPersonStatusBySocket(status notify.Person) {