mirror of
https://github.com/IceWhaleTech/CasaOS.git
synced 2025-06-16 05:55:33 +00:00
update file
This commit is contained in:
parent
33acfababd
commit
d890b16644
@ -39,7 +39,7 @@ func CheckPermission(src string) bool {
|
|||||||
|
|
||||||
// IsNotExistMkDir create a directory if it does not exist
|
// IsNotExistMkDir create a directory if it does not exist
|
||||||
func IsNotExistMkDir(src string) error {
|
func IsNotExistMkDir(src string) error {
|
||||||
if notExist := CheckNotExist(src); notExist == true {
|
if notExist := CheckNotExist(src); notExist {
|
||||||
if err := MkDir(src); err != nil {
|
if err := MkDir(src); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -293,7 +293,7 @@ func WriteToPath(data []byte, path, name string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//最终拼接
|
//最终拼接
|
||||||
func SpliceFiles(dir, path string, length int) error {
|
func SpliceFiles(dir, path string, length int, startPoint int) error {
|
||||||
|
|
||||||
fullPath := path
|
fullPath := path
|
||||||
|
|
||||||
@ -305,8 +305,8 @@ func SpliceFiles(dir, path string, length int) error {
|
|||||||
)
|
)
|
||||||
defer file.Close()
|
defer file.Close()
|
||||||
bufferedWriter := bufio.NewWriter(file)
|
bufferedWriter := bufio.NewWriter(file)
|
||||||
for i := 0; i < length; i++ {
|
for i := 0; i < length+startPoint; i++ {
|
||||||
data, err := ioutil.ReadFile(path + strconv.Itoa(i))
|
data, err := ioutil.ReadFile(dir + "/" + strconv.Itoa(i+startPoint))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -292,27 +292,23 @@ func GetFileUpload(c *gin.Context) {
|
|||||||
|
|
||||||
relative := c.Query("relativePath")
|
relative := c.Query("relativePath")
|
||||||
fileName := c.Query("filename")
|
fileName := c.Query("filename")
|
||||||
size, _ := strconv.ParseInt(c.Query("totalSize"), 10, 64)
|
chunkNumber := c.Query("chunkNumber")
|
||||||
path := c.Query("path")
|
path := c.Query("path")
|
||||||
|
dirPath := ""
|
||||||
if fileName != relative {
|
if fileName != relative {
|
||||||
dirPath := strings.TrimSuffix(relative, fileName)
|
dirPath = strings.TrimSuffix(relative, fileName)
|
||||||
file.MkDir(path + "/" + dirPath)
|
file.MkDir(path + "/" + dirPath)
|
||||||
}
|
}
|
||||||
path += "/" + relative
|
hash := file.GetHashByContent([]byte(fileName))
|
||||||
|
tempDir := path + "/"
|
||||||
if !file.CheckNotExist(path) {
|
if len(dirPath) > 0 {
|
||||||
f, _ := os.Stat(path)
|
tempDir += dirPath + "/" + hash + "/" + chunkNumber
|
||||||
|
} else {
|
||||||
if f.Size() == size {
|
tempDir += hash + "/" + chunkNumber
|
||||||
|
}
|
||||||
c.JSON(200, model.Result{Success: 200, Message: oasis_err2.GetMsg(oasis_err2.FILE_ALREADY_EXISTS)})
|
if !file.CheckNotExist(tempDir) {
|
||||||
return
|
c.JSON(200, model.Result{Success: 200, Message: oasis_err2.GetMsg(oasis_err2.FILE_ALREADY_EXISTS)})
|
||||||
}
|
|
||||||
|
|
||||||
os.Remove(path)
|
|
||||||
c.JSON(204, model.Result{Success: 204, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
c.JSON(204, model.Result{Success: 204, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
|
c.JSON(204, model.Result{Success: 204, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
|
||||||
@ -331,32 +327,66 @@ func PostFileUpload(c *gin.Context) {
|
|||||||
f, _, _ := c.Request.FormFile("file")
|
f, _, _ := c.Request.FormFile("file")
|
||||||
relative := c.PostForm("relativePath")
|
relative := c.PostForm("relativePath")
|
||||||
fileName := c.PostForm("filename")
|
fileName := c.PostForm("filename")
|
||||||
|
totalChunks, _ := strconv.Atoi(c.DefaultPostForm("totalChunks", "0"))
|
||||||
|
chunkNumber := c.PostForm("chunkNumber")
|
||||||
|
dirPath := ""
|
||||||
path := c.PostForm("path")
|
path := c.PostForm("path")
|
||||||
|
|
||||||
|
hash := file.GetHashByContent([]byte(fileName))
|
||||||
|
|
||||||
if len(path) == 0 {
|
if len(path) == 0 {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
||||||
if fileName != relative {
|
if fileName != relative {
|
||||||
dirPath := strings.TrimSuffix(relative, fileName)
|
dirPath = strings.TrimSuffix(relative, fileName)
|
||||||
file.MkDir(path + "/" + dirPath)
|
file.MkDir(path + "/" + dirPath)
|
||||||
}
|
}
|
||||||
|
tempDir := path + "/"
|
||||||
|
if len(dirPath) > 0 {
|
||||||
|
tempDir += dirPath + "/" + hash
|
||||||
|
} else {
|
||||||
|
tempDir += hash
|
||||||
|
}
|
||||||
path += "/" + relative
|
path += "/" + relative
|
||||||
|
|
||||||
if !file.CheckNotExist(path) {
|
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)})
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
out, _ := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0644)
|
if totalChunks > 1 {
|
||||||
defer out.Close()
|
file.IsNotExistMkDir(tempDir)
|
||||||
_, err := io.Copy(out, f)
|
|
||||||
|
out, _ := os.OpenFile(tempDir+"/"+chunkNumber, os.O_WRONLY|os.O_CREATE, 0644)
|
||||||
|
defer out.Close()
|
||||||
|
_, err := io.Copy(out, f)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(oasis_err2.ERROR, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
out, _ := os.OpenFile(path, os.O_WRONLY|os.O_CREATE, 0644)
|
||||||
|
defer out.Close()
|
||||||
|
_, err := io.Copy(out, f)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(oasis_err2.ERROR, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fileNum, err := ioutil.ReadDir(tempDir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(oasis_err2.ERROR, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
|
c.JSON(oasis_err2.ERROR, model.Result{Success: oasis_err2.ERROR, Message: oasis_err2.GetMsg(oasis_err2.ERROR), Data: err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if totalChunks == len(fileNum) {
|
||||||
|
file.SpliceFiles(tempDir, path, totalChunks, 1)
|
||||||
|
file.RMDir(tempDir)
|
||||||
|
}
|
||||||
|
|
||||||
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
|
c.JSON(http.StatusOK, model.Result{Success: oasis_err2.SUCCESS, Message: oasis_err2.GetMsg(oasis_err2.SUCCESS)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ func ReadContent(stream quic.Stream) (model.MessageModel, error) {
|
|||||||
|
|
||||||
err = ioutil.WriteFile(filepath, dataByte, 0644)
|
err = ioutil.WriteFile(filepath, dataByte, 0644)
|
||||||
if dataModel.Index >= (dataModel.Length - 1) {
|
if dataModel.Index >= (dataModel.Length - 1) {
|
||||||
file.SpliceFiles("", path, dataModel.Length)
|
//file.SpliceFiles("", path, dataModel.Length)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -2,4 +2,4 @@ package types
|
|||||||
|
|
||||||
const CURRENTVERSION = "0.2.10"
|
const CURRENTVERSION = "0.2.10"
|
||||||
|
|
||||||
const BODY = "<li>sAdded CasaOS own file manager</li><li>Fixed issues</li><li>Update front-end translation</li>"
|
const BODY = "<li>Added CasaOS own file manager</li><li>Fixed the problem of failed to create storage space</li>"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user