Add ability to revert to non-hyphenated user IDs

The first 10.7.0 build i tried used hyphens, but a later one didn't.
emails.json can now be converted between the two forms depending on what
the server uses.
This commit is contained in:
Harvey Tindall
2020-12-18 15:44:19 +00:00
parent c79f86137e
commit ee6f81b9e9
3 changed files with 54 additions and 11 deletions
+28 -4
View File
@@ -192,10 +192,34 @@ func storeJSON(path string, obj interface{}) error {
return err
}
// JF 10.7.0 added hyphens to user IDs like this and we need to upgrade email storage to match it:
// [8 chars]-[4]-[4]-[4]-[12]
// This seems consistent, but we'll grab IDs from jellyfin just in case theres some variation.
func (app *appContext) upgradeEmailStorage(old map[string]interface{}) (map[string]interface{}, int, error) {
// One build of JF 10.7.0 hyphenated to user IDs like this and we need to upgrade email storage to match it:
// One build of JF 10.7.0 hyphenated user IDs while another one later didn't. These functions will hyphenate/de-hyphenate email storage.
func hyphenate(userID string) string {
if userID[8] == '-' {
return userID
}
return userID[:8] + "-" + userID[8:12] + "-" + userID[12:16] + "-" + userID[16:20] + "-" + userID[20:]
}
func (app *appContext) deHyphenateEmailStorage(old map[string]interface{}) (map[string]interface{}, int, error) {
jfUsers, status, err := app.jf.GetUsers(false)
if status != 200 || err != nil {
return nil, status, err
}
newEmails := map[string]interface{}{}
for _, user := range jfUsers {
unHyphenated := user["Id"].(string)
hyphenated := hyphenate(unHyphenated)
email, ok := old[hyphenated]
if ok {
newEmails[unHyphenated] = email
}
}
return newEmails, status, err
}
func (app *appContext) hyphenateEmailStorage(old map[string]interface{}) (map[string]interface{}, int, error) {
jfUsers, status, err := app.jf.GetUsers(false)
if status != 200 || err != nil {
return nil, status, err