mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-28 20:10:11 +00:00
Compare commits
2 Commits
5702e8012c
...
cf94fdb2f0
Author | SHA1 | Date | |
---|---|---|---|
cf94fdb2f0 | |||
4864c6c53c |
42
api-ombi.go
42
api-ombi.go
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/hrfee/mediabrowser"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (app *appContext) getOmbiUser(jfID string) (map[string]interface{}, int, error) {
|
func (app *appContext) getOmbiUser(jfID string) (map[string]interface{}, int, error) {
|
||||||
@ -29,7 +30,31 @@ func (app *appContext) getOmbiUser(jfID string) (map[string]interface{}, int, er
|
|||||||
return ombiUser, code, err
|
return ombiUser, code, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nil, 400, fmt.Errorf("Couldn't find user")
|
return nil, 400, fmt.Errorf("couldn't find user")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Returns a user with the given name who has been imported from Jellyfin/Emby by Ombi
|
||||||
|
func (app *appContext) getOmbiImportedUser(name string) (map[string]interface{}, int, error) {
|
||||||
|
// Ombi User Types: 3/4 = Emby, 5 = Jellyfin
|
||||||
|
ombiUsers, code, err := app.ombi.GetUsers()
|
||||||
|
if err != nil || code != 200 {
|
||||||
|
return nil, code, err
|
||||||
|
}
|
||||||
|
for _, ombiUser := range ombiUsers {
|
||||||
|
if ombiUser["userName"].(string) == name {
|
||||||
|
uType, ok := ombiUser["userType"].(int)
|
||||||
|
if !ok { // Don't know if Ombi somehow allows duplicate usernames
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if serverType == mediabrowser.JellyfinServer && uType != 5 { // Jellyfin
|
||||||
|
continue
|
||||||
|
} else if uType != 3 && uType != 4 { // Emby
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return ombiUser, code, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil, 400, fmt.Errorf("couldn't find user")
|
||||||
}
|
}
|
||||||
|
|
||||||
// @Summary Get a list of Ombi users.
|
// @Summary Get a list of Ombi users.
|
||||||
@ -107,3 +132,18 @@ func (app *appContext) DeleteOmbiProfile(gc *gin.Context) {
|
|||||||
app.storage.SetProfileKey(profileName, profile)
|
app.storage.SetProfileKey(profileName, profile)
|
||||||
respondBool(204, true, gc)
|
respondBool(204, true, gc)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (app *appContext) applyOmbiProfile(user map[string]interface{}, profile map[string]interface{}) (status int, err error) {
|
||||||
|
for k, v := range profile {
|
||||||
|
switch v.(type) {
|
||||||
|
case map[string]interface{}, []interface{}:
|
||||||
|
user[k] = v
|
||||||
|
default:
|
||||||
|
if v != user[k] {
|
||||||
|
user[k] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
status, err = app.ombi.ModifyUser(user)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
73
api-users.go
73
api-users.go
@ -377,30 +377,47 @@ func (app *appContext) newUser(req newUserDTO, confirmed bool) (f errorFunc, suc
|
|||||||
if profile.Ombi != nil && len(profile.Ombi) != 0 {
|
if profile.Ombi != nil && len(profile.Ombi) != 0 {
|
||||||
template := profile.Ombi
|
template := profile.Ombi
|
||||||
errors, code, err := app.ombi.NewUser(req.Username, req.Password, req.Email, template)
|
errors, code, err := app.ombi.NewUser(req.Username, req.Password, req.Email, template)
|
||||||
|
accountExists := false
|
||||||
|
var ombiUser map[string]interface{}
|
||||||
if err != nil || code != 200 {
|
if err != nil || code != 200 {
|
||||||
app.info.Printf("Failed to create Ombi user (%d): %s", code, err)
|
// Check if on the off chance, Ombi's user importer has already added the account.
|
||||||
app.debug.Printf("Errors reported by Ombi: %s", strings.Join(errors, ", "))
|
ombiUser, status, err = app.getOmbiImportedUser(req.Username)
|
||||||
} else {
|
if status == 200 && err == nil {
|
||||||
app.info.Println("Created Ombi user")
|
app.info.Println("Found existing Ombi user, applying changes")
|
||||||
if discordVerified || telegramVerified {
|
accountExists = true
|
||||||
ombiUser, status, err := app.getOmbiUser(id)
|
template["password"] = req.Password
|
||||||
|
status, err = app.applyOmbiProfile(ombiUser, template)
|
||||||
if status != 200 || err != nil {
|
if status != 200 || err != nil {
|
||||||
app.err.Printf("Failed to get Ombi user (%d): %v", status, err)
|
app.err.Printf("Failed to modify existing Ombi user (%d): %v\n", status, err)
|
||||||
} else {
|
}
|
||||||
dID := ""
|
} else {
|
||||||
tUser := ""
|
app.info.Printf("Failed to create Ombi user (%d): %s", code, err)
|
||||||
if discordVerified {
|
app.debug.Printf("Errors reported by Ombi: %s", strings.Join(errors, ", "))
|
||||||
dID = discordUser.ID
|
}
|
||||||
}
|
} else {
|
||||||
if telegramVerified {
|
ombiUser, status, err = app.getOmbiUser(id)
|
||||||
u, _ := app.storage.GetTelegramKey(user.ID)
|
if status != 200 || err != nil {
|
||||||
tUser = u.Username
|
app.err.Printf("Failed to get Ombi user (%d): %v", status, err)
|
||||||
}
|
} else {
|
||||||
resp, status, err := app.ombi.SetNotificationPrefs(ombiUser, dID, tUser)
|
app.info.Println("Created Ombi user")
|
||||||
if !(status == 200 || status == 204) || err != nil {
|
accountExists = true
|
||||||
app.err.Printf("Failed to link Telegram/Discord to Ombi (%d): %v", status, err)
|
}
|
||||||
app.debug.Printf("Response: %v", resp)
|
}
|
||||||
}
|
if accountExists {
|
||||||
|
if discordVerified || telegramVerified {
|
||||||
|
dID := ""
|
||||||
|
tUser := ""
|
||||||
|
if discordVerified {
|
||||||
|
dID = discordUser.ID
|
||||||
|
}
|
||||||
|
if telegramVerified {
|
||||||
|
u, _ := app.storage.GetTelegramKey(user.ID)
|
||||||
|
tUser = u.Username
|
||||||
|
}
|
||||||
|
resp, status, err := app.ombi.SetNotificationPrefs(ombiUser, dID, tUser)
|
||||||
|
if !(status == 200 || status == 204) || err != nil {
|
||||||
|
app.err.Printf("Failed to link Telegram/Discord to Ombi (%d): %v", status, err)
|
||||||
|
app.debug.Printf("Response: %v", resp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1214,17 +1231,7 @@ func (app *appContext) ApplySettings(gc *gin.Context) {
|
|||||||
// newUser["userName"] = user["userName"]
|
// newUser["userName"] = user["userName"]
|
||||||
// newUser["alias"] = user["alias"]
|
// newUser["alias"] = user["alias"]
|
||||||
// newUser["emailAddress"] = user["emailAddress"]
|
// newUser["emailAddress"] = user["emailAddress"]
|
||||||
for k, v := range ombi {
|
status, err = app.applyOmbiProfile(user, ombi)
|
||||||
switch v.(type) {
|
|
||||||
case map[string]interface{}, []interface{}:
|
|
||||||
user[k] = v
|
|
||||||
default:
|
|
||||||
if v != user[k] {
|
|
||||||
user[k] = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
status, err = app.ombi.ModifyUser(user)
|
|
||||||
if status != 200 || err != nil {
|
if status != 200 || err != nil {
|
||||||
errorString += fmt.Sprintf("Apply %d: %v ", status, err)
|
errorString += fmt.Sprintf("Apply %d: %v ", status, err)
|
||||||
}
|
}
|
||||||
|
2
api.go
2
api.go
@ -182,7 +182,7 @@ func (app *appContext) ResetSetPassword(gc *gin.Context) {
|
|||||||
}
|
}
|
||||||
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
if app.config.Section("ombi").Key("enabled").MustBool(false) {
|
||||||
// Silently fail for changing ombi passwords
|
// Silently fail for changing ombi passwords
|
||||||
if status != 200 || err != nil {
|
if (status != 200 && status != 204) || err != nil {
|
||||||
app.err.Printf("Failed to get user \"%s\" from jellyfin/emby (%d): %v", username, status, err)
|
app.err.Printf("Failed to get user \"%s\" from jellyfin/emby (%d): %v", username, status, err)
|
||||||
respondBool(200, true, gc)
|
respondBool(200, true, gc)
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user