Implement proper "reset" that reads snapshots from database

This commit is contained in:
2025-07-20 11:43:25 +02:00
parent b785d24a08
commit 774ac0f0ca
3 changed files with 63 additions and 6 deletions

View File

@@ -14,6 +14,7 @@ type DB interface {
DB() *gorm.DB
Raw(sql string, args ...any) *gorm.DB
SaveFile(filePath string, fileData []byte) error
GetFile(filePath string) ([]byte, error)
}
type FileSnapshot struct {
@@ -80,3 +81,15 @@ func (db *DBWrapper) SaveFile(filePath string, fileData []byte) error {
FileData: fileData,
}).Error
}
func (db *DBWrapper) GetFile(filePath string) ([]byte, error) {
log := cylogger.Default.WithPrefix(fmt.Sprintf("GetFile: %q", filePath))
log.Debug("Getting file from database")
var fileSnapshot FileSnapshot
err := db.db.Model(&FileSnapshot{}).Where("file_path = ?", filePath).First(&fileSnapshot).Error
if err != nil {
return nil, err
}
log.Debug("File found in database")
return fileSnapshot.FileData, nil
}