fixed file upload bug
This commit is contained in:
parent
07e96511cd
commit
9213f9e379
2
UI
2
UI
|
@ -1 +1 @@
|
||||||
Subproject commit 30aac33948d96c4c302438f98a435fc51953702a
|
Subproject commit 247c099bf14a2d9eb94bf7798e04d00dbc8f7efd
|
|
@ -199,7 +199,7 @@ func CopyFile(src, dst string) error {
|
||||||
if len(name) > 2 {
|
if len(name) > 2 {
|
||||||
nameIndex = len(name) - 2
|
nameIndex = len(name) - 2
|
||||||
}
|
}
|
||||||
name[nameIndex] = name[nameIndex] + strconv.Itoa(i+1)
|
name[nameIndex] = name[nameIndex] + "(Copy)"
|
||||||
dst = dstPath
|
dst = dstPath
|
||||||
for _, v := range name {
|
for _, v := range name {
|
||||||
dst += v + "."
|
dst += v + "."
|
||||||
|
|
|
@ -296,12 +296,14 @@ func GetFileUpload(c *gin.Context) {
|
||||||
totalChunks, _ := strconv.Atoi(c.DefaultQuery("totalChunks", "0"))
|
totalChunks, _ := strconv.Atoi(c.DefaultQuery("totalChunks", "0"))
|
||||||
path := c.Query("path")
|
path := c.Query("path")
|
||||||
dirPath := ""
|
dirPath := ""
|
||||||
|
hash := file.GetHashByContent([]byte(fileName))
|
||||||
|
tempDir := "/casaOS/temp/" + hash + strconv.Itoa(totalChunks) + "/"
|
||||||
if fileName != relative {
|
if fileName != relative {
|
||||||
dirPath = strings.TrimSuffix(relative, fileName)
|
dirPath = strings.TrimSuffix(relative, fileName)
|
||||||
|
tempDir += dirPath
|
||||||
file.MkDir(path + "/" + dirPath)
|
file.MkDir(path + "/" + dirPath)
|
||||||
}
|
}
|
||||||
hash := file.GetHashByContent([]byte(fileName))
|
tempDir += chunkNumber
|
||||||
tempDir := "/casaOS/temp/" + hash + strconv.Itoa(totalChunks) + "/" + chunkNumber
|
|
||||||
if !file.CheckNotExist(tempDir) {
|
if !file.CheckNotExist(tempDir) {
|
||||||
c.JSON(200, model.Result{Success: 200, Message: oasis_err2.GetMsg(oasis_err2.FILE_ALREADY_EXISTS)})
|
c.JSON(200, model.Result{Success: 200, Message: oasis_err2.GetMsg(oasis_err2.FILE_ALREADY_EXISTS)})
|
||||||
return
|
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)})
|
c.JSON(oasis_err2.INVALID_PARAMS, model.Result{Success: oasis_err2.INVALID_PARAMS, Message: oasis_err2.GetMsg(oasis_err2.INVALID_PARAMS)})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
tempDir := "/casaOS/temp/" + hash + strconv.Itoa(totalChunks) + "/"
|
||||||
|
|
||||||
if fileName != relative {
|
if fileName != relative {
|
||||||
dirPath = strings.TrimSuffix(relative, fileName)
|
dirPath = strings.TrimSuffix(relative, fileName)
|
||||||
|
tempDir += dirPath
|
||||||
file.MkDir(path + "/" + dirPath)
|
file.MkDir(path + "/" + dirPath)
|
||||||
}
|
}
|
||||||
tempDir := "/casaOS/temp/" + hash + strconv.Itoa(totalChunks)
|
|
||||||
|
|
||||||
path += "/" + relative
|
path += "/" + relative
|
||||||
|
|
||||||
if !file.CheckNotExist(tempDir + "/" + chunkNumber) {
|
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)})
|
file.RMDir(tempDir + chunkNumber)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if totalChunks > 1 {
|
if totalChunks > 1 {
|
||||||
file.IsNotExistMkDir(tempDir)
|
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()
|
defer out.Close()
|
||||||
_, err := io.Copy(out, f)
|
_, err := io.Copy(out, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
|
"context"
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
|
@ -22,8 +23,10 @@ import (
|
||||||
|
|
||||||
var UDPconn *net.UDPConn
|
var UDPconn *net.UDPConn
|
||||||
var PeopleMap map[string]quic.Stream
|
var PeopleMap map[string]quic.Stream
|
||||||
|
var Message chan model.MessageModel
|
||||||
|
|
||||||
func Dial(addr string, token string) error {
|
func Dial(addr string, token string) error {
|
||||||
|
Message = make(chan model.MessageModel)
|
||||||
quicConfig := &quic.Config{
|
quicConfig := &quic.Config{
|
||||||
ConnectionIDLength: 4,
|
ConnectionIDLength: 4,
|
||||||
KeepAlive: true,
|
KeepAlive: true,
|
||||||
|
@ -38,11 +41,15 @@ func Dial(addr string, token string) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// stream, err := session.OpenStreamSync(context.Background())
|
stream, err := session.OpenStreamSync(context.Background())
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
|
SayHello(stream, token)
|
||||||
|
//写
|
||||||
|
go ReadContent(stream)
|
||||||
|
//读
|
||||||
|
//结果
|
||||||
return nil
|
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 := ""
|
path := ""
|
||||||
for {
|
for {
|
||||||
prefixByte := make([]byte, 4)
|
prefixByte := make([]byte, 4)
|
||||||
|
@ -161,8 +168,8 @@ func ReadContent(stream quic.Stream) (model.MessageModel, error) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return m, nil
|
Message <- m
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return model.MessageModel{}, nil
|
Message <- model.MessageModel{}
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,7 +157,7 @@ GetPartitionSectors() {
|
||||||
#检查没有使用的挂载点删除文件夹
|
#检查没有使用的挂载点删除文件夹
|
||||||
AutoRemoveUnuseDir() {
|
AutoRemoveUnuseDir() {
|
||||||
DIRECTORY="/DATA/"
|
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
|
for i in $dir; do
|
||||||
|
|
||||||
path="$DIRECTORY$i"
|
path="$DIRECTORY$i"
|
||||||
|
|
Loading…
Reference in a new issue