feat(plugins): add SubsonicAPI CallRaw, with support for raw=true binary response for host functions (#4982)

* feat: implement raw binary framing for host function responses

Signed-off-by: Deluan <deluan@navidrome.org>

* feat: add CallRaw method for Subsonic API to handle binary responses

Signed-off-by: Deluan <deluan@navidrome.org>

* test: add tests for raw=true methods and binary framing generation

Signed-off-by: Deluan <deluan@navidrome.org>

* fix: improve error message for malformed raw responses to indicate incomplete header

Signed-off-by: Deluan <deluan@navidrome.org>

* fix: add wasm_import_module attribute for raw methods and improve content-type handling

Signed-off-by: Deluan <deluan@navidrome.org>

---------

Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
Deluan Quintão
2026-02-04 15:48:08 -05:00
committed by GitHub
parent 19ea338bed
commit e8863ed147
23 changed files with 1223 additions and 40 deletions
+26
View File
@@ -3,6 +3,8 @@
package main
import (
"fmt"
"github.com/navidrome/navidrome/plugins/pdk/go/host"
"github.com/navidrome/navidrome/plugins/pdk/go/pdk"
)
@@ -28,4 +30,28 @@ func callSubsonicAPIExport() int32 {
return 0
}
// call_subsonic_api_raw is the exported function that tests the SubsonicAPI CallRaw host function.
// Input: URI string (e.g., "/getCoverArt?u=testuser&id=al-1")
// Output: JSON with contentType, size, and first bytes of the raw response
//
//go:wasmexport call_subsonic_api_raw
func callSubsonicAPIRawExport() int32 {
uri := pdk.InputString()
contentType, data, err := host.SubsonicAPICallRaw(uri)
if err != nil {
pdk.SetErrorString("failed to call SubsonicAPI raw: " + err.Error())
return 1
}
// Return metadata about the raw response as JSON
firstByte := 0
if len(data) > 0 {
firstByte = int(data[0])
}
result := fmt.Sprintf(`{"contentType":%q,"size":%d,"firstByte":%d}`, contentType, len(data), firstByte)
pdk.OutputString(result)
return 0
}
func main() {}