Skip to content

Enable Plugins to call the Subsonic API #4260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Jun 25, 2025
Merged

Enable Plugins to call the Subsonic API #4260

merged 15 commits into from
Jun 25, 2025

Conversation

deluan
Copy link
Member

@deluan deluan commented Jun 24, 2025

This pull request introduces significant enhancements to the Navidrome plugin system by adding support for accessing the Subsonic API from plugins. The main changes include the implementation of the SubsonicAPIService, and the addition of a demo plugin showcasing the Subsonic API integration.

Subsonic API Integration

  • plugins/host/subsonicapi/subsonicapi.proto: Defined the SubsonicAPIService with CallRequest and CallResponse messages for interacting with the Subsonic API.
  • plugins/host/subsonicapi/subsonicapi.pb.go: Generated code for the SubsonicAPIService implementation, including methods for marshaling and unmarshaling requests and responses.
  • plugins/host_subsonicapi.go: Implemented the SubsonicAPIService interface to enable plugins to make authenticated API calls to the Subsonic API.

Plugin System Enhancements

  • cmd/plugin.go: Updated plugin manager to support the new Subsonic API service and added permission handling for subsonicapi. [1] [2]
  • model/request/request.go: Added context key and helper methods for internal authentication, enabling secure API calls from plugins. [1] [2] [3]

Subsonic API Demo Plugin

  • plugins/examples/subsonicapi-demo/plugin.go: Implemented the demo plugin, showcasing how to use the SubsonicAPIService to make API calls such as /rest/ping and /rest/getLicense.
  • plugins/examples/subsonicapi-demo/README.md: Documented the demo plugin, including its capabilities, usage, and build instructions.
  • plugins/examples/subsonicapi-demo/manifest.json: Created the plugin manifest with permissions for accessing the Subsonic API.

Build System Updates

  • plugins/examples/Makefile: Added build instructions for the Subsonic API demo plugin, including WebAssembly compilation. [1] [2]

@Copilot Copilot AI review requested due to automatic review settings June 24, 2025 15:47
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @deluan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Navidrome plugin system by enabling plugins to directly interact with the server's Subsonic API. This new capability allows plugins to query and manipulate server data, opening up new possibilities for extending Navidrome's functionality. The changes involve defining a new host service, integrating it into the plugin runtime, updating authentication mechanisms to support internal plugin calls, and providing a clear example of how to use this new feature.

Highlights

  • Subsonic API Integration for Plugins: Introduced a new SubsonicAPIService that allows plugins to make authenticated calls to the Navidrome Subsonic API. This service handles URL parsing, automatically adds required Subsonic API parameters (c, f, v), and validates the presence of the u (username) parameter.
  • Secure Internal Authentication: Implemented a mechanism for plugins to securely authenticate internal API calls. A new InternalAuth context key and associated helper functions (WithInternalAuth, InternalAuthFrom) were added to model/request/request.go, allowing plugin-initiated requests to carry user context for authentication within the Subsonic API middlewares.
  • Plugin System Enhancements: Updated the core plugin manager (plugins/manager.go, plugins/runtime.go) and the plugin manifest schema (plugins/schema/manifest.schema.json, plugins/schema/manifest_gen.go) to support the new subsonicapi permission. This ensures that plugins explicitly declare their need to access the Subsonic API, and the manager can provide the necessary routing.
  • Subsonic API Demo Plugin: Added a comprehensive example plugin (plugins/examples/subsonicapi-demo) that showcases how to use the new SubsonicAPIService. This demo plugin makes calls to /rest/ping and /rest/getLicense, providing a clear blueprint for future plugin development leveraging this new capability.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR enables Navidrome plugins to call the Subsonic API by introducing a new SubsonicAPIService, updating the plugin host and CLI to register and authorize it, and providing a demo plugin to illustrate its usage.

  • Implement SubsonicAPIService interface, routing logic, and permission checks.
  • Extend plugin manifest schema, CLI output, and manager to support subsonicapi permissions.
  • Add a Subsonic API demo plugin with build scripts and documentation.

Reviewed Changes

Copilot reviewed 20 out of 21 changed files in this pull request and generated no comments.

Show a summary per file
File Description
server/subsonic/middlewares.go Merged internal and proxy auth paths but references cmp.Or incorrectly.
server/auth.go Added InternalAuth helper for internal plugin authentication.
plugins/manager.go Introduced SubsonicRouter type and SetSubsonicRouter method on Manager.
plugins/runtime.go Registered the Subsonic API host service during plugin runtime setup.
plugins/schema/manifest_gen.go Extended plugin manifest schema to include subsonicapi permissions.
plugins/host_subsonicapi.go Implemented the subsonicAPIServiceImpl handling plugin calls to Subsonic API.
Comments suppressed due to low confidence (5)

plugins/manager.go:84

  • Exported types should have a doc comment. Add a comment explaining that SubsonicRouter represents the HTTP handler for Subsonic API routes.
type SubsonicRouter http.Handler

server/auth.go:217

  • Add a doc comment for InternalAuth to explain that it extracts the internal plugin username from the request context.
func InternalAuth(r *http.Request) string {

server/subsonic/middlewares.go:51

  • The identifier cmp is undefined here. Since you imported utils/gg as a dot import, use Or(server.InternalAuth(r), server.UsernameFromReverseProxyHeader(r)) or import the package with an alias.
		username := cmp.Or(server.InternalAuth(r), server.UsernameFromReverseProxyHeader(r))

server/subsonic/middlewares.go:93

  • Reference to cmp.Or will not compile because cmp is not imported. Replace with If(…) or Or(…) from the dot-imported gg package, or add a proper import alias.
			if username := cmp.Or(internalAuth, proxyAuth); username != "" {

server/subsonic/middlewares.go:25

  • [nitpick] Dot-importing utils/gg makes it unclear where functions like Or and If come from. Consider using a named import alias (e.g., gg ".../utils/gg").
	. "github.com/navidrome/navidrome/utils/gg"

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the ability for plugins to call the Subsonic API. The changes include the implementation of the SubsonicAPIService, enhancements to the plugin system, and a demo plugin showcasing the Subsonic API integration. I have provided some feedback to improve readability and maintainability.

@deluan deluan force-pushed the plugins-subsonicapi branch 3 times, most recently from 4730290 to 1eac09a Compare June 24, 2025 17:41
deluan added 9 commits June 25, 2025 09:44
Signed-off-by: Deluan <deluan@navidrome.org>
Signed-off-by: Deluan <deluan@navidrome.org>
Signed-off-by: Deluan <deluan@navidrome.org>
…e plugin

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

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

Signed-off-by: Deluan <deluan@navidrome.org>
@deluan deluan force-pushed the plugins-subsonicapi branch from 1eac09a to 11cbc43 Compare June 25, 2025 17:15
deluan added 6 commits June 25, 2025 13:24
Signed-off-by: Deluan <deluan@navidrome.org>
Signed-off-by: Deluan <deluan@navidrome.org>
…larity and detail

Signed-off-by: Deluan <deluan@navidrome.org>
…ernames and admin flag

Signed-off-by: Deluan <deluan@navidrome.org>
Signed-off-by: Deluan <deluan@navidrome.org>
Signed-off-by: Deluan <deluan@navidrome.org>
@deluan deluan merged commit 45c408a into master Jun 25, 2025
34 of 35 checks passed
@deluan deluan deleted the plugins-subsonicapi branch June 25, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant