mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-31 07:30:32 +00:00
refactor(plugins): reorganize Rust output structure to follow standard conventions
Signed-off-by: Deluan <deluan@navidrome.org>
This commit is contained in:
parent
e2d0c5626c
commit
2b2b673581
@ -228,11 +228,11 @@ type ServiceB interface {
|
|||||||
|
|
||||||
Expect(string(pyClientActual)).To(Equal(pyClientExpected), "Python client code mismatch")
|
Expect(string(pyClientActual)).To(Equal(pyClientExpected), "Python client code mismatch")
|
||||||
|
|
||||||
// Verify Rust client code (now in $output/rust/nd-pdk-host/)
|
// Verify Rust client code (now in $output/rust/nd-pdk-host/src/)
|
||||||
rustHostDir := filepath.Join(outputDir, "rust", "nd-pdk-host")
|
rustSrcDir := filepath.Join(outputDir, "rust", "nd-pdk-host", "src")
|
||||||
rsClientEntries, err := os.ReadDir(rustHostDir)
|
rsClientEntries, err := os.ReadDir(rustSrcDir)
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
Expect(rsClientEntries).To(HaveLen(2), "Expected Rust client file and lib.rs")
|
Expect(rsClientEntries).To(HaveLen(2), "Expected Rust client file and lib.rs in src/")
|
||||||
|
|
||||||
// Find the client file (not lib.rs)
|
// Find the client file (not lib.rs)
|
||||||
var rsClientName string
|
var rsClientName string
|
||||||
@ -244,7 +244,7 @@ type ServiceB interface {
|
|||||||
}
|
}
|
||||||
Expect(rsClientName).ToNot(BeEmpty(), "Expected to find Rust client file")
|
Expect(rsClientName).ToNot(BeEmpty(), "Expected to find Rust client file")
|
||||||
|
|
||||||
rsClientActual, err := os.ReadFile(filepath.Join(rustHostDir, rsClientName))
|
rsClientActual, err := os.ReadFile(filepath.Join(rustSrcDir, rsClientName))
|
||||||
Expect(err).ToNot(HaveOccurred())
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
Expect(string(rsClientActual)).To(Equal(rsClientExpected), "Rust client code mismatch")
|
Expect(string(rsClientActual)).To(Equal(rsClientExpected), "Rust client code mismatch")
|
||||||
|
|||||||
@ -36,8 +36,12 @@
|
|||||||
//! - [`{{.Name | lower}}`] - {{if .Doc}}{{.Doc | firstLine}}{{else}}{{.Name}} service{{end}}
|
//! - [`{{.Name | lower}}`] - {{if .Doc}}{{.Doc | firstLine}}{{else}}{{.Name}} service{{end}}
|
||||||
{{- end}}
|
{{- end}}
|
||||||
{{range .Services}}
|
{{range .Services}}
|
||||||
#[path = "nd_host_{{.Name | lower}}.rs"]
|
#[doc(hidden)]
|
||||||
pub mod {{.Name | lower}};
|
mod nd_host_{{.Name | lower}};
|
||||||
|
/// {{if .Doc}}{{.Doc | firstLine}}{{else}}{{.Name}} host service wrappers.{{end}}
|
||||||
|
pub mod {{.Name | lower}} {
|
||||||
|
pub use super::nd_host_{{.Name | lower}}::*;
|
||||||
|
}
|
||||||
{{end}}
|
{{end}}
|
||||||
// Re-export commonly used types from extism-pdk for convenience
|
// Re-export commonly used types from extism-pdk for convenience
|
||||||
pub use extism_pdk::Error;
|
pub use extism_pdk::Error;
|
||||||
|
|||||||
@ -577,17 +577,18 @@ func generateRustClientCode(svc internal.Service, outputDir string, dryRun, verb
|
|||||||
return fmt.Errorf("generating code: %w", err)
|
return fmt.Errorf("generating code: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rust code goes directly in the output directory
|
// Rust code goes in src/ subdirectory (standard Rust convention)
|
||||||
clientFile := filepath.Join(outputDir, "nd_host_"+strings.ToLower(svc.Name)+".rs")
|
srcDir := filepath.Join(outputDir, "src")
|
||||||
|
clientFile := filepath.Join(srcDir, "nd_host_"+strings.ToLower(svc.Name)+".rs")
|
||||||
|
|
||||||
if dryRun {
|
if dryRun {
|
||||||
fmt.Printf("=== %s ===\n%s\n", clientFile, code)
|
fmt.Printf("=== %s ===\n%s\n", clientFile, code)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create output directory if needed
|
// Create src directory if needed
|
||||||
if err := os.MkdirAll(outputDir, 0755); err != nil {
|
if err := os.MkdirAll(srcDir, 0755); err != nil {
|
||||||
return fmt.Errorf("creating rust client directory: %w", err)
|
return fmt.Errorf("creating rust src directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.WriteFile(clientFile, code, 0600); err != nil {
|
if err := os.WriteFile(clientFile, code, 0600); err != nil {
|
||||||
@ -607,17 +608,18 @@ func generateRustLibFile(services []internal.Service, outputDir string, dryRun,
|
|||||||
return fmt.Errorf("generating lib.rs: %w", err)
|
return fmt.Errorf("generating lib.rs: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// lib.rs goes directly in the output directory
|
// lib.rs goes in src/ subdirectory (standard Rust convention)
|
||||||
libFile := filepath.Join(outputDir, "lib.rs")
|
srcDir := filepath.Join(outputDir, "src")
|
||||||
|
libFile := filepath.Join(srcDir, "lib.rs")
|
||||||
|
|
||||||
if dryRun {
|
if dryRun {
|
||||||
fmt.Printf("=== %s ===\n%s\n", libFile, code)
|
fmt.Printf("=== %s ===\n%s\n", libFile, code)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create output directory if needed
|
// Create src directory if needed
|
||||||
if err := os.MkdirAll(outputDir, 0755); err != nil {
|
if err := os.MkdirAll(srcDir, 0755); err != nil {
|
||||||
return fmt.Errorf("creating rust client directory: %w", err)
|
return fmt.Errorf("creating rust src directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.WriteFile(libFile, code, 0600); err != nil {
|
if err := os.WriteFile(libFile, code, 0600); err != nil {
|
||||||
|
|||||||
@ -67,10 +67,10 @@ impl Scrobbler for WebhookPlugin {
|
|||||||
// Build query parameters
|
// Build query parameters
|
||||||
let query = format!(
|
let query = format!(
|
||||||
"?title={}&artist={}&album={}&user={}×tamp={}",
|
"?title={}&artist={}&album={}&user={}×tamp={}",
|
||||||
urlencod(&req.track.title),
|
urlencode(&req.track.title),
|
||||||
urlencod(&req.track.artist),
|
urlencode(&req.track.artist),
|
||||||
urlencod(&req.track.album),
|
urlencode(&req.track.album),
|
||||||
urlencod(&req.username),
|
urlencode(&req.username),
|
||||||
req.timestamp
|
req.timestamp
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -105,7 +105,7 @@ impl Scrobbler for WebhookPlugin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Simple URL encoding for query parameters.
|
/// Simple URL encoding for query parameters.
|
||||||
fn urlencod(s: &str) -> String {
|
fn urlencode(s: &str) -> String {
|
||||||
let mut result = String::with_capacity(s.len() * 3);
|
let mut result = String::with_capacity(s.len() * 3);
|
||||||
for c in s.chars() {
|
for c in s.chars() {
|
||||||
match c {
|
match c {
|
||||||
|
|||||||
@ -8,7 +8,6 @@ license = "GPL-3.0"
|
|||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
path = "lib.rs"
|
|
||||||
crate-type = ["rlib"]
|
crate-type = ["rlib"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|||||||
@ -40,26 +40,54 @@
|
|||||||
//! - [`subsonicapi`] - provides access to Navidrome's Subsonic API from plugins.
|
//! - [`subsonicapi`] - provides access to Navidrome's Subsonic API from plugins.
|
||||||
//! - [`websocket`] - provides WebSocket communication capabilities for plugins.
|
//! - [`websocket`] - provides WebSocket communication capabilities for plugins.
|
||||||
|
|
||||||
#[path = "nd_host_artwork.rs"]
|
#[doc(hidden)]
|
||||||
pub mod artwork;
|
mod nd_host_artwork;
|
||||||
|
/// provides artwork URL generation capabilities for plugins.
|
||||||
|
pub mod artwork {
|
||||||
|
pub use super::nd_host_artwork::*;
|
||||||
|
}
|
||||||
|
|
||||||
#[path = "nd_host_cache.rs"]
|
#[doc(hidden)]
|
||||||
pub mod cache;
|
mod nd_host_cache;
|
||||||
|
/// provides in-memory TTL-based caching capabilities for plugins.
|
||||||
|
pub mod cache {
|
||||||
|
pub use super::nd_host_cache::*;
|
||||||
|
}
|
||||||
|
|
||||||
#[path = "nd_host_kvstore.rs"]
|
#[doc(hidden)]
|
||||||
pub mod kvstore;
|
mod nd_host_kvstore;
|
||||||
|
/// provides persistent key-value storage for plugins.
|
||||||
|
pub mod kvstore {
|
||||||
|
pub use super::nd_host_kvstore::*;
|
||||||
|
}
|
||||||
|
|
||||||
#[path = "nd_host_library.rs"]
|
#[doc(hidden)]
|
||||||
pub mod library;
|
mod nd_host_library;
|
||||||
|
/// provides access to music library metadata for plugins.
|
||||||
|
pub mod library {
|
||||||
|
pub use super::nd_host_library::*;
|
||||||
|
}
|
||||||
|
|
||||||
#[path = "nd_host_scheduler.rs"]
|
#[doc(hidden)]
|
||||||
pub mod scheduler;
|
mod nd_host_scheduler;
|
||||||
|
/// provides task scheduling capabilities for plugins.
|
||||||
|
pub mod scheduler {
|
||||||
|
pub use super::nd_host_scheduler::*;
|
||||||
|
}
|
||||||
|
|
||||||
#[path = "nd_host_subsonicapi.rs"]
|
#[doc(hidden)]
|
||||||
pub mod subsonicapi;
|
mod nd_host_subsonicapi;
|
||||||
|
/// provides access to Navidrome's Subsonic API from plugins.
|
||||||
|
pub mod subsonicapi {
|
||||||
|
pub use super::nd_host_subsonicapi::*;
|
||||||
|
}
|
||||||
|
|
||||||
#[path = "nd_host_websocket.rs"]
|
#[doc(hidden)]
|
||||||
pub mod websocket;
|
mod nd_host_websocket;
|
||||||
|
/// provides WebSocket communication capabilities for plugins.
|
||||||
|
pub mod websocket {
|
||||||
|
pub use super::nd_host_websocket::*;
|
||||||
|
}
|
||||||
|
|
||||||
// Re-export commonly used types from extism-pdk for convenience
|
// Re-export commonly used types from extism-pdk for convenience
|
||||||
pub use extism_pdk::Error;
|
pub use extism_pdk::Error;
|
||||||
Loading…
x
Reference in New Issue
Block a user