fix: restore notifications table from dump when it already had the correct format
continuous-integration/drone/push Build is failing Details

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

View File

@ -22,6 +22,7 @@ import (
"bytes"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"io"
"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.
if table == "notifications" {
for i := range content {
decoded, err := base64.StdEncoding.DecodeString(content[i]["notification"].(string))
if err != nil {
var decoded []byte
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)
}
if err != nil && errors.Is(err, base64.CorruptInputError(0)) {
decoded = []byte(content[i]["notification"].(string))
}
content[i]["notification"] = string(decoded)
}
}