Skip to content

Commit

Permalink
Update API version, other small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
initialed85 committed Aug 11, 2024
1 parent c209752 commit cd0ef12
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 21 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/VideoTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export function VideoTable(props: VideoTableProps) {
const startedAt = new Date(video.started_at);
const endedAt = video.ended_at && new Date(video.ended_at);

const available = !!endedAt;
const available = video?.status !== "recording";

const minutes = Math.floor(
(video?.duration || 0) / (1_000_000_000 * 60),
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/go-chi/chi/v5 v5.1.0
github.com/gomodule/redigo v1.9.2
github.com/google/uuid v1.6.0
github.com/initialed85/djangolang v0.0.25
github.com/initialed85/djangolang v0.0.27
github.com/jackc/pgtype v1.14.3
github.com/jackc/pgx/v5 v5.6.0
github.com/jmoiron/sqlx v1.4.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/initialed85/djangolang v0.0.25 h1:5vb/R9KpOKZ8sasD2MFFlh250ciABqqYGhEdsw4DV6w=
github.com/initialed85/djangolang v0.0.25/go.mod h1:3mqaFDBq9zfX/18jyDCHs5UpH2r5XGgBj/SlRcgfY64=
github.com/initialed85/djangolang v0.0.27 h1:y/+0WwvKmJ0eyJIq/fWGqVFjyNHRgclkZiSV7kf/r7w=
github.com/initialed85/djangolang v0.0.27/go.mod h1:3mqaFDBq9zfX/18jyDCHs5UpH2r5XGgBj/SlRcgfY64=
github.com/initialed85/structmeta v0.0.0-20240802152142-39f398ef1ab7 h1:G9Z1k4TyxQ/9Kk4ZSuw82WZCxJayZf12Aos2MorzKRg=
github.com/initialed85/structmeta v0.0.0-20240802152142-39f398ef1ab7/go.mod h1:hTGWTsfgy6Um+L8e3Qcj8/pBkHGcIGxEpZAKziWhQfc=
github.com/invopop/yaml v0.3.1 h1:f0+ZpmhfBSS4MhG+4HYseMdJhoeeopbSKbq5Rpeelso=
Expand Down
Binary file modified pkg/api/bin/api
Binary file not shown.
26 changes: 21 additions & 5 deletions pkg/api/camera.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,18 +642,18 @@ func SelectCameras(

err = object.FromItem(item)
if err != nil {
return nil, fmt.Errorf("failed to call Camera.FromItem; err: %v", err)
return nil, err
}

func() {
err = func() error {
possibleRootTableName := ctx.Value(_rootTableNameContextKey)
rootTableName, _ := possibleRootTableName.(string)
if rootTableName == "" {
ctx = context.WithValue(ctx, _rootTableNameContextKey, CameraTable)
}

if rootTableName != CameraTable {
object.ReferencedByVideoCameraIDObjects, _ = SelectVideos(
object.ReferencedByVideoCameraIDObjects, err = SelectVideos(
ctx,
tx,
fmt.Sprintf("%v = $1", VideoTableCameraIDColumn),
Expand All @@ -662,18 +662,26 @@ func SelectCameras(
nil,
object.ID,
)
if err != nil {
return err
}
}

return nil
}()
if err != nil {
return nil, err
}

func() {
err = func() error {
possibleRootTableName := ctx.Value(_rootTableNameContextKey)
rootTableName, _ := possibleRootTableName.(string)
if rootTableName == "" {
ctx = context.WithValue(ctx, _rootTableNameContextKey, CameraTable)
}

if rootTableName != CameraTable {
object.ReferencedByDetectionCameraIDObjects, _ = SelectDetections(
object.ReferencedByDetectionCameraIDObjects, err = SelectDetections(
ctx,
tx,
fmt.Sprintf("%v = $1", DetectionTableCameraIDColumn),
Expand All @@ -682,8 +690,16 @@ func SelectCameras(
nil,
object.ID,
)
if err != nil {
return err
}
}

return nil
}()
if err != nil {
return nil, err
}

objects = append(objects, object)
}
Expand Down
7 changes: 5 additions & 2 deletions pkg/api/detection.go
Original file line number Diff line number Diff line change
Expand Up @@ -832,16 +832,19 @@ func SelectDetections(

err = object.FromItem(item)
if err != nil {
return nil, fmt.Errorf("failed to call Detection.FromItem; err: %v", err)
return nil, err
}

if !types.IsZeroUUID(object.CameraID) {
object.CameraIDObject, _ = SelectCamera(
object.CameraIDObject, err = SelectCamera(
ctx,
tx,
fmt.Sprintf("%v = $1", CameraTablePrimaryKeyColumn),
object.CameraID,
)
if err != nil {
return nil, err
}
}

objects = append(objects, object)
Expand Down
7 changes: 5 additions & 2 deletions pkg/api/video.go
Original file line number Diff line number Diff line change
Expand Up @@ -880,16 +880,19 @@ func SelectVideos(

err = object.FromItem(item)
if err != nil {
return nil, fmt.Errorf("failed to call Video.FromItem; err: %v", err)
return nil, err
}

if !types.IsZeroUUID(object.CameraID) {
object.CameraIDObject, _ = SelectCamera(
object.CameraIDObject, err = SelectCamera(
ctx,
tx,
fmt.Sprintf("%v = $1", CameraTablePrimaryKeyColumn),
object.CameraID,
)
if err != nil {
return nil, err
}
}

objects = append(objects, object)
Expand Down
4 changes: 2 additions & 2 deletions pkg/segment_producer/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func GenerateThumbnail(videoPath, imagePath string) error {
videoPath,
"-ss",
"00:00:00.000",
"-vframes",
"-frames:v",
"1",
imagePath,
}
Expand All @@ -34,7 +34,7 @@ func GenerateThumbnail(videoPath, imagePath string) error {

err := cmd.Run()
if err != nil {
return fmt.Errorf("failed to generate thumbnail: %v; stdout=%#+v, stderr=%#+v", err, stdout, stderr)
return fmt.Errorf("failed to generate thumbnail: %v; stdout=%#+v, stderr=%#+v", err, stdout.String(), stderr.String())
}

return nil
Expand Down
38 changes: 32 additions & 6 deletions pkg/segment_producer/segment_producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ func Run() error {
return err
}

func() error {
err = func() error {
tx, err := db.BeginTxx(ctx, nil)
if err != nil {
return err
Expand Down Expand Up @@ -440,11 +440,24 @@ func Run() error {
return err
}

for _, orphanedVideo := range orphanedVideos {
log.Printf("marking orphaned video %s as failed", orphanedVideo.ID)
for _, video := range orphanedVideos {
log.Printf("marking orphaned video %s as failed", video.ID)

filePath := filepath.Join(destinationPath, video.FileName)

_, fileName := filepath.Split(filePath)
video.FileName = fileName

orphanedVideo.Status = helpers.Ptr("failed")
err = orphanedVideo.Update(ctx, tx, false)
ext := filepath.Ext(fileName)
thumbnailPath := fmt.Sprintf("%v.jpg", filePath[:len(filePath)-len(ext)])
err = GenerateThumbnail(filePath, thumbnailPath)
if err == nil {
_, thumbnailName := filepath.Split(thumbnailPath)
video.ThumbnailName = &thumbnailName
}

video.Status = helpers.Ptr("failed")
err = video.Update(ctx, tx, false)
if err != nil {
return err
}
Expand All @@ -461,7 +474,7 @@ func Run() error {
return fmt.Errorf("failed to handle orphaned videos: %v", err)
}

log.Printf("api confirmed %#+v", camera)
log.Printf("api confirmed camera %s | %s | %s", camera.ID, camera.StreamURL, camera.Name)

mu := new(sync.Mutex)
var video *api.Video
Expand All @@ -482,6 +495,19 @@ func Run() error {
if video != nil {
log.Printf("warning: there was a Video in-flight that should have been closed out- marking %v as failed", video.ID)

filePath := filepath.Join(destinationPath, video.FileName)

_, fileName := filepath.Split(filePath)
video.FileName = fileName

ext := filepath.Ext(fileName)
thumbnailPath := fmt.Sprintf("%v.jpg", filePath[:len(filePath)-len(ext)])
err = GenerateThumbnail(filePath, thumbnailPath)
if err == nil {
_, thumbnailName := filepath.Split(thumbnailPath)
video.ThumbnailName = &thumbnailName
}

video.Status = helpers.Ptr("failed")
err = video.Update(ctx, tx, false)
if err != nil {
Expand Down

0 comments on commit cd0ef12

Please sign in to comment.