fix: restore notifications table from dump when it already had the correct format

This commit is contained in:
kolaente 2022-12-01 17:33:00 +01:00
parent e27cd9b336
commit 8c67be558f
Signed by untrusted user: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 8 additions and 2 deletions

View File

@ -22,6 +22,7 @@ import (
"bytes" "bytes"
"encoding/base64" "encoding/base64"
"encoding/json" "encoding/json"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -144,11 +145,16 @@ func Restore(filename string) error {
// FIXME: There has to be a general way to do this but this works for now. // FIXME: There has to be a general way to do this but this works for now.
if table == "notifications" { if table == "notifications" {
for i := range content { for i := range content {
decoded, err := base64.StdEncoding.DecodeString(content[i]["notification"].(string)) var decoded []byte
if err != nil { decoded, err = base64.StdEncoding.DecodeString(content[i]["notification"].(string))
if err != nil && !errors.Is(err, base64.CorruptInputError(0)) {
return fmt.Errorf("could not decode notification %s: %w", content[i]["notification"], err) return fmt.Errorf("could not decode notification %s: %w", content[i]["notification"], err)
} }
if err != nil && errors.Is(err, base64.CorruptInputError(0)) {
decoded = []byte(content[i]["notification"].(string))
}
content[i]["notification"] = string(decoded) content[i]["notification"] = string(decoded)
} }
} }