mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 21:04:37 +03:00
Migrate vtt contents when hash changes (#2554)
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
package scene
|
package scene
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
@@ -35,13 +37,14 @@ func MigrateHash(p *paths.Paths, oldHash string, newHash string) {
|
|||||||
newPath = scenePaths.GetTranscodePath(newHash)
|
newPath = scenePaths.GetTranscodePath(newHash)
|
||||||
migrateSceneFiles(oldPath, newPath)
|
migrateSceneFiles(oldPath, newPath)
|
||||||
|
|
||||||
oldPath = scenePaths.GetSpriteVttFilePath(oldHash)
|
oldVttPath := scenePaths.GetSpriteVttFilePath(oldHash)
|
||||||
newPath = scenePaths.GetSpriteVttFilePath(newHash)
|
newVttPath := scenePaths.GetSpriteVttFilePath(newHash)
|
||||||
migrateSceneFiles(oldPath, newPath)
|
migrateSceneFiles(oldVttPath, newVttPath)
|
||||||
|
|
||||||
oldPath = scenePaths.GetSpriteImageFilePath(oldHash)
|
oldPath = scenePaths.GetSpriteImageFilePath(oldHash)
|
||||||
newPath = scenePaths.GetSpriteImageFilePath(newHash)
|
newPath = scenePaths.GetSpriteImageFilePath(newHash)
|
||||||
migrateSceneFiles(oldPath, newPath)
|
migrateSceneFiles(oldPath, newPath)
|
||||||
|
migrateVttFile(newVttPath, oldPath, newPath)
|
||||||
|
|
||||||
oldPath = scenePaths.GetInteractiveHeatmapPath(oldHash)
|
oldPath = scenePaths.GetInteractiveHeatmapPath(oldHash)
|
||||||
newPath = scenePaths.GetInteractiveHeatmapPath(newHash)
|
newPath = scenePaths.GetInteractiveHeatmapPath(newHash)
|
||||||
@@ -62,3 +65,22 @@ func migrateSceneFiles(oldName, newName string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// #2481: migrate vtt file contents in addition to renaming
|
||||||
|
func migrateVttFile(vttPath, oldSpritePath, newSpritePath string) {
|
||||||
|
contents, err := ioutil.ReadFile(vttPath)
|
||||||
|
if err != nil {
|
||||||
|
logger.Errorf("Error reading %s for vtt migration: %v", vttPath, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
oldSpriteBasename := filepath.Base(oldSpritePath)
|
||||||
|
newSpriteBasename := filepath.Base(newSpritePath)
|
||||||
|
|
||||||
|
contents = bytes.ReplaceAll(contents, []byte(oldSpriteBasename), []byte(newSpriteBasename))
|
||||||
|
|
||||||
|
if err := ioutil.WriteFile(vttPath, contents, 0644); err != nil {
|
||||||
|
logger.Errorf("Error writing %s for vtt migration: %v", vttPath, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user