2020-04-07 12:51:01 +02:00
|
|
|
package query
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
|
|
)
|
|
|
|
|
|
|
|
// SetDownloadFileID updates the local file id for remote downloads.
|
2020-05-08 15:41:01 +02:00
|
|
|
func SetDownloadFileID(filename string, fileId uint) error {
|
2020-04-07 12:51:01 +02:00
|
|
|
if len(filename) == 0 {
|
2022-01-05 11:40:44 +01:00
|
|
|
return errors.New("sync: cannot update, filename empty")
|
2020-04-07 12:51:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: Might break on Windows
|
|
|
|
if filename[0] != os.PathSeparator {
|
|
|
|
filename = string(os.PathSeparator) + filename
|
|
|
|
}
|
|
|
|
|
2020-05-08 15:41:01 +02:00
|
|
|
result := Db().Model(entity.FileSync{}).
|
2020-04-07 12:51:01 +02:00
|
|
|
Where("remote_name = ? AND status = ? AND file_id = 0", filename, entity.FileSyncDownloaded).
|
|
|
|
Update("file_id", fileId)
|
|
|
|
|
|
|
|
return result.Error
|
|
|
|
}
|