Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds import event #85

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 imported 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
Loading