Commit f012a199 by Li Feifei

debug

parent defe8ede
Pipeline #8494 passed with stages
in 21 seconds
...@@ -3,7 +3,6 @@ package upload ...@@ -3,7 +3,6 @@ package upload
import ( import (
"archive/zip" "archive/zip"
"crypto/md5" "crypto/md5"
"crypto/sha1"
"encoding/hex" "encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
...@@ -130,6 +129,9 @@ func Down(v *models.XyuSmallTempFiles) { ...@@ -130,6 +129,9 @@ func Down(v *models.XyuSmallTempFiles) {
t := time.Now() t := time.Now()
now := fmt.Sprintf("%02d-%02d-%02d %02d:%02d:%02d", now := fmt.Sprintf("%02d-%02d-%02d %02d:%02d:%02d",
t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second()) t.Year(), t.Month(), t.Day(), t.Hour(), t.Minute(), t.Second())
objectName := v.Url[strings.Index(v.Url, "com/")+4:]
slice_path := strings.Split(objectName, "/")
fmt.Println(slice_path[2])
room_file["room_id"] = room.Id room_file["room_id"] = room.Id
room_file["id"] = t.Unix() room_file["id"] = t.Unix()
room_file["is_courseware"] = "1" room_file["is_courseware"] = "1"
...@@ -144,12 +146,8 @@ func Down(v *models.XyuSmallTempFiles) { ...@@ -144,12 +146,8 @@ func Down(v *models.XyuSmallTempFiles) {
} else if v.Type == 3 { } else if v.Type == 3 {
room_file["is_titlebook"] = 1 room_file["is_titlebook"] = 1
} }
contentHash := slice_path[2]
contentHash, _ := fileContentHash(file) room_file["file_name_hash"] = slice_path[3]
fileHash := []byte(filename)
fileHashName := fmt.Sprintf("%x", sha1.Sum(fileHash))
room_file["file_name_hash"] = fileHashName
room_file["hash"] = contentHash room_file["hash"] = contentHash
//获取文件后缀 //获取文件后缀
...@@ -177,8 +175,7 @@ func Down(v *models.XyuSmallTempFiles) { ...@@ -177,8 +175,7 @@ func Down(v *models.XyuSmallTempFiles) {
} }
defer fd.Close() defer fd.Close()
//objectPath := "documents/" + v.RoomNum + "/" + contentHash + "/" + fileHashName + "/"
objectName := v.Url[strings.Index(v.Url, "com/")+4:]
fmt.Println("objectName == ", objectName) fmt.Println("objectName == ", objectName)
objectPath := objectName[0:strings.LastIndex(objectName, "/")]+"/" objectPath := objectName[0:strings.LastIndex(objectName, "/")]+"/"
room_file["path"] = objectName room_file["path"] = objectName
...@@ -212,7 +209,7 @@ func Down(v *models.XyuSmallTempFiles) { ...@@ -212,7 +209,7 @@ func Down(v *models.XyuSmallTempFiles) {
ch := make(chan bool) ch := make(chan bool)
go func() { go func() {
err := downloadFile(downUrl, func(length, downLen int64) { err := downloadFile(downUrl, contentHash ,func(length, downLen int64) {
}) })
if err == nil { if err == nil {
...@@ -521,7 +518,7 @@ func fileContentHash(file io.Reader) (string, []byte) { ...@@ -521,7 +518,7 @@ func fileContentHash(file io.Reader) (string, []byte) {
return fmt.Sprintf("%s", hex.EncodeToString(result)), b return fmt.Sprintf("%s", hex.EncodeToString(result)), b
} }
func downloadFile(url string, fb func(length, downLen int64)) error { func downloadFile(url, contentHash string, fb func(length, downLen int64)) error {
var ( var (
fsize int64 fsize int64
buf = make([]byte, 32*1024) buf = make([]byte, 32*1024)
...@@ -541,15 +538,10 @@ func downloadFile(url string, fb func(length, downLen int64)) error { ...@@ -541,15 +538,10 @@ func downloadFile(url string, fb func(length, downLen int64)) error {
fmt.Println(err) fmt.Println(err)
} }
//创建文件 //创建文件
var filenameWithSuffix string
filenameWithSuffix = path.Base(url) //获取文件名带后缀
var fileSuffix string
fileSuffix = path.Ext(filenameWithSuffix) //获取文件后缀
var filenameOnly string
filenameOnly = strings.Replace(filenameWithSuffix, fileSuffix, ".zip", -1) //获取文件名 file, err := os.Create("/data/files/" + contentHash+".zip")
file, err := os.Create("/data/files/" + filenameOnly)
if err != nil { if err != nil {
return err return err
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment