|
|
@@ -10,6 +10,7 @@ import (
|
|
|
"log-server/model/fileManager"
|
|
|
"log-server/model/fileManager/request"
|
|
|
"log-server/model/fileManager/response"
|
|
|
+ "strings"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
@@ -35,8 +36,9 @@ func (s *ServiceFileQiniu) QueryVersionByType(req request.FileQiniuRequest) (int
|
|
|
func (s *ServiceFileQiniu) AddQiniuFile(requestCoding request.FileQiniuRequest) (err error) {
|
|
|
//查询真实的父文件夹ID
|
|
|
parentFolder := fileManager.FileFolder{}
|
|
|
- global.GVA_LOG.Info(requestCoding.FileTypeName)
|
|
|
- err = global.GVA_DB.Where("parent_id = ? and name = ?", requestCoding.ParentId, requestCoding.FileTypeName).First(&parentFolder).Error
|
|
|
+ if errors.Is(global.GVA_DB.Where("task_id = ? and name = ?", requestCoding.TaskId, requestCoding.FileTypeName).First(&parentFolder).Error, gorm.ErrRecordNotFound) {
|
|
|
+ return errors.New("父文件夹不存在")
|
|
|
+ }
|
|
|
//==================================
|
|
|
if !errors.Is(global.GVA_DB.Where("parent_id = ? and file_name = ?", requestCoding.ParentId, requestCoding.FileName).First(&fileManager.FileQiniu{}).Error, gorm.ErrRecordNotFound) {
|
|
|
return errors.New("该目录下已存在同名文件")
|
|
|
@@ -127,3 +129,34 @@ func (s *ServiceFileQiniu) DeleteQiniuFileAndRecord(requestCoding request.FileQi
|
|
|
err = global.GVA_DB.Delete(&fileManager.FileQiniu{}, "id = ?", requestCoding.Id).Error
|
|
|
return err
|
|
|
}
|
|
|
+
|
|
|
+// RenameQiniuFileAndRecord 重命名七牛云文件和数据库记录
|
|
|
+func (s *ServiceFileQiniu) RenameQiniuFileAndRecord(requestCoding request.FileQiniuRequest) (err error) {
|
|
|
+ file := fileManager.FileQiniu{}
|
|
|
+ if errors.Is(global.GVA_DB.Where("id = ?", requestCoding.Id).First(&file).Error, gorm.ErrRecordNotFound) {
|
|
|
+ return errors.New("数据库中未找到该记录")
|
|
|
+ }
|
|
|
+ mac := qbox.NewMac(accessKey, secretKey)
|
|
|
+ cfg := storage.Config{
|
|
|
+ // 是否使用https域名进行资源管理
|
|
|
+ UseHTTPS: true,
|
|
|
+ }
|
|
|
+ bucketManager := storage.NewBucketManager(mac, &cfg)
|
|
|
+ bucket := bucket0
|
|
|
+ srcKey := requestCoding.QiniuKey
|
|
|
+ //处理字段
|
|
|
+ s2 := file.QiniuKey[0:strings.Index(file.QiniuKey, file.FileName)]
|
|
|
+ //global.GVA_LOG.Info(s2)
|
|
|
+ destKey := s2 + requestCoding.FileNameNew
|
|
|
+ //如果目标文件存在,是否强制覆盖,如果不覆盖,默认返回614 file exists
|
|
|
+ err = bucketManager.Move(bucket, srcKey, bucket, destKey, false)
|
|
|
+ if err != nil {
|
|
|
+ return err
|
|
|
+ }
|
|
|
+ s3 := file.QiniuAddress[0:strings.Index(file.QiniuAddress, file.FileName)]
|
|
|
+ file.QiniuAddress = s3 + requestCoding.FileNameNew
|
|
|
+ file.FileName = requestCoding.FileNameNew
|
|
|
+ file.QiniuKey = destKey
|
|
|
+ err = global.GVA_DB.Save(file).Error
|
|
|
+ return err
|
|
|
+}
|