wip
This commit is contained in:
63
server/models/cameras.go
Normal file
63
server/models/cameras.go
Normal file
@@ -0,0 +1,63 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/pocketbase/pocketbase/core"
|
||||
"github.com/pocketbase/pocketbase/tools/security"
|
||||
)
|
||||
|
||||
const (
|
||||
CameraFPassword = "password"
|
||||
CameraFRecordStream = "record_stream"
|
||||
)
|
||||
|
||||
type Camera struct {
|
||||
core.BaseRecordProxy
|
||||
}
|
||||
|
||||
func (c *Camera) Name() string {
|
||||
return c.GetString("name")
|
||||
}
|
||||
|
||||
func (c *Camera) OnvifHost() string {
|
||||
return c.GetString("onvif_host")
|
||||
}
|
||||
|
||||
func (c *Camera) Username() string {
|
||||
return c.GetString("username")
|
||||
}
|
||||
|
||||
func (c *Camera) PasswordRaw() string {
|
||||
return c.GetString(CameraFPassword)
|
||||
}
|
||||
|
||||
func (c *Camera) Password(key string) (string, error) {
|
||||
password, err := security.Decrypt(c.PasswordRaw(), key)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to decrypt password: %w", err)
|
||||
}
|
||||
return string(password), nil
|
||||
}
|
||||
|
||||
func (c *Camera) SetPassword(password string, key string) error {
|
||||
encrypted, err := security.Encrypt([]byte(password), key)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to encrypt password: %w", err)
|
||||
}
|
||||
c.Set(CameraFPassword, encrypted)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Camera) RecordStreamID() string {
|
||||
return c.GetString(CameraFRecordStream)
|
||||
}
|
||||
|
||||
func (c *Camera) RecordStream() *Stream {
|
||||
if r := c.ExpandedOne(CameraFRecordStream); r != nil {
|
||||
stream := &Stream{}
|
||||
stream.SetProxyRecord(r)
|
||||
return stream
|
||||
}
|
||||
return nil
|
||||
}
|
||||
60
server/models/streams.go
Normal file
60
server/models/streams.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package models
|
||||
|
||||
import "github.com/pocketbase/pocketbase/core"
|
||||
|
||||
const (
|
||||
StreamFCamera = "camera"
|
||||
)
|
||||
|
||||
type Stream struct {
|
||||
core.BaseRecordProxy
|
||||
}
|
||||
|
||||
func (s *Stream) CameraID() string {
|
||||
return s.GetString(StreamFCamera)
|
||||
}
|
||||
|
||||
func (s *Stream) SetCameraID(id string) {
|
||||
s.Set("camera", id)
|
||||
}
|
||||
|
||||
func (s *Stream) Camera() *Camera {
|
||||
if r := s.ExpandedOne(StreamFCamera); r != nil {
|
||||
camera := &Camera{}
|
||||
camera.SetProxyRecord(r)
|
||||
return camera
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *Stream) URL() string {
|
||||
return s.GetString("url")
|
||||
}
|
||||
|
||||
func (s *Stream) SetURL(url string) {
|
||||
s.Set("url", url)
|
||||
}
|
||||
|
||||
func (s *Stream) FPS() float64 {
|
||||
return s.GetFloat("fps")
|
||||
}
|
||||
|
||||
func (s *Stream) SetFPS(fps float64) {
|
||||
s.Set("fps", fps)
|
||||
}
|
||||
|
||||
func (s *Stream) Height() int {
|
||||
return s.GetInt("height")
|
||||
}
|
||||
|
||||
func (s *Stream) SetHeight(height int) {
|
||||
s.Set("height", height)
|
||||
}
|
||||
|
||||
func (s *Stream) Width() int {
|
||||
return s.GetInt("width")
|
||||
}
|
||||
|
||||
func (s *Stream) SetWidth(width int) {
|
||||
s.Set("width", width)
|
||||
}
|
||||
Reference in New Issue
Block a user