fixed file upload bug

This commit is contained in:
link 2022-03-10 16:25:33 +08:00
parent 07e96511cd
commit 9213f9e379
5 changed files with 27 additions and 18 deletions

2
UI

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

View file

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

View file

@ -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 {

View file

@ -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{}
}

View file

@ -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"