update
Some checks failed
Pipeline: Test, Lint, Build / Get version info (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test JS code (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint i18n files (push) Has been cancelled
Pipeline: Test, Lint, Build / Check Docker configuration (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v5) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v6) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v7) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to GHCR (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to Docker Hub (push) Has been cancelled
Pipeline: Test, Lint, Build / Cleanup digest artifacts (push) Has been cancelled
Pipeline: Test, Lint, Build / Build Windows installers (push) Has been cancelled
Pipeline: Test, Lint, Build / Package/Release (push) Has been cancelled
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
POEditor import / update-translations (push) Has been cancelled
Some checks failed
Pipeline: Test, Lint, Build / Get version info (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test JS code (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint i18n files (push) Has been cancelled
Pipeline: Test, Lint, Build / Check Docker configuration (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v5) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v6) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v7) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to GHCR (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to Docker Hub (push) Has been cancelled
Pipeline: Test, Lint, Build / Cleanup digest artifacts (push) Has been cancelled
Pipeline: Test, Lint, Build / Build Windows installers (push) Has been cancelled
Pipeline: Test, Lint, Build / Package/Release (push) Has been cancelled
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
POEditor import / update-translations (push) Has been cancelled
This commit is contained in:
1136
plugins/api/api.pb.go
Normal file
1136
plugins/api/api.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
246
plugins/api/api.proto
Normal file
246
plugins/api/api.proto
Normal file
@@ -0,0 +1,246 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package api;
|
||||
|
||||
option go_package = "github.com/navidrome/navidrome/plugins/api;api";
|
||||
|
||||
// go:plugin type=plugin version=1
|
||||
service MetadataAgent {
|
||||
// Artist metadata methods
|
||||
rpc GetArtistMBID(ArtistMBIDRequest) returns (ArtistMBIDResponse);
|
||||
rpc GetArtistURL(ArtistURLRequest) returns (ArtistURLResponse);
|
||||
rpc GetArtistBiography(ArtistBiographyRequest) returns (ArtistBiographyResponse);
|
||||
rpc GetSimilarArtists(ArtistSimilarRequest) returns (ArtistSimilarResponse);
|
||||
rpc GetArtistImages(ArtistImageRequest) returns (ArtistImageResponse);
|
||||
rpc GetArtistTopSongs(ArtistTopSongsRequest) returns (ArtistTopSongsResponse);
|
||||
|
||||
// Album metadata methods
|
||||
rpc GetAlbumInfo(AlbumInfoRequest) returns (AlbumInfoResponse);
|
||||
rpc GetAlbumImages(AlbumImagesRequest) returns (AlbumImagesResponse);
|
||||
}
|
||||
|
||||
message ArtistMBIDRequest {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
}
|
||||
|
||||
message ArtistMBIDResponse {
|
||||
string mbid = 1;
|
||||
}
|
||||
|
||||
message ArtistURLRequest {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
string mbid = 3;
|
||||
}
|
||||
|
||||
message ArtistURLResponse {
|
||||
string url = 1;
|
||||
}
|
||||
|
||||
message ArtistBiographyRequest {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
string mbid = 3;
|
||||
}
|
||||
|
||||
message ArtistBiographyResponse {
|
||||
string biography = 1;
|
||||
}
|
||||
|
||||
message ArtistSimilarRequest {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
string mbid = 3;
|
||||
int32 limit = 4;
|
||||
}
|
||||
|
||||
message Artist {
|
||||
string name = 1;
|
||||
string mbid = 2;
|
||||
}
|
||||
|
||||
message ArtistSimilarResponse {
|
||||
repeated Artist artists = 1;
|
||||
}
|
||||
|
||||
message ArtistImageRequest {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
string mbid = 3;
|
||||
}
|
||||
|
||||
message ExternalImage {
|
||||
string url = 1;
|
||||
int32 size = 2;
|
||||
}
|
||||
|
||||
message ArtistImageResponse {
|
||||
repeated ExternalImage images = 1;
|
||||
}
|
||||
|
||||
message ArtistTopSongsRequest {
|
||||
string id = 1;
|
||||
string artistName = 2;
|
||||
string mbid = 3;
|
||||
int32 count = 4;
|
||||
}
|
||||
|
||||
message Song {
|
||||
string name = 1;
|
||||
string mbid = 2;
|
||||
}
|
||||
|
||||
message ArtistTopSongsResponse {
|
||||
repeated Song songs = 1;
|
||||
}
|
||||
|
||||
message AlbumInfoRequest {
|
||||
string name = 1;
|
||||
string artist = 2;
|
||||
string mbid = 3;
|
||||
}
|
||||
|
||||
message AlbumInfo {
|
||||
string name = 1;
|
||||
string mbid = 2;
|
||||
string description = 3;
|
||||
string url = 4;
|
||||
}
|
||||
|
||||
message AlbumInfoResponse {
|
||||
AlbumInfo info = 1;
|
||||
}
|
||||
|
||||
message AlbumImagesRequest {
|
||||
string name = 1;
|
||||
string artist = 2;
|
||||
string mbid = 3;
|
||||
}
|
||||
|
||||
message AlbumImagesResponse {
|
||||
repeated ExternalImage images = 1;
|
||||
}
|
||||
|
||||
// go:plugin type=plugin version=1
|
||||
service Scrobbler {
|
||||
rpc IsAuthorized(ScrobblerIsAuthorizedRequest) returns (ScrobblerIsAuthorizedResponse);
|
||||
rpc NowPlaying(ScrobblerNowPlayingRequest) returns (ScrobblerNowPlayingResponse);
|
||||
rpc Scrobble(ScrobblerScrobbleRequest) returns (ScrobblerScrobbleResponse);
|
||||
}
|
||||
|
||||
message ScrobblerIsAuthorizedRequest {
|
||||
string user_id = 1;
|
||||
string username = 2;
|
||||
}
|
||||
|
||||
message ScrobblerIsAuthorizedResponse {
|
||||
bool authorized = 1;
|
||||
string error = 2;
|
||||
}
|
||||
|
||||
message TrackInfo {
|
||||
string id = 1;
|
||||
string mbid = 2;
|
||||
string name = 3;
|
||||
string album = 4;
|
||||
string album_mbid = 5;
|
||||
repeated Artist artists = 6;
|
||||
repeated Artist album_artists = 7;
|
||||
int32 length = 8; // seconds
|
||||
int32 position = 9; // seconds
|
||||
}
|
||||
|
||||
message ScrobblerNowPlayingRequest {
|
||||
string user_id = 1;
|
||||
string username = 2;
|
||||
TrackInfo track = 3;
|
||||
int64 timestamp = 4;
|
||||
}
|
||||
|
||||
message ScrobblerNowPlayingResponse {
|
||||
string error = 1;
|
||||
}
|
||||
|
||||
message ScrobblerScrobbleRequest {
|
||||
string user_id = 1;
|
||||
string username = 2;
|
||||
TrackInfo track = 3;
|
||||
int64 timestamp = 4;
|
||||
}
|
||||
|
||||
message ScrobblerScrobbleResponse {
|
||||
string error = 1;
|
||||
}
|
||||
|
||||
// go:plugin type=plugin version=1
|
||||
service SchedulerCallback {
|
||||
rpc OnSchedulerCallback(SchedulerCallbackRequest) returns (SchedulerCallbackResponse);
|
||||
}
|
||||
|
||||
message SchedulerCallbackRequest {
|
||||
string schedule_id = 1; // ID of the scheduled job that triggered this callback
|
||||
bytes payload = 2; // The data passed when the job was scheduled
|
||||
bool is_recurring = 3; // Whether this is from a recurring schedule (cron job)
|
||||
}
|
||||
|
||||
message SchedulerCallbackResponse {
|
||||
string error = 1; // Error message if the callback failed
|
||||
}
|
||||
|
||||
// go:plugin type=plugin version=1
|
||||
service LifecycleManagement {
|
||||
rpc OnInit(InitRequest) returns (InitResponse);
|
||||
}
|
||||
|
||||
message InitRequest {
|
||||
map<string, string> config = 1; // Configuration specific to this plugin
|
||||
}
|
||||
|
||||
message InitResponse {
|
||||
string error = 1; // Error message if initialization failed
|
||||
}
|
||||
|
||||
// go:plugin type=plugin version=1
|
||||
service WebSocketCallback {
|
||||
// Called when a text message is received
|
||||
rpc OnTextMessage(OnTextMessageRequest) returns (OnTextMessageResponse);
|
||||
|
||||
// Called when a binary message is received
|
||||
rpc OnBinaryMessage(OnBinaryMessageRequest) returns (OnBinaryMessageResponse);
|
||||
|
||||
// Called when an error occurs
|
||||
rpc OnError(OnErrorRequest) returns (OnErrorResponse);
|
||||
|
||||
// Called when the connection is closed
|
||||
rpc OnClose(OnCloseRequest) returns (OnCloseResponse);
|
||||
}
|
||||
|
||||
message OnTextMessageRequest {
|
||||
string connection_id = 1;
|
||||
string message = 2;
|
||||
}
|
||||
|
||||
message OnTextMessageResponse {}
|
||||
|
||||
message OnBinaryMessageRequest {
|
||||
string connection_id = 1;
|
||||
bytes data = 2;
|
||||
}
|
||||
|
||||
message OnBinaryMessageResponse {}
|
||||
|
||||
message OnErrorRequest {
|
||||
string connection_id = 1;
|
||||
string error = 2;
|
||||
}
|
||||
|
||||
message OnErrorResponse {}
|
||||
|
||||
message OnCloseRequest {
|
||||
string connection_id = 1;
|
||||
int32 code = 2;
|
||||
string reason = 3;
|
||||
}
|
||||
|
||||
message OnCloseResponse {}
|
||||
1688
plugins/api/api_host.pb.go
Normal file
1688
plugins/api/api_host.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
47
plugins/api/api_options.pb.go
Normal file
47
plugins/api/api_options.pb.go
Normal file
@@ -0,0 +1,47 @@
|
||||
//go:build !wasip1
|
||||
|
||||
// Code generated by protoc-gen-go-plugin. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go-plugin v0.1.0
|
||||
// protoc v5.29.3
|
||||
// source: api/api.proto
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
context "context"
|
||||
wazero "github.com/tetratelabs/wazero"
|
||||
wasi_snapshot_preview1 "github.com/tetratelabs/wazero/imports/wasi_snapshot_preview1"
|
||||
)
|
||||
|
||||
type wazeroConfigOption func(plugin *WazeroConfig)
|
||||
|
||||
type WazeroNewRuntime func(context.Context) (wazero.Runtime, error)
|
||||
|
||||
type WazeroConfig struct {
|
||||
newRuntime func(context.Context) (wazero.Runtime, error)
|
||||
moduleConfig wazero.ModuleConfig
|
||||
}
|
||||
|
||||
func WazeroRuntime(newRuntime WazeroNewRuntime) wazeroConfigOption {
|
||||
return func(h *WazeroConfig) {
|
||||
h.newRuntime = newRuntime
|
||||
}
|
||||
}
|
||||
|
||||
func DefaultWazeroRuntime() WazeroNewRuntime {
|
||||
return func(ctx context.Context) (wazero.Runtime, error) {
|
||||
r := wazero.NewRuntime(ctx)
|
||||
if _, err := wasi_snapshot_preview1.Instantiate(ctx, r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
}
|
||||
|
||||
func WazeroModuleConfig(moduleConfig wazero.ModuleConfig) wazeroConfigOption {
|
||||
return func(h *WazeroConfig) {
|
||||
h.moduleConfig = moduleConfig
|
||||
}
|
||||
}
|
||||
487
plugins/api/api_plugin.pb.go
Normal file
487
plugins/api/api_plugin.pb.go
Normal file
@@ -0,0 +1,487 @@
|
||||
//go:build wasip1
|
||||
|
||||
// Code generated by protoc-gen-go-plugin. DO NOT EDIT.
|
||||
// versions:
|
||||
// protoc-gen-go-plugin v0.1.0
|
||||
// protoc v5.29.3
|
||||
// source: api/api.proto
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
context "context"
|
||||
wasm "github.com/knqyf263/go-plugin/wasm"
|
||||
)
|
||||
|
||||
const MetadataAgentPluginAPIVersion = 1
|
||||
|
||||
//go:wasmexport metadata_agent_api_version
|
||||
func _metadata_agent_api_version() uint64 {
|
||||
return MetadataAgentPluginAPIVersion
|
||||
}
|
||||
|
||||
var metadataAgent MetadataAgent
|
||||
|
||||
func RegisterMetadataAgent(p MetadataAgent) {
|
||||
metadataAgent = p
|
||||
}
|
||||
|
||||
//go:wasmexport metadata_agent_get_artist_mbid
|
||||
func _metadata_agent_get_artist_mbid(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(ArtistMBIDRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := metadataAgent.GetArtistMBID(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport metadata_agent_get_artist_url
|
||||
func _metadata_agent_get_artist_url(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(ArtistURLRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := metadataAgent.GetArtistURL(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport metadata_agent_get_artist_biography
|
||||
func _metadata_agent_get_artist_biography(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(ArtistBiographyRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := metadataAgent.GetArtistBiography(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport metadata_agent_get_similar_artists
|
||||
func _metadata_agent_get_similar_artists(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(ArtistSimilarRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := metadataAgent.GetSimilarArtists(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport metadata_agent_get_artist_images
|
||||
func _metadata_agent_get_artist_images(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(ArtistImageRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := metadataAgent.GetArtistImages(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport metadata_agent_get_artist_top_songs
|
||||
func _metadata_agent_get_artist_top_songs(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(ArtistTopSongsRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := metadataAgent.GetArtistTopSongs(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport metadata_agent_get_album_info
|
||||
func _metadata_agent_get_album_info(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(AlbumInfoRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := metadataAgent.GetAlbumInfo(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport metadata_agent_get_album_images
|
||||
func _metadata_agent_get_album_images(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(AlbumImagesRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := metadataAgent.GetAlbumImages(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
const ScrobblerPluginAPIVersion = 1
|
||||
|
||||
//go:wasmexport scrobbler_api_version
|
||||
func _scrobbler_api_version() uint64 {
|
||||
return ScrobblerPluginAPIVersion
|
||||
}
|
||||
|
||||
var scrobbler Scrobbler
|
||||
|
||||
func RegisterScrobbler(p Scrobbler) {
|
||||
scrobbler = p
|
||||
}
|
||||
|
||||
//go:wasmexport scrobbler_is_authorized
|
||||
func _scrobbler_is_authorized(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(ScrobblerIsAuthorizedRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := scrobbler.IsAuthorized(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport scrobbler_now_playing
|
||||
func _scrobbler_now_playing(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(ScrobblerNowPlayingRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := scrobbler.NowPlaying(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport scrobbler_scrobble
|
||||
func _scrobbler_scrobble(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(ScrobblerScrobbleRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := scrobbler.Scrobble(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
const SchedulerCallbackPluginAPIVersion = 1
|
||||
|
||||
//go:wasmexport scheduler_callback_api_version
|
||||
func _scheduler_callback_api_version() uint64 {
|
||||
return SchedulerCallbackPluginAPIVersion
|
||||
}
|
||||
|
||||
var schedulerCallback SchedulerCallback
|
||||
|
||||
func RegisterSchedulerCallback(p SchedulerCallback) {
|
||||
schedulerCallback = p
|
||||
}
|
||||
|
||||
//go:wasmexport scheduler_callback_on_scheduler_callback
|
||||
func _scheduler_callback_on_scheduler_callback(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(SchedulerCallbackRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := schedulerCallback.OnSchedulerCallback(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
const LifecycleManagementPluginAPIVersion = 1
|
||||
|
||||
//go:wasmexport lifecycle_management_api_version
|
||||
func _lifecycle_management_api_version() uint64 {
|
||||
return LifecycleManagementPluginAPIVersion
|
||||
}
|
||||
|
||||
var lifecycleManagement LifecycleManagement
|
||||
|
||||
func RegisterLifecycleManagement(p LifecycleManagement) {
|
||||
lifecycleManagement = p
|
||||
}
|
||||
|
||||
//go:wasmexport lifecycle_management_on_init
|
||||
func _lifecycle_management_on_init(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(InitRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := lifecycleManagement.OnInit(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
const WebSocketCallbackPluginAPIVersion = 1
|
||||
|
||||
//go:wasmexport web_socket_callback_api_version
|
||||
func _web_socket_callback_api_version() uint64 {
|
||||
return WebSocketCallbackPluginAPIVersion
|
||||
}
|
||||
|
||||
var webSocketCallback WebSocketCallback
|
||||
|
||||
func RegisterWebSocketCallback(p WebSocketCallback) {
|
||||
webSocketCallback = p
|
||||
}
|
||||
|
||||
//go:wasmexport web_socket_callback_on_text_message
|
||||
func _web_socket_callback_on_text_message(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(OnTextMessageRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := webSocketCallback.OnTextMessage(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport web_socket_callback_on_binary_message
|
||||
func _web_socket_callback_on_binary_message(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(OnBinaryMessageRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := webSocketCallback.OnBinaryMessage(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport web_socket_callback_on_error
|
||||
func _web_socket_callback_on_error(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(OnErrorRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := webSocketCallback.OnError(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
|
||||
//go:wasmexport web_socket_callback_on_close
|
||||
func _web_socket_callback_on_close(ptr, size uint32) uint64 {
|
||||
b := wasm.PtrToByte(ptr, size)
|
||||
req := new(OnCloseRequest)
|
||||
if err := req.UnmarshalVT(b); err != nil {
|
||||
return 0
|
||||
}
|
||||
response, err := webSocketCallback.OnClose(context.Background(), req)
|
||||
if err != nil {
|
||||
ptr, size = wasm.ByteToPtr([]byte(err.Error()))
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size) |
|
||||
// Indicate that this is the error string by setting the 32-th bit, assuming that
|
||||
// no data exceeds 31-bit size (2 GiB).
|
||||
(1 << 31)
|
||||
}
|
||||
|
||||
b, err = response.MarshalVT()
|
||||
if err != nil {
|
||||
return 0
|
||||
}
|
||||
ptr, size = wasm.ByteToPtr(b)
|
||||
return (uint64(ptr) << uint64(32)) | uint64(size)
|
||||
}
|
||||
34
plugins/api/api_plugin_dev.go
Normal file
34
plugins/api/api_plugin_dev.go
Normal file
@@ -0,0 +1,34 @@
|
||||
//go:build !wasip1
|
||||
|
||||
package api
|
||||
|
||||
import "github.com/navidrome/navidrome/plugins/host/scheduler"
|
||||
|
||||
// This file exists to provide stubs for the plugin registration functions when building for non-WASM targets.
|
||||
// This is useful for testing and development purposes, as it allows you to build and run your plugin code
|
||||
// without having to compile it to WASM.
|
||||
// In a real-world scenario, you would compile your plugin to WASM and use the generated registration functions.
|
||||
|
||||
func RegisterMetadataAgent(MetadataAgent) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func RegisterScrobbler(Scrobbler) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func RegisterSchedulerCallback(SchedulerCallback) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func RegisterLifecycleManagement(LifecycleManagement) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func RegisterWebSocketCallback(WebSocketCallback) {
|
||||
panic("not implemented")
|
||||
}
|
||||
|
||||
func RegisterNamedSchedulerCallback(name string, cb SchedulerCallback) scheduler.SchedulerService {
|
||||
panic("not implemented")
|
||||
}
|
||||
94
plugins/api/api_plugin_dev_named_registry.go
Normal file
94
plugins/api/api_plugin_dev_named_registry.go
Normal file
@@ -0,0 +1,94 @@
|
||||
//go:build wasip1
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
"context"
|
||||
"strings"
|
||||
|
||||
"github.com/navidrome/navidrome/plugins/host/scheduler"
|
||||
)
|
||||
|
||||
var callbacks = make(namedCallbacks)
|
||||
|
||||
// RegisterNamedSchedulerCallback registers a named scheduler callback. Named callbacks allow multiple callbacks to be registered
|
||||
// within the same plugin, and for the schedules to be scoped to the named callback. If you only need a single callback, you can use
|
||||
// the default (unnamed) callback registration function, RegisterSchedulerCallback.
|
||||
// It returns a scheduler.SchedulerService that can be used to schedule jobs for the named callback.
|
||||
//
|
||||
// Notes:
|
||||
//
|
||||
// - You can't mix named and unnamed callbacks within the same plugin.
|
||||
// - The name should be unique within the plugin, and it's recommended to use a short, descriptive name.
|
||||
// - The name is case-sensitive.
|
||||
func RegisterNamedSchedulerCallback(name string, cb SchedulerCallback) scheduler.SchedulerService {
|
||||
callbacks[name] = cb
|
||||
RegisterSchedulerCallback(&callbacks)
|
||||
return &namedSchedulerService{name: name, svc: scheduler.NewSchedulerService()}
|
||||
}
|
||||
|
||||
const zwsp = string('\u200b')
|
||||
|
||||
// namedCallbacks is a map of named scheduler callbacks. The key is the name of the callback, and the value is the callback itself.
|
||||
type namedCallbacks map[string]SchedulerCallback
|
||||
|
||||
func parseKey(key string) (string, string) {
|
||||
parts := strings.SplitN(key, zwsp, 2)
|
||||
if len(parts) != 2 {
|
||||
return "", ""
|
||||
}
|
||||
return parts[0], parts[1]
|
||||
}
|
||||
|
||||
func (n *namedCallbacks) OnSchedulerCallback(ctx context.Context, req *SchedulerCallbackRequest) (*SchedulerCallbackResponse, error) {
|
||||
name, scheduleId := parseKey(req.ScheduleId)
|
||||
cb, exists := callbacks[name]
|
||||
if !exists {
|
||||
return nil, nil
|
||||
}
|
||||
req.ScheduleId = scheduleId
|
||||
return cb.OnSchedulerCallback(ctx, req)
|
||||
}
|
||||
|
||||
// namedSchedulerService is a wrapper around the host scheduler service that prefixes the schedule IDs with the
|
||||
// callback name. It is returned by RegisterNamedSchedulerCallback, and should be used by the plugin to schedule
|
||||
// jobs for the named callback.
|
||||
type namedSchedulerService struct {
|
||||
name string
|
||||
cb SchedulerCallback
|
||||
svc scheduler.SchedulerService
|
||||
}
|
||||
|
||||
func (n *namedSchedulerService) makeKey(id string) string {
|
||||
return n.name + zwsp + id
|
||||
}
|
||||
|
||||
func (n *namedSchedulerService) mapResponse(resp *scheduler.ScheduleResponse, err error) (*scheduler.ScheduleResponse, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, resp.ScheduleId = parseKey(resp.ScheduleId)
|
||||
return resp, nil
|
||||
}
|
||||
|
||||
func (n *namedSchedulerService) ScheduleOneTime(ctx context.Context, request *scheduler.ScheduleOneTimeRequest) (*scheduler.ScheduleResponse, error) {
|
||||
key := n.makeKey(request.ScheduleId)
|
||||
request.ScheduleId = key
|
||||
return n.mapResponse(n.svc.ScheduleOneTime(ctx, request))
|
||||
}
|
||||
|
||||
func (n *namedSchedulerService) ScheduleRecurring(ctx context.Context, request *scheduler.ScheduleRecurringRequest) (*scheduler.ScheduleResponse, error) {
|
||||
key := n.makeKey(request.ScheduleId)
|
||||
request.ScheduleId = key
|
||||
return n.mapResponse(n.svc.ScheduleRecurring(ctx, request))
|
||||
}
|
||||
|
||||
func (n *namedSchedulerService) CancelSchedule(ctx context.Context, request *scheduler.CancelRequest) (*scheduler.CancelResponse, error) {
|
||||
key := n.makeKey(request.ScheduleId)
|
||||
request.ScheduleId = key
|
||||
return n.svc.CancelSchedule(ctx, request)
|
||||
}
|
||||
|
||||
func (n *namedSchedulerService) TimeNow(ctx context.Context, request *scheduler.TimeNowRequest) (*scheduler.TimeNowResponse, error) {
|
||||
return n.svc.TimeNow(ctx, request)
|
||||
}
|
||||
7315
plugins/api/api_vtproto.pb.go
Normal file
7315
plugins/api/api_vtproto.pb.go
Normal file
File diff suppressed because it is too large
Load Diff
12
plugins/api/errors.go
Normal file
12
plugins/api/errors.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package api
|
||||
|
||||
import "errors"
|
||||
|
||||
var (
|
||||
// ErrNotImplemented indicates that the plugin does not implement the requested method.
|
||||
// No logic should be executed by the plugin.
|
||||
ErrNotImplemented = errors.New("plugin:not_implemented")
|
||||
|
||||
// ErrNotFound indicates that the requested resource was not found by the plugin.
|
||||
ErrNotFound = errors.New("plugin:not_found")
|
||||
)
|
||||
Reference in New Issue
Block a user