mirror of
https://github.com/hrfee/jfa-go.git
synced 2024-12-22 17:10:10 +00:00
use newJellyfin instead of constructor method
This commit is contained in:
parent
072776c15f
commit
6e3d5dac19
5
jfapi.go
5
jfapi.go
@ -54,7 +54,8 @@ func (jf *Jellyfin) timeoutHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jf *Jellyfin) init(server, client, version, device, deviceId string) error {
|
func newJellyfin(server, client, version, device, deviceId string) (*Jellyfin, error) {
|
||||||
|
jf := &Jellyfin{}
|
||||||
jf.server = server
|
jf.server = server
|
||||||
jf.client = client
|
jf.client = client
|
||||||
jf.version = version
|
jf.version = version
|
||||||
@ -84,7 +85,7 @@ func (jf *Jellyfin) init(server, client, version, device, deviceId string) error
|
|||||||
}
|
}
|
||||||
jf.cacheLength = 30
|
jf.cacheLength = 30
|
||||||
jf.cacheExpiry = time.Now()
|
jf.cacheExpiry = time.Now()
|
||||||
return nil
|
return jf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (jf *Jellyfin) authenticate(username, password string) (map[string]interface{}, int, error) {
|
func (jf *Jellyfin) authenticate(username, password string) (map[string]interface{}, int, error) {
|
||||||
|
8
main.go
8
main.go
@ -43,8 +43,8 @@ type appContext struct {
|
|||||||
jellyfinLogin bool
|
jellyfinLogin bool
|
||||||
users []User
|
users []User
|
||||||
invalidTokens []string
|
invalidTokens []string
|
||||||
jf Jellyfin
|
jf *Jellyfin
|
||||||
authJf Jellyfin
|
authJf *Jellyfin
|
||||||
datePattern string
|
datePattern string
|
||||||
timePattern string
|
timePattern string
|
||||||
storage Storage
|
storage Storage
|
||||||
@ -266,14 +266,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
server := app.config.Section("jellyfin").Key("server").String()
|
server := app.config.Section("jellyfin").Key("server").String()
|
||||||
app.jf.init(server, "jfa-go", app.version, "hrfee-arch", "hrfee-arch")
|
app.jf, _ = newJellyfin(server, "jfa-go", app.version, "hrfee-arch", "hrfee-arch")
|
||||||
var status int
|
var status int
|
||||||
_, status, err = app.jf.authenticate(app.config.Section("jellyfin").Key("username").String(), app.config.Section("jellyfin").Key("password").String())
|
_, status, err = app.jf.authenticate(app.config.Section("jellyfin").Key("username").String(), app.config.Section("jellyfin").Key("password").String())
|
||||||
if status != 200 || err != nil {
|
if status != 200 || err != nil {
|
||||||
app.err.Fatalf("Failed to authenticate with Jellyfin @ %s: Code %d", server, status)
|
app.err.Fatalf("Failed to authenticate with Jellyfin @ %s: Code %d", server, status)
|
||||||
}
|
}
|
||||||
app.info.Printf("Authenticated with %s", server)
|
app.info.Printf("Authenticated with %s", server)
|
||||||
app.authJf.init(server, "jfa-go", app.version, "auth", "auth")
|
app.authJf, _ = newJellyfin(server, "jfa-go", app.version, "auth", "auth")
|
||||||
|
|
||||||
app.loadStrftime()
|
app.loadStrftime()
|
||||||
|
|
||||||
|
3
setup.go
3
setup.go
@ -13,8 +13,7 @@ type testReq struct {
|
|||||||
func (app *appContext) TestJF(gc *gin.Context) {
|
func (app *appContext) TestJF(gc *gin.Context) {
|
||||||
var req testReq
|
var req testReq
|
||||||
gc.BindJSON(&req)
|
gc.BindJSON(&req)
|
||||||
tempjf := Jellyfin{}
|
tempjf, _ := newJellyfin(req.Host, "jfa-go-setup", app.version, "auth", "auth")
|
||||||
tempjf.init(req.Host, "jfa-go-setup", app.version, "auth", "auth")
|
|
||||||
tempjf.noFail = true
|
tempjf.noFail = true
|
||||||
_, status, err := tempjf.authenticate(req.Username, req.Password)
|
_, status, err := tempjf.authenticate(req.Username, req.Password)
|
||||||
if !(status == 200 || status == 204) || err != nil {
|
if !(status == 200 || status == 204) || err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user