|
|
@ -2,10 +2,10 @@ package rest |
|
|
|
|
|
|
|
|
import ( |
|
|
import ( |
|
|
"github.com/jinzhu/gorm" |
|
|
"github.com/jinzhu/gorm" |
|
|
|
|
|
"path/filepath" |
|
|
|
|
|
|
|
|
"github.com/nu7hatch/gouuid" |
|
|
"github.com/nu7hatch/gouuid" |
|
|
"os" |
|
|
"os" |
|
|
"strings" |
|
|
|
|
|
"time" |
|
|
"time" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
@ -239,17 +239,16 @@ func (this *MatterDao) Delete(matter *Matter) { |
|
|
this.Delete(f) |
|
|
this.Delete(f) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//从磁盘中删除该文件夹。
|
|
|
//删除数据库中文件夹本身
|
|
|
removeError := os.Remove(CONFIG.MatterPath + matter.Path) |
|
|
|
|
|
if removeError != nil { |
|
|
|
|
|
this.logger.Error("从磁盘上删除文件夹%s出错:%s", CONFIG.MatterPath+matter.Path, removeError.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//删除文件夹本身
|
|
|
|
|
|
db := CONTEXT.DB.Delete(&matter) |
|
|
db := CONTEXT.DB.Delete(&matter) |
|
|
this.PanicError(db.Error) |
|
|
this.PanicError(db.Error) |
|
|
|
|
|
|
|
|
|
|
|
//从磁盘中删除该文件夹。
|
|
|
|
|
|
DeleteEmptyDir(matter.AbsolutePath()) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
} else { |
|
|
|
|
|
|
|
|
//删除数据库中文件记录
|
|
|
//删除数据库中文件记录
|
|
|
db := CONTEXT.DB.Delete(&matter) |
|
|
db := CONTEXT.DB.Delete(&matter) |
|
|
this.PanicError(db.Error) |
|
|
this.PanicError(db.Error) |
|
|
@ -257,25 +256,15 @@ func (this *MatterDao) Delete(matter *Matter) { |
|
|
//删除对应的缓存图片。
|
|
|
//删除对应的缓存图片。
|
|
|
this.imageCacheDao.DeleteByMatterUuid(matter.Uuid) |
|
|
this.imageCacheDao.DeleteByMatterUuid(matter.Uuid) |
|
|
|
|
|
|
|
|
filePath := CONFIG.MatterPath + matter.Path |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: do it here.
|
|
|
|
|
|
//递归找寻文件的上级目录uuid. 因为是/开头的缘故
|
|
|
|
|
|
parts := strings.Split(matter.Path, "/") |
|
|
|
|
|
dirPath := CONFIG.MatterPath + "/" + parts[1] + "/" + parts[2] + "/" + parts[3] |
|
|
|
|
|
|
|
|
|
|
|
//删除文件
|
|
|
//删除文件
|
|
|
err := os.Remove(filePath) |
|
|
err := os.Remove(matter.AbsolutePath()) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
this.logger.Error("删除磁盘上的文件出错 %s", err.Error()) |
|
|
this.logger.Error("删除磁盘上的文件出错 %s", err.Error()) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//删除这一层文件夹
|
|
|
//如果目录为空,那么一并删除
|
|
|
err = os.Remove(dirPath) |
|
|
dirPath := filepath.Dir(matter.AbsolutePath()) |
|
|
if err != nil { |
|
|
DeleteEmptyDir(dirPath) |
|
|
this.logger.Error("删除磁盘上的文件夹出错 %s", err.Error()) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -294,6 +283,7 @@ func (this *MatterDao) SizeBetweenTime(startTime time.Time, endTime time.Time) i |
|
|
db := CONTEXT.DB.Model(&Matter{}).Where("create_time >= ? AND create_time <= ?", startTime, endTime).Select("SUM(size)") |
|
|
db := CONTEXT.DB.Model(&Matter{}).Where("create_time >= ? AND create_time <= ?", startTime, endTime).Select("SUM(size)") |
|
|
this.PanicError(db.Error) |
|
|
this.PanicError(db.Error) |
|
|
row := db.Row() |
|
|
row := db.Row() |
|
|
row.Scan(&size) |
|
|
err := row.Scan(&size) |
|
|
|
|
|
this.PanicError(err) |
|
|
return size |
|
|
return size |
|
|
} |
|
|
} |
|
|
|