Skip to content

Commit

Permalink
adds import event
Browse files Browse the repository at this point in the history
  • Loading branch information
autodidaddict committed Mar 11, 2024
1 parent 680606c commit be941d2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
1 change: 1 addition & 0 deletions internal/models/global_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const (
CatalogSharedEventType = "catalog_shared"
CatalogUnsharedEventType = "catalog_unshared"
ContextBoundEventType = "context_bound"
CatalogImportedEventType = "catalog_imported"
)

// Heartbeats are emitted to the global service periodically by running natster
Expand Down
26 changes: 26 additions & 0 deletions natster/catalog.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ func ImportCatalog(ctx *fisk.ParseContext) error {
ShareOpts.Name, ShareOpts.AccountKey,
)
}
if !catFound && !mediaFound {
publishCatalogImported()
}
return nil
}

Expand Down Expand Up @@ -423,6 +426,29 @@ func publishCatalogUnshared() error {
return nil
}

func publishCatalogImported() error {
ctx, _ := loadContext()
client, err := globalservice.NewClientWithCredsPath(ctx.CredsPath)
if err != nil {
slog.Error(
"Failed to connect to NGS",
slog.String("error", err.Error()),
)
return err
}
err = client.PublishEvent(models.CatalogImportedEventType, ShareOpts.Name, ShareOpts.AccountKey, nil)
if err != nil {
slog.Error(
"Failed to publish catalog unshared event",
slog.String("error", err.Error()),
)
return err
}
client.Drain()

return nil
}

func publishCatalogShared() error {
ctx, _ := loadContext()
client, err := globalservice.NewClientWithCredsPath(ctx.CredsPath)
Expand Down

0 comments on commit be941d2

Please sign in to comment.