Add go2rtc module, test/config/urls pages, Frigate config fixes
This commit is contained in:
+12
-4
@@ -26,9 +26,17 @@ func Generate(req *Request) (*Response, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if strings.TrimSpace(req.ExistingConfig) == "" {
|
||||
existing := strings.TrimSpace(req.ExistingConfig)
|
||||
|
||||
// generate from scratch if no config or config has no go2rtc streams section
|
||||
if existing == "" || !strings.Contains(existing, "go2rtc:") {
|
||||
config := newConfig(info, req)
|
||||
return &Response{Config: config, Diff: fullDiff(config)}, nil
|
||||
lines := strings.Count(config, "\n") + 1
|
||||
added := make([]int, lines)
|
||||
for i := range added {
|
||||
added[i] = i + 1
|
||||
}
|
||||
return &Response{Config: config, Added: added}, nil
|
||||
}
|
||||
|
||||
return addToConfig(req.ExistingConfig, info, req)
|
||||
@@ -124,7 +132,7 @@ func newConfig(info *cameraInfo, req *Request) string {
|
||||
var b strings.Builder
|
||||
|
||||
b.WriteString("mqtt:\n enabled: false\n\n")
|
||||
b.WriteString("record:\n enabled: true\n retain:\n days: 7\n mode: motion\n\n")
|
||||
b.WriteString("record:\n enabled: true\n\n")
|
||||
|
||||
b.WriteString("go2rtc:\n streams:\n")
|
||||
writeStreamLines(&b, info)
|
||||
@@ -132,7 +140,7 @@ func newConfig(info *cameraInfo, req *Request) string {
|
||||
b.WriteString("cameras:\n")
|
||||
writeCameraBlock(&b, info, req)
|
||||
|
||||
b.WriteString("version: 0.18-0\n")
|
||||
b.WriteString("version: 0.17-0\n")
|
||||
return b.String()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
package generate
|
||||
|
||||
import "strings"
|
||||
|
||||
func fullDiff(config string) []DiffLine {
|
||||
lines := strings.Split(config, "\n")
|
||||
diff := make([]DiffLine, len(lines))
|
||||
for i, line := range lines {
|
||||
diff[i] = DiffLine{Line: i + 1, Text: line, Type: "added"}
|
||||
}
|
||||
return diff
|
||||
}
|
||||
|
||||
func diffWithContext(lines []string, added map[int]bool, ctx int) []DiffLine {
|
||||
visible := make(map[int]bool)
|
||||
for idx := range added {
|
||||
for c := -ctx; c <= ctx; c++ {
|
||||
if j := idx + c; j >= 0 && j < len(lines) {
|
||||
visible[j] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var diff []DiffLine
|
||||
for i, line := range lines {
|
||||
if !visible[i] {
|
||||
continue
|
||||
}
|
||||
t := "context"
|
||||
if added[i] {
|
||||
t = "added"
|
||||
}
|
||||
diff = append(diff, DiffLine{Line: i + 1, Text: line, Type: t})
|
||||
}
|
||||
return diff
|
||||
}
|
||||
@@ -65,8 +65,15 @@ func addToConfig(existing string, info *cameraInfo, req *Request) (*Response, er
|
||||
result = append(result, rest[split:]...)
|
||||
|
||||
config := strings.Join(result, "\n")
|
||||
diff := diffWithContext(result, added, 3)
|
||||
return &Response{Config: config, Diff: diff}, nil
|
||||
|
||||
addedLines := make([]int, 0, len(added))
|
||||
for i := range result {
|
||||
if added[i] {
|
||||
addedLines = append(addedLines, i+1)
|
||||
}
|
||||
}
|
||||
|
||||
return &Response{Config: config, Added: addedLines}, nil
|
||||
}
|
||||
|
||||
func dedup(info *cameraInfo, cams, streams map[string]bool) *cameraInfo {
|
||||
|
||||
@@ -106,12 +106,6 @@ type UIConfig struct {
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Config string `json:"config"`
|
||||
Diff []DiffLine `json:"diff"`
|
||||
}
|
||||
|
||||
type DiffLine struct {
|
||||
Line int `json:"line"`
|
||||
Text string `json:"text"`
|
||||
Type string `json:"type"` // context, added, removed
|
||||
Config string `json:"config"`
|
||||
Added []int `json:"added"` // 1-based line numbers of added lines
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user