mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
refactor(plugins): update macro names for websocket and metadata registration to improve clarity and consistency
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
3bfce4cc9c
commit
53aa1a67ee
1
.gitignore
vendored
1
.gitignore
vendored
@ -26,6 +26,7 @@ docker-compose.yml
|
||||
!contrib/docker-compose.yml
|
||||
binaries
|
||||
navidrome-*
|
||||
ndpgen
|
||||
AGENTS.md
|
||||
.github/prompts
|
||||
.github/instructions
|
||||
|
||||
@ -419,7 +419,7 @@ func rustCapabilityFuncMap(cap Capability) template.FuncMap {
|
||||
"hasHashMap": hasHashMap,
|
||||
"agentName": capabilityAgentName,
|
||||
"providerInterface": func(e Export) string { return e.ProviderInterfaceName() },
|
||||
"registerMacroName": registerMacroName,
|
||||
"registerMacroName": func(name string) string { return registerMacroName(cap.Name, name) },
|
||||
"snakeCase": ToSnakeCase,
|
||||
"indent": func(spaces int, s string) string {
|
||||
indent := strings.Repeat(" ", spaces)
|
||||
@ -509,16 +509,23 @@ func hasHashMap(cap Capability) bool {
|
||||
}
|
||||
|
||||
// registerMacroName returns the macro name for registering an optional method.
|
||||
// For "GetArtistBiography", returns "register_artist_biography".
|
||||
func registerMacroName(name string) string {
|
||||
// Remove common prefixes
|
||||
// For package "websocket" and method "OnClose", returns "register_websocket_close".
|
||||
// Also handles deduplication when method name starts with package name (e.g., "scheduler" + "OnSchedulerCallback" → "register_scheduler_callback").
|
||||
func registerMacroName(pkg, name string) string {
|
||||
// Remove common prefixes from method name
|
||||
for _, prefix := range []string{"Get", "On"} {
|
||||
if strings.HasPrefix(name, prefix) {
|
||||
name = name[len(prefix):]
|
||||
break
|
||||
}
|
||||
}
|
||||
return "register_" + ToSnakeCase(name)
|
||||
// Check if the method name starts with the package name to avoid duplication
|
||||
// e.g., package="scheduler", method="SchedulerCallback" → just "register_scheduler_callback"
|
||||
pkgTitle := strings.Title(pkg) //nolint:staticcheck
|
||||
if strings.HasPrefix(name, pkgTitle) {
|
||||
return "register_" + ToSnakeCase(name)
|
||||
}
|
||||
return "register_" + ToSnakeCase(pkg) + "_" + ToSnakeCase(name)
|
||||
}
|
||||
|
||||
// GenerateCapabilityRust generates Rust export wrapper code for a capability.
|
||||
|
||||
@ -37,10 +37,10 @@ mod rpc;
|
||||
// Register capabilities using PDK macros
|
||||
nd_pdk::register_scrobbler!(DiscordPlugin);
|
||||
nd_pdk::register_scheduler_callback!(DiscordPlugin);
|
||||
nd_pdk::register_text_message!(DiscordPlugin);
|
||||
nd_pdk::register_binary_message!(DiscordPlugin);
|
||||
nd_pdk::register_error!(DiscordPlugin);
|
||||
nd_pdk::register_close!(DiscordPlugin);
|
||||
nd_pdk::register_websocket_text_message!(DiscordPlugin);
|
||||
nd_pdk::register_websocket_binary_message!(DiscordPlugin);
|
||||
nd_pdk::register_websocket_error!(DiscordPlugin);
|
||||
nd_pdk::register_websocket_close!(DiscordPlugin);
|
||||
|
||||
// ============================================================================
|
||||
// Constants
|
||||
|
||||
@ -19,7 +19,7 @@ use nd_pdk::scheduler::{Error as SchedulerError, SchedulerCallbackProvider, Sche
|
||||
use std::fs;
|
||||
|
||||
// Register capabilities using PDK macros
|
||||
nd_pdk::register_init!(LibraryInspector);
|
||||
nd_pdk::register_lifecycle_init!(LibraryInspector);
|
||||
nd_pdk::register_scheduler_callback!(LibraryInspector);
|
||||
|
||||
// ============================================================================
|
||||
|
||||
@ -32,7 +32,7 @@ pub trait InitProvider {
|
||||
/// Register the on_init export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_init {
|
||||
macro_rules! register_lifecycle_init {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_on_init(
|
||||
|
||||
@ -212,7 +212,7 @@ pub trait ArtistMBIDProvider {
|
||||
/// Register the get_artist_mbid export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_artist_mbid {
|
||||
macro_rules! register_metadata_artist_mbid {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_get_artist_mbid(
|
||||
@ -233,7 +233,7 @@ pub trait ArtistURLProvider {
|
||||
/// Register the get_artist_url export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_artist_url {
|
||||
macro_rules! register_metadata_artist_url {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_get_artist_url(
|
||||
@ -254,7 +254,7 @@ pub trait ArtistBiographyProvider {
|
||||
/// Register the get_artist_biography export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_artist_biography {
|
||||
macro_rules! register_metadata_artist_biography {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_get_artist_biography(
|
||||
@ -275,7 +275,7 @@ pub trait SimilarArtistsProvider {
|
||||
/// Register the get_similar_artists export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_similar_artists {
|
||||
macro_rules! register_metadata_similar_artists {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_get_similar_artists(
|
||||
@ -296,7 +296,7 @@ pub trait ArtistImagesProvider {
|
||||
/// Register the get_artist_images export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_artist_images {
|
||||
macro_rules! register_metadata_artist_images {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_get_artist_images(
|
||||
@ -317,7 +317,7 @@ pub trait ArtistTopSongsProvider {
|
||||
/// Register the get_artist_top_songs export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_artist_top_songs {
|
||||
macro_rules! register_metadata_artist_top_songs {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_get_artist_top_songs(
|
||||
@ -338,7 +338,7 @@ pub trait AlbumInfoProvider {
|
||||
/// Register the get_album_info export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_album_info {
|
||||
macro_rules! register_metadata_album_info {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_get_album_info(
|
||||
@ -359,7 +359,7 @@ pub trait AlbumImagesProvider {
|
||||
/// Register the get_album_images export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_album_images {
|
||||
macro_rules! register_metadata_album_images {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_get_album_images(
|
||||
|
||||
@ -81,7 +81,7 @@ pub trait TextMessageProvider {
|
||||
/// Register the on_text_message export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_text_message {
|
||||
macro_rules! register_websocket_text_message {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_websocket_on_text_message(
|
||||
@ -102,7 +102,7 @@ pub trait BinaryMessageProvider {
|
||||
/// Register the on_binary_message export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_binary_message {
|
||||
macro_rules! register_websocket_binary_message {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_websocket_on_binary_message(
|
||||
@ -123,7 +123,7 @@ pub trait ErrorProvider {
|
||||
/// Register the on_error export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_error {
|
||||
macro_rules! register_websocket_error {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_websocket_on_error(
|
||||
@ -144,7 +144,7 @@ pub trait CloseProvider {
|
||||
/// Register the on_close export.
|
||||
/// This macro generates the WASM export function for this method.
|
||||
#[macro_export]
|
||||
macro_rules! register_close {
|
||||
macro_rules! register_websocket_close {
|
||||
($plugin_type:ty) => {
|
||||
#[extism_pdk::plugin_fn]
|
||||
pub fn nd_websocket_on_close(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user