mirror of
https://github.com/navidrome/navidrome.git
synced 2026-02-02 06:24:14 +00:00
70 lines
1.8 KiB
Go
70 lines
1.8 KiB
Go
// Code generated by hostgen. DO NOT EDIT.
|
|
//
|
|
// This file contains client wrappers for the SubsonicAPI host service.
|
|
// It is intended for use in Navidrome plugins built with TinyGo.
|
|
//
|
|
//go:build wasip1
|
|
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"errors"
|
|
|
|
"github.com/extism/go-pdk"
|
|
)
|
|
|
|
// subsonicapi_call is the host function provided by Navidrome.
|
|
//
|
|
//go:wasmimport extism:host/user subsonicapi_call
|
|
func subsonicapi_call(uint64) uint64
|
|
|
|
// SubsonicAPICallRequest is the request type for SubsonicAPI.Call.
|
|
type SubsonicAPICallRequest struct {
|
|
Uri string `json:"uri"`
|
|
}
|
|
|
|
// SubsonicAPICallResponse is the response type for SubsonicAPI.Call.
|
|
type SubsonicAPICallResponse struct {
|
|
ResponseJSON string `json:"responseJSON,omitempty"`
|
|
Error string `json:"error,omitempty"`
|
|
}
|
|
|
|
// SubsonicAPICall calls the subsonicapi_call host function.
|
|
// Call executes a Subsonic API request and returns the JSON response.
|
|
//
|
|
// The uri parameter should be the Subsonic API path without the server prefix,
|
|
// e.g., "getAlbumList2?type=random&size=10". The response is returned as raw JSON.
|
|
func SubsonicAPICall(uri string) (*SubsonicAPICallResponse, error) {
|
|
// Marshal request to JSON
|
|
req := SubsonicAPICallRequest{
|
|
Uri: uri,
|
|
}
|
|
reqBytes, err := json.Marshal(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
reqMem := pdk.AllocateBytes(reqBytes)
|
|
defer reqMem.Free()
|
|
|
|
// Call the host function
|
|
responsePtr := subsonicapi_call(reqMem.Offset())
|
|
|
|
// Read the response from memory
|
|
responseMem := pdk.FindMemory(responsePtr)
|
|
responseBytes := responseMem.ReadBytes()
|
|
|
|
// Parse the response
|
|
var response SubsonicAPICallResponse
|
|
if err := json.Unmarshal(responseBytes, &response); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Convert Error field to Go error
|
|
if response.Error != "" {
|
|
return nil, errors.New(response.Error)
|
|
}
|
|
|
|
return &response, nil
|
|
}
|