mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 03:26:37 +08:00
97b3a7bd7f
Add account-level multi-line configuration for emby_remote mounts. Lines are stored in strm_accounts.config as a urls JSON array with backward compatibility for the legacy single url field. The backend automatically fails over to the next line on connection errors and persists the working active_line index. Frontend: multi-line editor on Emby mount page and STRM account dialog with add/remove/reorder, line names, and URL validation. Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: truewhile <truewhile@users.noreply.github.com>
67 lines
1.9 KiB
Go
67 lines
1.9 KiB
Go
package service
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestParseEmbyRemoteLinesLegacyURL(t *testing.T) {
|
|
lines, active, err := ParseEmbyRemoteLines(map[string]string{
|
|
"url": "http://192.168.1.10:8096/",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("ParseEmbyRemoteLines() error = %v", err)
|
|
}
|
|
if active != 0 || len(lines) != 1 || lines[0].URL != "http://192.168.1.10:8096" {
|
|
t.Fatalf("unexpected lines: %#v active=%d", lines, active)
|
|
}
|
|
}
|
|
|
|
func TestParseEmbyRemoteLinesMulti(t *testing.T) {
|
|
lines, active, err := ParseEmbyRemoteLines(map[string]string{
|
|
"urls": `[{"name":"内网","url":"http://10.0.0.8:8096"},{"name":"外网","url":"https://emby.example.com"}]`,
|
|
"active_line": "1",
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("ParseEmbyRemoteLines() error = %v", err)
|
|
}
|
|
if active != 1 || len(lines) != 2 {
|
|
t.Fatalf("unexpected lines: %#v active=%d", lines, active)
|
|
}
|
|
if lines[1].Name != "外网" || lines[1].URL != "https://emby.example.com" {
|
|
t.Fatalf("unexpected second line: %#v", lines[1])
|
|
}
|
|
}
|
|
|
|
func TestEncodeEmbyRemoteLines(t *testing.T) {
|
|
jsonText, primary, err := EncodeEmbyRemoteLines([]EmbyRemoteLine{
|
|
{Name: "内网", URL: "http://10.0.0.8:8096/"},
|
|
{Name: "外网", URL: "https://emby.example.com"},
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("EncodeEmbyRemoteLines() error = %v", err)
|
|
}
|
|
if primary != "http://10.0.0.8:8096" {
|
|
t.Fatalf("primary = %q", primary)
|
|
}
|
|
lines, active, err := ParseEmbyRemoteLines(map[string]string{"urls": jsonText})
|
|
if err != nil || active != 0 || len(lines) != 2 {
|
|
t.Fatalf("roundtrip failed: %#v active=%d err=%v", lines, active, err)
|
|
}
|
|
}
|
|
|
|
func TestEmbyRemoteServiceLineOrder(t *testing.T) {
|
|
svc := &EmbyRemoteService{}
|
|
cfg := &EmbyRemoteConfig{
|
|
Lines: []EmbyRemoteLine{
|
|
{URL: "http://a"},
|
|
{URL: "http://b"},
|
|
{URL: "http://c"},
|
|
},
|
|
ActiveLine: 1,
|
|
}
|
|
order := svc.lineOrder(cfg)
|
|
if len(order) != 3 || order[0] != 1 || order[1] != 0 || order[2] != 2 {
|
|
t.Fatalf("unexpected order: %#v", order)
|
|
}
|
|
}
|