Skip to content

Commit

Permalink
Initial Ombi integration
Browse files Browse the repository at this point in the history
When enabled, an account for the user is created on both Jellyfin and
Ombi. Account defaults can be stored similarly to jf.
  • Loading branch information
hrfee committed Sep 5, 2020
1 parent 9850545 commit ba67fa7
Show file tree
Hide file tree
Showing 11 changed files with 493 additions and 30 deletions.
52 changes: 52 additions & 0 deletions api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -253,6 +254,18 @@ func (app *appContext) NewUser(gc *gin.Context) {
app.storage.emails[id] = req.Email
app.storage.storeEmails()
}
if app.config.Section("ombi").Key("enabled").MustBool(false) {
app.storage.loadOmbiTemplate()
if len(app.storage.ombi_template) != 0 {
errors, code, err := app.ombi.newUser(req.Username, req.Password, req.Email, app.storage.ombi_template)
if err != nil || code != 200 {
app.info.Printf("Failed to create Ombi user (%d): %s", code, err)
app.debug.Printf("Errors reported by Ombi: %s", strings.Join(errors, ", "))
} else {
app.info.Println("Created Ombi user")
}
}
}
gc.JSON(200, validation)
}

Expand Down Expand Up @@ -471,6 +484,30 @@ func (app *appContext) GetUsers(gc *gin.Context) {
gc.JSON(200, resp)
}

type ombiUser struct {
Name string `json:"name,omitempty"`
ID string `json:"id"`
}

func (app *appContext) OmbiUsers(gc *gin.Context) {
app.debug.Println("Ombi users requested")
users, status, err := app.ombi.getUsers()
if err != nil || status != 200 {
app.err.Printf("Failed to get users from Ombi: Code %d", status)
app.debug.Printf("Error: %s", err)
respond(500, "Couldn't get users", gc)
return
}
userlist := make([]ombiUser, len(users))
for i, data := range users {
userlist[i] = ombiUser{
Name: data["userName"].(string),
ID: data["id"].(string),
}
}
gc.JSON(200, map[string][]ombiUser{"users": userlist})
}

