mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
add http auth
This commit is contained in:
32
server/web/auth/auth.go
Normal file
32
server/web/auth/auth.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"server/settings"
|
||||
)
|
||||
|
||||
func SetupAuth(engine *gin.Engine) *gin.RouterGroup {
|
||||
if !settings.HttpAuth {
|
||||
return nil
|
||||
}
|
||||
accs := getAccounts()
|
||||
if accs == nil {
|
||||
return nil
|
||||
}
|
||||
return engine.Group("/", gin.BasicAuth(accs))
|
||||
}
|
||||
|
||||
func getAccounts() gin.Accounts {
|
||||
buf, err := ioutil.ReadFile(filepath.Join(settings.Path, "accs.db"))
|
||||
if err != nil {
|
||||
return nil
|
||||
}
|
||||
var accs gin.Accounts
|
||||
json.Unmarshal(buf, &accs)
|
||||
return accs
|
||||
}
|
||||
Reference in New Issue
Block a user