mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-28 03:50:10 +00:00
Compare commits
2 Commits
d7fcfe9416
...
1707c8c1f9
Author | SHA1 | Date | |
---|---|---|---|
1707c8c1f9 | |||
e0c4d7c545 |
10
jfapi.go
10
jfapi.go
@ -130,7 +130,7 @@ func (jf *Jellyfin) authenticate(username, password string) (map[string]interfac
|
|||||||
jf.accessToken = respData["AccessToken"].(string)
|
jf.accessToken = respData["AccessToken"].(string)
|
||||||
user := respData["User"].(map[string]interface{})
|
user := respData["User"].(map[string]interface{})
|
||||||
jf.userId = respData["User"].(map[string]interface{})["Id"].(string)
|
jf.userId = respData["User"].(map[string]interface{})["Id"].(string)
|
||||||
jf.auth = fmt.Sprintf("MediaBrowser Client=%s, Device=%s, DeviceId=%s, Version=%s, Token=%s", jf.client, jf.device, jf.deviceId, jf.version, jf.accessToken)
|
jf.auth = fmt.Sprintf("MediaBrowser Client=\"%s\", Device=\"%s\", DeviceId=\"%s\", Version=\"%s\", Token=\"%s\"", jf.client, jf.device, jf.deviceId, jf.version, jf.accessToken)
|
||||||
jf.header["X-Emby-Authorization"] = jf.auth
|
jf.header["X-Emby-Authorization"] = jf.auth
|
||||||
jf.authenticated = true
|
jf.authenticated = true
|
||||||
return user, resp.StatusCode, nil
|
return user, resp.StatusCode, nil
|
||||||
@ -213,11 +213,11 @@ func (jf *Jellyfin) getUsers(public bool) ([]map[string]interface{}, int, error)
|
|||||||
var err error
|
var err error
|
||||||
if time.Now().After(jf.cacheExpiry) {
|
if time.Now().After(jf.cacheExpiry) {
|
||||||
if public {
|
if public {
|
||||||
url := fmt.Sprintf("%s/emby/Users/Public", jf.server)
|
url := fmt.Sprintf("%s/users/public", jf.server)
|
||||||
data, status, err = jf._getReader(url, nil)
|
data, status, err = jf._getReader(url, nil)
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
url := fmt.Sprintf("%s/emby/Users", jf.server)
|
url := fmt.Sprintf("%s/users", jf.server)
|
||||||
data, status, err = jf._getReader(url, jf.loginParams)
|
data, status, err = jf._getReader(url, jf.loginParams)
|
||||||
}
|
}
|
||||||
if err != nil || status != 200 {
|
if err != nil || status != 200 {
|
||||||
@ -268,7 +268,7 @@ func (jf *Jellyfin) userById(userId string, public bool) (map[string]interface{}
|
|||||||
var data io.Reader
|
var data io.Reader
|
||||||
var status int
|
var status int
|
||||||
var err error
|
var err error
|
||||||
url := fmt.Sprintf("%s/emby/Users/%s", jf.server, userId)
|
url := fmt.Sprintf("%s/users/%s", jf.server, userId)
|
||||||
data, status, err = jf._getReader(url, jf.loginParams)
|
data, status, err = jf._getReader(url, jf.loginParams)
|
||||||
if err != nil || status != 200 {
|
if err != nil || status != 200 {
|
||||||
return nil, status, err
|
return nil, status, err
|
||||||
@ -279,7 +279,7 @@ func (jf *Jellyfin) userById(userId string, public bool) (map[string]interface{}
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (jf *Jellyfin) newUser(username, password string) (map[string]interface{}, int, error) {
|
func (jf *Jellyfin) newUser(username, password string) (map[string]interface{}, int, error) {
|
||||||
url := fmt.Sprintf("%s/emby/Users/New", jf.server)
|
url := fmt.Sprintf("%s/Users/New", jf.server)
|
||||||
stringData := map[string]string{
|
stringData := map[string]string{
|
||||||
"Name": username,
|
"Name": username,
|
||||||
"Password": password,
|
"Password": password,
|
||||||
|
35
main.go
35
main.go
@ -17,6 +17,7 @@ import (
|
|||||||
"os/signal"
|
"os/signal"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gin-contrib/pprof"
|
"github.com/gin-contrib/pprof"
|
||||||
@ -106,8 +107,33 @@ var (
|
|||||||
DATA, CONFIG, HOST *string
|
DATA, CONFIG, HOST *string
|
||||||
PORT *int
|
PORT *int
|
||||||
DEBUG *bool
|
DEBUG *bool
|
||||||
|
TEST bool
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func test(app *appContext) {
|
||||||
|
fmt.Printf("\n\n----\n\n")
|
||||||
|
settings := map[string]interface{}{
|
||||||
|
"server": app.jf.server,
|
||||||
|
"server version": app.jf.serverInfo.Version,
|
||||||
|
"server name": app.jf.serverInfo.Name,
|
||||||
|
"authenticated?": app.jf.authenticated,
|
||||||
|
"access token": app.jf.accessToken,
|
||||||
|
"username": app.jf.username,
|
||||||
|
}
|
||||||
|
for n, v := range settings {
|
||||||
|
fmt.Println(n, ":", v)
|
||||||
|
}
|
||||||
|
users, status, err := app.jf.getUsers(false)
|
||||||
|
fmt.Printf("getUsers: code %d err %s maplength %d\n", status, err, len(users))
|
||||||
|
fmt.Printf("View output? [y/n]: ")
|
||||||
|
var choice string
|
||||||
|
fmt.Scanln(&choice)
|
||||||
|
if strings.Contains(choice, "y") {
|
||||||
|
out, err := json.MarshalIndent(users, "", " ")
|
||||||
|
fmt.Print(string(out), err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func start(asDaemon, firstCall bool) {
|
func start(asDaemon, firstCall bool) {
|
||||||
// app encompasses essentially all useful functions.
|
// app encompasses essentially all useful functions.
|
||||||
app := new(appContext)
|
app := new(appContext)
|
||||||
@ -361,6 +387,11 @@ func start(asDaemon, firstCall bool) {
|
|||||||
}
|
}
|
||||||
app.validator.init(validatorConf)
|
app.validator.init(validatorConf)
|
||||||
|
|
||||||
|
if TEST {
|
||||||
|
test(app)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
inviteDaemon := NewRepeater(time.Duration(60*time.Second), app)
|
inviteDaemon := NewRepeater(time.Duration(60*time.Second), app)
|
||||||
go inviteDaemon.Run()
|
go inviteDaemon.Run()
|
||||||
|
|
||||||
@ -371,7 +402,6 @@ func start(asDaemon, firstCall bool) {
|
|||||||
debugMode = false
|
debugMode = false
|
||||||
address = "0.0.0.0:8056"
|
address = "0.0.0.0:8056"
|
||||||
}
|
}
|
||||||
|
|
||||||
app.info.Println("Loading routes")
|
app.info.Println("Loading routes")
|
||||||
if debugMode {
|
if debugMode {
|
||||||
gin.SetMode(gin.DebugMode)
|
gin.SetMode(gin.DebugMode)
|
||||||
@ -475,6 +505,9 @@ func main() {
|
|||||||
}
|
}
|
||||||
SOCK = filepath.Join(folder, SOCK)
|
SOCK = filepath.Join(folder, SOCK)
|
||||||
fmt.Println("Socket:", SOCK)
|
fmt.Println("Socket:", SOCK)
|
||||||
|
if flagPassed("test") {
|
||||||
|
TEST = true
|
||||||
|
}
|
||||||
if flagPassed("start") {
|
if flagPassed("start") {
|
||||||
args := []string{}
|
args := []string{}
|
||||||
for i, f := range os.Args {
|
for i, f := range os.Args {
|
||||||
|
@ -66,11 +66,13 @@ func pwrMonitor(app *appContext, watcher *fsnotify.Watcher) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
app.storage.loadEmails()
|
app.storage.loadEmails()
|
||||||
address, ok := app.storage.emails[user["Id"].(string)].(string)
|
var address string
|
||||||
if !ok {
|
addr, ok := app.storage.emails[user["Id"].(string)]
|
||||||
|
if !ok || addr == nil {
|
||||||
app.err.Printf("Couldn't find email for user \"%s\". Make sure it's set", pwr.Username)
|
app.err.Printf("Couldn't find email for user \"%s\". Make sure it's set", pwr.Username)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
address = addr.(string)
|
||||||
msg, err := app.email.constructReset(pwr, app)
|
msg, err := app.email.constructReset(pwr, app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
app.err.Printf("Failed to construct password reset email for %s", pwr.Username)
|
app.err.Printf("Failed to construct password reset email for %s", pwr.Username)
|
||||||
|
Loading…
Reference in New Issue
Block a user