func (app *appContext) ModifyEmails(gc *gin.Context) {
var req map[string]string
gc.BindJSON(&req)
Expand All @@ -492,6 +529,21 @@ func (app *appContext) ModifyEmails(gc *gin.Context) {
gc.JSON(200, map[string]bool{"success": true})
}

func (app *appContext) SetOmbiDefaults(gc *gin.Context) {
var req ombiUser
gc.BindJSON(&req)
template, code, err := app.ombi.templateByID(req.ID)
if err != nil || code != 200 || len(template) == 0 {
app.err.Printf("Couldn't get user from Ombi: %d %s", code, err)
respond(500, "Couldn't get user", gc)
return
}
app.storage.ombi_template = template
fmt.Println(app.storage.ombi_path)
app.storage.storeOmbiTemplate()
gc.JSON(200, map[string]bool{"success": true})
}

type defaultsReq struct {
Username string `json:"username"`
Homescreen bool `json:"homescreen"`
Expand Down
2 changes: 1 addition & 1 deletion config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (app *appContext) loadConfig() error {
// }
key.SetValue(key.MustString(filepath.Join(app.data_path, (key.Name() + ".json"))))
}
for _, key := range []string{"user_configuration", "user_displayprefs"} {
for _, key := range []string{"user_configuration", "user_displayprefs", "ombi_template"} {
// if app.config.Section("files").Key(key).MustString("") == "" {
// key.SetValue(filepath.Join(app.data_path, (key.Name() + ".json")))
// }
Expand Down
48 changes: 44 additions & 4 deletions config/config-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"required": true,
"requires_restart": true,
"type": "text",
"value": "jf-accounts",
"value": "jfa-go",
"description": "This and below settings will show on the Jellyfin dashboard when the program connects. You may as well leave them alone."
},
"version": {
Expand All @@ -55,14 +55,14 @@
"required": true,
"requires_restart": true,
"type": "text",
"value": "jf-accounts"
"value": "jfa-go"
},
"device_id": {
"name": "Device ID",
"required": true,
"requires_restart": true,
"type": "text",
"value": "jf-accounts-{version}"
"value": "jfa-go-{version}"
}
},
"ui": {
Expand Down Expand Up @@ -398,7 +398,7 @@
"depends_true": "enabled",
"type": "text",
"value": "http://accounts.jellyf.in:8056/invite",
"description": "Base URL for jf-accounts. This is necessary because using a reverse proxy means the program has no way of knowing the URL itself."
"description": "Base URL for jfa-go. This is necessary because using a reverse proxy means the program has no way of knowing the URL itself."
}
},
"notifications": {
Expand Down Expand Up @@ -511,6 +511,38 @@
"value": "smtp password"
}
},
"ombi": {
"meta": {
"name": "Ombi Integration",
"description": "Connect to Ombi to automatically create a new user's account. You'll need to create an Ombi user template."
},
"enabled": {
"name": "Enabled",
"required": false,
"requires_restart": true,
"type": "bool",
"value": false,
"description": "Enable to create an Ombi account for new Jellyfin users"
},
"server": {
"name": "URL",
"required": false,
"requires_restart": true,
"type": "text",
"value": "localhost:5000",
"depends_true": "enabled",
"description": "Ombi server URL, including http(s)://."
},
"api_key": {
"name": "API Key",
"required": false,
"requires_restart": true,
"type": "text",
"value": "",
"depends_true": "enabled",
"description": "API Key. Get this from the first tab in Ombi settings."
}
},
"files": {
"meta": {
"name": "File Storage",
Expand All @@ -532,6 +564,14 @@
"value": "",
"description": "Location of stored email addresses (json)."
},
"ombi_template": {
"name": "Ombi user template",
"required": false,
"requires_restart": false,
"type": "text",
"value": "",
"description": "Location of stored Ombi user template."
},
"user_template": {
"name": "User Template",
"required": false,
Expand Down
55 changes: 51 additions & 4 deletions data/config-base.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"notifications",
"mailgun",
"smtp",
"ombi",
"files"
],
"jellyfin": {
Expand Down Expand Up @@ -62,7 +63,7 @@
"required": true,
"requires_restart": true,
"type": "text",
"value": "jf-accounts",
"value": "jfa-go",
"description": "This and below settings will show on the Jellyfin dashboard when the program connects. You may as well leave them alone."
},
"version": {
Expand All @@ -77,14 +78,14 @@
"required": true,
"requires_restart": true,
"type": "text",
"value": "jf-accounts"
"value": "jfa-go"
},
"device_id": {
"name": "Device ID",
"required": true,
"requires_restart": true,
"type": "text",
"value": "jf-accounts-{version}"
"value": "jfa-go-{version}"
}
},
"ui": {
Expand Down Expand Up @@ -466,7 +467,7 @@
"depends_true": "enabled",
"type": "text",
"value": "http://accounts.jellyf.in:8056/invite",
"description": "Base URL for jf-accounts. This is necessary because using a reverse proxy means the program has no way of knowing the URL itself."
"description": "Base URL for jfa-go. This is necessary because using a reverse proxy means the program has no way of knowing the URL itself."
}
},
"notifications": {
Expand Down Expand Up @@ -596,10 +597,48 @@
"value": "smtp password"
}
},
"ombi": {
"order": [
"enabled",
"server",
"api_key"
],
"meta": {
"name": "Ombi Integration",
"description": "Connect to Ombi to automatically create a new user's account. You'll need to create an Ombi user template."
},
"enabled": {
"name": "Enabled",
"required": false,
"requires_restart": true,
"type": "bool",
"value": false,
"description": "Enable to create an Ombi account for new Jellyfin users"
},
"server": {
"name": "URL",
"required": false,
"requires_restart": true,
"type": "text",
"value": "localhost:5000",
"depends_true": "enabled",
"description": "Ombi server URL."
},
"api_key": {
"name": "API Key",
"required": false,
"requires_restart": true,
"type": "text",
"value": "",
"depends_true": "enabled",
"description": "API Key. Get this from the first tab in Ombi settings."
}
},
"files": {
"order": [
"invites",
"emails",
"ombi_template",
"user_template",
"user_configuration",
"user_displayprefs",
Expand All @@ -625,6 +664,14 @@
"value": "",
"description": "Location of stored email addresses (json)."
},
"ombi_template": {
"name": "Ombi user template",
"required": false,
"requires_restart": false,
"type": "text",
"value": "",
"description": "Location of stored Ombi user template."
},
"user_template": {
"name": "User Template",
"required": false,
Expand Down

0 comments on commit ba67fa7

Please sign in to comment.