Explorar el Código

fixed file upload bug

link hace 3 años
padre
commit
9213f9e379
Se han modificado 5 ficheros con 27 adiciones y 18 borrados
  1. 1 1
      UI
  2. 1 1
      pkg/utils/file/file.go
  3. 9 7
      route/v1/file.go
  4. 15 8
      service/udpconn.go
  5. 1 1
      shell/helper.sh

+ 1 - 1
UI

@@ -1 +1 @@
-Subproject commit 30aac33948d96c4c302438f98a435fc51953702a
+Subproject commit 247c099bf14a2d9eb94bf7798e04d00dbc8f7efd

+ 1 - 1
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 + "."

+ 9 - 7
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 {

+ 15 - 8
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{}
 }

+ 1 - 1
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"