diff --git a/UI b/UI index 30aac33..247c099 160000 --- a/UI +++ b/UI @@ -1 +1 @@ -Subproject commit 30aac33948d96c4c302438f98a435fc51953702a +Subproject commit 247c099bf14a2d9eb94bf7798e04d00dbc8f7efd diff --git a/pkg/utils/file/file.go b/pkg/utils/file/file.go index c411a8f..c2d3316 100644 --- a/pkg/utils/file/file.go +++ b/pkg/utils/file/file.go @@ -199,7 +199,7 @@ func CopyFile(src, dst string) error { if len(name) > 2 { nameIndex = len(name) - 2 } - name[nameIndex] = name[nameIndex] + strconv.Itoa(i+1) + name[nameIndex] = name[nameIndex] + "(Copy)" dst = dstPath for _, v := range name { dst += v + "." diff --git a/route/v1/file.go b/route/v1/file.go index 0fed966..9f3a7c6 100644 --- a/route/v1/file.go +++ b/route/v1/file.go @@ -296,12 +296,14 @@ func GetFileUpload(c *gin.Context) { totalChunks, _ := strconv.Atoi(c.DefaultQuery("totalChunks", "0")) path := c.Query("path") dirPath := "" + hash := file.GetHashByContent([]byte(fileName)) + tempDir := "/casaOS/temp/" + hash + strconv.Itoa(totalChunks) + "/" if fileName != relative { dirPath = strings.TrimSuffix(relative, fileName) + tempDir += dirPath file.MkDir(path + "/" + dirPath) } - hash := file.GetHashByContent([]byte(fileName)) - tempDir := "/casaOS/temp/" + hash + strconv.Itoa(totalChunks) + "/" + chunkNumber + tempDir += chunkNumber if !file.CheckNotExist(tempDir) { c.JSON(200, model.Result{Success: 200, Message: oasis_err2.GetMsg(oasis_err2.FILE_ALREADY_EXISTS)}) return @@ -334,24 +336,24 @@ func PostFileUpload(c *gin.Context) { c.JSON(oasis_err2.INVALID_PARAMS, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)}) return } + tempDir := "/casaOS/temp/" + hash + strconv.Itoa(totalChunks) + "/" if fileName != relative { dirPath = strings.TrimSuffix(relative, fileName) + tempDir += dirPath file.MkDir(path + "/" + dirPath) } - tempDir := "/casaOS/temp/" + hash + strconv.Itoa(totalChunks) path += "/" + relative - if !file.CheckNotExist(tempDir + "/" + chunkNumber) { - c.JSON(oasis_err2.FILE_ALREADY_EXISTS, model.Result{Success: oasis_err2.FILE_ALREADY_EXISTS, Message: oasis_err2.GetMsg(oasis_err2.FILE_ALREADY_EXISTS)}) - return + if !file.CheckNotExist(tempDir + chunkNumber) { + file.RMDir(tempDir + chunkNumber) } if totalChunks > 1 { file.IsNotExistMkDir(tempDir) - out, _ := os.OpenFile(tempDir+"/"+chunkNumber, os.O_WRONLY|os.O_CREATE, 0644) + out, _ := os.OpenFile(tempDir+chunkNumber, os.O_WRONLY|os.O_CREATE, 0644) defer out.Close() _, err := io.Copy(out, f) if err != nil { diff --git a/service/udpconn.go b/service/udpconn.go index c22c762..edf8688 100644 --- a/service/udpconn.go +++ b/service/udpconn.go @@ -2,6 +2,7 @@ package service import ( "bufio" + "context" "crypto/md5" "crypto/tls" "encoding/hex" @@ -22,8 +23,10 @@ import ( var UDPconn *net.UDPConn var PeopleMap map[string]quic.Stream +var Message chan model.MessageModel func Dial(addr string, token string) error { + Message = make(chan model.MessageModel) quicConfig := &quic.Config{ ConnectionIDLength: 4, KeepAlive: true, @@ -38,11 +41,15 @@ func Dial(addr string, token string) error { if err != nil { return err } - // stream, err := session.OpenStreamSync(context.Background()) - // if err != nil { - // return err - // } - + stream, err := session.OpenStreamSync(context.Background()) + if err != nil { + return err + } + SayHello(stream, token) + //写 + go ReadContent(stream) + //读 + //结果 return nil } @@ -112,7 +119,7 @@ func SendData(stream quic.Stream, m model.MessageModel) { } //读取数据 -func ReadContent(stream quic.Stream) (model.MessageModel, error) { +func ReadContent(stream quic.Stream) { path := "" for { prefixByte := make([]byte, 4) @@ -161,8 +168,8 @@ func ReadContent(stream quic.Stream) (model.MessageModel, error) { break } } else { - return m, nil + Message <- m } } - return model.MessageModel{}, nil + Message <- model.MessageModel{} } diff --git a/shell/helper.sh b/shell/helper.sh index 56e5358..b48061f 100644 --- a/shell/helper.sh +++ b/shell/helper.sh @@ -157,7 +157,7 @@ GetPartitionSectors() { #检查没有使用的挂载点删除文件夹 AutoRemoveUnuseDir() { DIRECTORY="/DATA/" - dir=$(ls -l $DIRECTORY | grep "Storage[0-9]" | awk '/^d/ {print $NF}') + dir=$(ls -l $DIRECTORY | grep "USB_Storage_sd[a-z][0-9]" | awk '/^d/ {print $NF}') for i in $dir; do path="$DIRECTORY$i"