package subsonic import "sort" func init() { register("getOpenSubsonicExtensions", handleGetOpenSubsonicExtensions) } // extensionRegistry lists every OpenSubsonic extension VibeSonic // actually implements and has tests for. Advertising an extension here // is a promise the corresponding endpoint(s) really work — never add an // entry just because a route exists. Each feature file registers its // own entry via registerExtension() in its init(). var extensionRegistry = map[string][]int{} func registerExtension(name string, versions ...int) { if _, exists := extensionRegistry[name]; exists { panic("subsonic: duplicate extension registration for " + name) } extensionRegistry[name] = versions } func supportedExtensions() []OpenSubsonicExtension { names := make([]string, 0, len(extensionRegistry)) for n := range extensionRegistry { names = append(names, n) } sort.Strings(names) out := make([]OpenSubsonicExtension, 0, len(names)) for _, n := range names { out = append(out, OpenSubsonicExtension{Name: n, Versions: extensionRegistry[n]}) } return out } // hasExtension reports whether ext (any version) is advertised — used // where a feature is fully optional and we want to fail closed if it // were ever unregistered. func hasExtension(name string) bool { _, ok := extensionRegistry[name] return ok } func handleGetOpenSubsonicExtensions(rc *Context) *apiError { rc.Response = newResponse() rc.Response.OpenSubsonicExtensions = supportedExtensions() return nil }