mirror of
https://github.com/navidrome/navidrome.git
synced 2026-10-18 07:30:29 +00:00
183 lines
5.1 KiB
Go
183 lines
5.1 KiB
Go
// Code generated by hostgen. DO NOT EDIT.
|
|
|
|
package host
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
extism "github.com/extism/go-sdk"
|
|
)
|
|
|
|
// ArtworkGetArtistUrlResponse is the response type for Artwork.GetArtistUrl.
|
|
type ArtworkGetArtistUrlResponse struct {
|
|
Url string `json:"url,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// ArtworkGetAlbumUrlResponse is the response type for Artwork.GetAlbumUrl.
|
|
type ArtworkGetAlbumUrlResponse struct {
|
|
Url string `json:"url,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// ArtworkGetTrackUrlResponse is the response type for Artwork.GetTrackUrl.
|
|
type ArtworkGetTrackUrlResponse struct {
|
|
Url string `json:"url,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// ArtworkGetPlaylistUrlResponse is the response type for Artwork.GetPlaylistUrl.
|
|
type ArtworkGetPlaylistUrlResponse struct {
|
|
Url string `json:"url,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// RegisterArtworkHostFunctions registers Artwork service host functions.
|
|
// The returned host functions should be added to the plugin's configuration.
|
|
func RegisterArtworkHostFunctions(service ArtworkService) []extism.HostFunction {
|
|
return []extism.HostFunction{
|
|
newArtworkGetArtistUrlHostFunction(service),
|
|
newArtworkGetAlbumUrlHostFunction(service),
|
|
newArtworkGetTrackUrlHostFunction(service),
|
|
newArtworkGetPlaylistUrlHostFunction(service),
|
|
}
|
|
}
|
|
|
|
func newArtworkGetArtistUrlHostFunction(service ArtworkService) extism.HostFunction {
|
|
return extism.NewHostFunctionWithStack(
|
|
"artwork_getartisturl",
|
|
func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {
|
|
// Read parameters from stack
|
|
id, err := p.ReadString(stack[0])
|
|
if err != nil {
|
|
return
|
|
}
|
|
size := extism.DecodeI32(stack[1])
|
|
|
|
// Call the service method
|
|
url, err := service.GetArtistUrl(ctx, id, size)
|
|
if err != nil {
|
|
artworkWriteError(p, stack, err)
|
|
return
|
|
}
|
|
// Write JSON response to plugin memory
|
|
resp := ArtworkGetArtistUrlResponse{
|
|
Url: url,
|
|
}
|
|
artworkWriteResponse(p, stack, resp)
|
|
},
|
|
[]extism.ValueType{extism.ValueTypePTR, extism.ValueTypeI32},
|
|
[]extism.ValueType{extism.ValueTypePTR},
|
|
)
|
|
}
|
|
|
|
func newArtworkGetAlbumUrlHostFunction(service ArtworkService) extism.HostFunction {
|
|
return extism.NewHostFunctionWithStack(
|
|
"artwork_getalbumurl",
|
|
func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {
|
|
// Read parameters from stack
|
|
id, err := p.ReadString(stack[0])
|
|
if err != nil {
|
|
return
|
|
}
|
|
size := extism.DecodeI32(stack[1])
|
|
|
|
// Call the service method
|
|
url, err := service.GetAlbumUrl(ctx, id, size)
|
|
if err != nil {
|
|
artworkWriteError(p, stack, err)
|
|
return
|
|
}
|
|
// Write JSON response to plugin memory
|
|
resp := ArtworkGetAlbumUrlResponse{
|
|
Url: url,
|
|
}
|
|
artworkWriteResponse(p, stack, resp)
|
|
},
|
|
[]extism.ValueType{extism.ValueTypePTR, extism.ValueTypeI32},
|
|
[]extism.ValueType{extism.ValueTypePTR},
|
|
)
|
|
}
|
|
|
|
func newArtworkGetTrackUrlHostFunction(service ArtworkService) extism.HostFunction {
|
|
return extism.NewHostFunctionWithStack(
|
|
"artwork_gettrackurl",
|
|
func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {
|
|
// Read parameters from stack
|
|
id, err := p.ReadString(stack[0])
|
|
if err != nil {
|
|
return
|
|
}
|
|
size := extism.DecodeI32(stack[1])
|
|
|
|
// Call the service method
|
|
url, err := service.GetTrackUrl(ctx, id, size)
|
|
if err != nil {
|
|
artworkWriteError(p, stack, err)
|
|
return
|
|
}
|
|
// Write JSON response to plugin memory
|
|
resp := ArtworkGetTrackUrlResponse{
|
|
Url: url,
|
|
}
|
|
artworkWriteResponse(p, stack, resp)
|
|
},
|
|
[]extism.ValueType{extism.ValueTypePTR, extism.ValueTypeI32},
|
|
[]extism.ValueType{extism.ValueTypePTR},
|
|
)
|
|
}
|
|
|
|
func newArtworkGetPlaylistUrlHostFunction(service ArtworkService) extism.HostFunction {
|
|
return extism.NewHostFunctionWithStack(
|
|
"artwork_getplaylisturl",
|
|
func(ctx context.Context, p *extism.CurrentPlugin, stack []uint64) {
|
|
// Read parameters from stack
|
|
id, err := p.ReadString(stack[0])
|
|
if err != nil {
|
|
return
|
|
}
|
|
size := extism.DecodeI32(stack[1])
|
|
|
|
// Call the service method
|
|
url, err := service.GetPlaylistUrl(ctx, id, size)
|
|
if err != nil {
|
|
artworkWriteError(p, stack, err)
|
|
return
|
|
}
|
|
// Write JSON response to plugin memory
|
|
resp := ArtworkGetPlaylistUrlResponse{
|
|
Url: url,
|
|
}
|
|
artworkWriteResponse(p, stack, resp)
|
|
},
|
|
[]extism.ValueType{extism.ValueTypePTR, extism.ValueTypeI32},
|
|
[]extism.ValueType{extism.ValueTypePTR},
|
|
)
|
|
}
|
|
|
|
// artworkWriteResponse writes a JSON response to plugin memory.
|
|
func artworkWriteResponse(p *extism.CurrentPlugin, stack []uint64, resp any) {
|
|
respBytes, err := json.Marshal(resp)
|
|
if err != nil {
|
|
artworkWriteError(p, stack, err)
|
|
return
|
|
}
|
|
respPtr, err := p.WriteBytes(respBytes)
|
|
if err != nil {
|
|
stack[0] = 0
|
|
return
|
|
}
|
|
stack[0] = respPtr
|
|
}
|
|
|
|
// artworkWriteError writes an error response to plugin memory.
|
|
func artworkWriteError(p *extism.CurrentPlugin, stack []uint64, err error) {
|
|
errResp := struct {
|
|
Error string `json:"error"`
|
|
}{Error: err.Error()}
|
|
respBytes, _ := json.Marshal(errResp)
|
|
respPtr, _ := p.WriteBytes(respBytes)
|
|
stack[0] = respPtr
|
|
}
|