Skip to content

Commit

Permalink
save user to videos
Browse files Browse the repository at this point in the history
  • Loading branch information
marnym committed Nov 11, 2023
1 parent 61f358e commit 685242f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions backend/pocketbase/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"strconv"

"github.com/pocketbase/pocketbase"
"github.com/pocketbase/pocketbase/apis"
"github.com/pocketbase/pocketbase/core"
"github.com/pocketbase/pocketbase/models"
)
Expand All @@ -22,6 +23,21 @@ type Comparison struct {
func main() {
app := pocketbase.New()

app.OnRecordBeforeCreateRequest("videos").Add(func(e *core.RecordCreateEvent) error {
user, ok := e.HttpContext.Get(apis.ContextAuthRecordKey).(*models.Record)
if !ok {
return fmt.Errorf("invalid user: %s", e.HttpContext.Get(apis.ContextAuthRecordKey))
}

e.Record.Set("user", user)

if err := app.Dao().SaveRecord(e.Record); err != nil {
return fmt.Errorf("failed to save video %s: %v", e.Record.Id, err)
}

return nil
})

app.OnRecordAfterCreateRequest("videos").Add(func(e *core.RecordCreateEvent) error {
videoFile := e.Record.Get("video").(string)
go inferAndScore(app, e.Record, videoFile)
Expand Down

0 comments on commit 685242f

Please sign in to comment.