feat: 移动文件后更新 media_info 的 file_path 为新路径
This commit is contained in:
@@ -198,6 +198,27 @@ func (s *Store) ClearScanLog() error {
|
||||
return err
|
||||
}
|
||||
|
||||
// UpdateMediaFilePaths 批量更新 media_info 的 file_path。
|
||||
// moved 的 key 是源路径,value 是新路径。
|
||||
func (s *Store) UpdateMediaFilePaths(moved map[string]string) error {
|
||||
if s == nil || s.engine == nil || len(moved) == 0 {
|
||||
return nil
|
||||
}
|
||||
sess := s.engine.NewSession()
|
||||
defer sess.Close()
|
||||
if err := sess.Begin(); err != nil {
|
||||
return err
|
||||
}
|
||||
for oldPath, newPath := range moved {
|
||||
if _, err := sess.Where("file_path = ?", oldPath).
|
||||
Update(&MediaInfo{FilePath: newPath}); err != nil {
|
||||
_ = sess.Rollback()
|
||||
return err
|
||||
}
|
||||
}
|
||||
return sess.Commit()
|
||||
}
|
||||
|
||||
// ============================ 媒体记录的新增/更新 ============================
|
||||
|
||||
// SaveMedia 保存/更新一条媒体记录:按 MD5 找,有就更新,没有就新增。
|
||||
|
||||
Reference in New Issue
Block a user