Skip to content

Commit

Permalink
Implement routes for subtitle page
Browse files Browse the repository at this point in the history
  • Loading branch information
nandesh-dev committed Nov 5, 2024
1 parent 70cd534 commit 782af30
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions internal/server/subtitle/get_segment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package subtitle

import (
"context"
"fmt"

"connectrpc.com/connect"
subtitle_proto "github.com/nandesh-dev/subtle/generated/proto/subtitle"
"github.com/nandesh-dev/subtle/pkgs/db"
"google.golang.org/protobuf/types/known/durationpb"
)

func (s ServiceHandler) GetSegment(ctx context.Context, req *connect.Request[subtitle_proto.GetSegmentRequest]) (*connect.Response[subtitle_proto.GetSegmentResponse], error) {
var segmentEntry db.Segment

if err := db.DB().Where(&db.Segment{ID: int(req.Msg.Id)}).
First(&segmentEntry).Error; err != nil {
return nil, fmt.Errorf("Error getting video entry: %v", err)
}

res := subtitle_proto.GetSegmentResponse{
Start: durationpb.New(segmentEntry.StartTime),
End: durationpb.New(segmentEntry.EndTime),
Original: &subtitle_proto.OriginalSegment{},
New: &subtitle_proto.NewSegment{
Text: segmentEntry.Text,
},
}

if segmentEntry.OriginalText == "" {
res.Original.Image = segmentEntry.OriginalImage
} else {
res.Original.Text = &segmentEntry.OriginalText
}

return connect.NewResponse(&res), nil
}
1 change: 1 addition & 0 deletions internal/server/subtitle/get_subtitle.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func (s ServiceHandler) GetSubtitle(ctx context.Context, req *connect.Request[su
}

res := subtitle_proto.GetSubtitleResponse{
VideoId: int32(subtitleEntry.VideoID),
Id: req.Msg.Id,
Title: subtitleEntry.Title,
Language: subtitleEntry.Language,
Expand Down

0 comments on commit 782af30

Please sign in to comment.