Skip to content

Commit

Permalink
Dev (#262)
Browse files Browse the repository at this point in the history
* 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](#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](#214))
### Fixed

- [System] Fixed the problem that sync data cannot submit the device ID ([#68](#68))
- [Files] Fixed the code editor center alignment display problem.([#210](#210))
- [Files] Fixed the problem of wrong name when downloading files.([#240](#240))
- [System] Fixed the network display as a negative number problem.([#224](#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
  • Loading branch information
LinkLeong authored Jun 8, 2022
1 parent d4bed3e commit eaf2341
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 9 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

## [0.3.2-pre]
## [0.3.2-pre] - 2022-06-08

### Added

Expand Down
1 change: 1 addition & 0 deletions route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ func InitRouter() *gin.Engine {
v1FileGroup.DELETE("/delete", v1.DeleteFile)
v1FileGroup.PUT("/update", v1.PutFileContent)
v1FileGroup.GET("/image", v1.GetFileImage)
v1FileGroup.DELETE("/operate/:id", v1.DeleteOperateFileOrDir)

//v1FileGroup.GET("/download", v1.UserFileDownloadCommonService)
}
Expand Down
28 changes: 27 additions & 1 deletion route/v1/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync"

"github.com/IceWhaleTech/CasaOS/model"
"github.com/IceWhaleTech/CasaOS/pkg/config"
Expand Down Expand Up @@ -198,6 +199,7 @@ func GetDownloadFile(c *gin.Context) {
defer ar.Close()
commonDir := file.CommonPrefix(filepath.Separator, list...)


currentPath := filepath.Base(commonDir)

name := "_" + currentPath
Expand Down Expand Up @@ -514,7 +516,9 @@ func PostOperateFileOrDir(c *gin.Context) {
if len(service.OpStrArr) == 1 {
go service.ExecOpFile()
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)})
Expand Down Expand Up @@ -623,3 +627,25 @@ func GetFileImage(c *gin.Context) {
}
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)})
}
98 changes: 91 additions & 7 deletions service/notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type NotifyServer interface {
SendUSBInfoBySocket(list []model2.DriveUSB)
SendDiskInfoBySocket(disk model2.Summary)
SendPersonStatusBySocket(status notify.Person)
SendFileOperateNotify()
SendFileOperateNotify(nowSend bool)
SendInstallAppBySocket(app notify.Application)
}

Expand All @@ -44,19 +44,34 @@ type notifyServer struct {
}

// Send periodic broadcast messages
func (i *notifyServer) SendFileOperateNotify() {
for {
func (i *notifyServer) SendFileOperateNotify(nowSend bool) {

if nowSend {

len := 0
FileQueue.Range(func(k, v interface{}) bool {
len++
return true
})

model := notify.NotifyModel{}
listMsg := make(map[string]interface{})
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
}
listMsg := make(map[string]interface{})
model := notify.NotifyModel{}

model.State = "NORMAL"
list := []notify.File{}
OpStrArrbak := OpStrArr
Expand All @@ -78,7 +93,9 @@ func (i *notifyServer) SendFileOperateNotify() {
} else {
task.Status = "PROCESSING"
}
if temp.ProcessedSize == temp.TotalSize {

if temp.ProcessedSize >= temp.TotalSize {

task.Finished = true
task.Status = "FINISHED"
FileQueue.Delete(v)
Expand Down Expand Up @@ -109,8 +126,75 @@ func (i *notifyServer) SendFileOperateNotify() {
notify.Path = "file_operate"
notify.Msg = msg
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) {
Expand Down

0 comments on commit eaf2341

Please sign in to comment.