Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,11 @@ customJSON<T>(method: string, params: Params): Promise<T>
```

Allows you to make a custom request to the server and parse the response as JSON.

### `buildUrl`

```ts
buildUrl(method: string, params: Record<string, unknown>) {
```

Builds a complete URL for a Subsonic API request with authentication and query parameters.
15 changes: 14 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,14 @@ export default class SubsonicAPI {
return base;
}

async #request(method: string, params?: Record<string, unknown>) {
/**
* Builds a complete URL for a Subsonic API request with authentication and query parameters.
*/
async buildUrl(method: string, params: Record<string, unknown>) {
return this.#buildUrl(method, params);
}

async #buildUrl(method: string, params?: Record<string, unknown>): Promise<URL> {
let base = this.baseURL();
if (!base.endsWith("rest/")) base += "rest/";

Expand Down Expand Up @@ -201,6 +208,12 @@ export default class SubsonicAPI {
throw new Error("no auth provided");
}

return url
}

async #request(method: string, params?: Record<string, unknown>) {
const url = await this.#buildUrl(method, params)

if (this.#config.post) {
const [path, search] = url.toString().split("?");
return this.#fetch(path, {
Expand Down