feat(db, client): split work into separate files and finished database

This commit is contained in:
DarthMooMancer committed 2026-11-24 19:03:22 -05:00
1 parent 29e94a679d
commit 4bfb5bb19a
6 files changed
+383 -240

No files matched your search

+69
View File
@@ -0,0 +1,69 @@
package main
import (
"crypto/md5"
"crypto/rand"
"encoding/hex"
"math/big"
"net/http"
"net/url"
"strconv"
)
type NavidromeClient struct {
BaseURL string
Username string
Password string
APIVersion string
ClientName string
HTTP *http.Client
}
func (c *NavidromeClient) newSaltKey() (string, error) {
n, err := rand.Int(rand.Reader, big.NewInt(900000))
if err != nil {
return "", err
}
return strconv.Itoa(int(n.Int64() + 100000)), nil
}
func (c *NavidromeClient) newTokenKey(salt string, password string) string {
sum := md5.Sum([]byte(password + salt))
return hex.EncodeToString(sum[:])
}
func (c *NavidromeClient) newURLRequest(endpoint string, extras url.Values) (string, error) {
salt, err := c.newSaltKey()
if err != nil {
return "", err
}
token := c.newTokenKey(salt, c.Password)
params := url.Values{}
params.Set("u", c.Username)
params.Set("t", token)
params.Set("s", salt)
params.Set("v", c.APIVersion)
params.Set("c", c.ClientName)
params.Set("f", "json")
for key, value := range extras {
for _, val := range value {
if val != "" {
params.Set(key, val)
}
}
}
base, err := url.Parse(c.BaseURL)
if err != nil {
return "", err
}
base.Path = "/rest/" + endpoint
base.RawQuery = params.Encode()
return base.String(), nil
}