lavalink-client 1.2.5 → 1.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -130,6 +130,7 @@ export declare class LavalinkNode {
|
|
|
130
130
|
* @param manager
|
|
131
131
|
*/
|
|
132
132
|
constructor(options: LavalinkNodeOptions, manager: NodeManager);
|
|
133
|
+
private rawRequest;
|
|
133
134
|
/**
|
|
134
135
|
* Makes an API call to the Node
|
|
135
136
|
* @param endpoint The endpoint that we will make the call to
|
|
@@ -138,7 +139,7 @@ export declare class LavalinkNode {
|
|
|
138
139
|
*/
|
|
139
140
|
request(endpoint: string, modify?: ModifyRequest, parseAsText?: boolean): Promise<unknown>;
|
|
140
141
|
search(query: SearchQuery, requestUser: unknown): Promise<SearchResult>;
|
|
141
|
-
lavaSearch(query: LavaSearchQuery, requestUser: unknown): Promise<SearchResult | LavaSearchResponse>;
|
|
142
|
+
lavaSearch(query: LavaSearchQuery, requestUser: unknown, throwOnEmpty?: boolean): Promise<SearchResult | LavaSearchResponse>;
|
|
142
143
|
/**
|
|
143
144
|
* Update the Player State on the Lavalink Server
|
|
144
145
|
* @param data
|
|
@@ -70,13 +70,7 @@ class LavalinkNode {
|
|
|
70
70
|
this.options.regions = (this.options.regions || []).map(a => a.toLowerCase());
|
|
71
71
|
Object.defineProperty(this, Utils_1.NodeSymbol, { configurable: true, value: true });
|
|
72
72
|
}
|
|
73
|
-
|
|
74
|
-
* Makes an API call to the Node
|
|
75
|
-
* @param endpoint The endpoint that we will make the call to
|
|
76
|
-
* @param modify Used to modify the request before being sent
|
|
77
|
-
* @returns The returned data
|
|
78
|
-
*/
|
|
79
|
-
async request(endpoint, modify, parseAsText = false) {
|
|
73
|
+
async rawRequest(endpoint, modify) {
|
|
80
74
|
const options = {
|
|
81
75
|
path: `/${this.version}/${endpoint.replace(/^\//gm, "")}`,
|
|
82
76
|
method: "GET",
|
|
@@ -91,10 +85,20 @@ class LavalinkNode {
|
|
|
91
85
|
options.path = url.pathname + url.search;
|
|
92
86
|
const request = await this.rest.request(options);
|
|
93
87
|
this.calls++;
|
|
88
|
+
return { request, options };
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Makes an API call to the Node
|
|
92
|
+
* @param endpoint The endpoint that we will make the call to
|
|
93
|
+
* @param modify Used to modify the request before being sent
|
|
94
|
+
* @returns The returned data
|
|
95
|
+
*/
|
|
96
|
+
async request(endpoint, modify, parseAsText = false) {
|
|
97
|
+
const { request, options } = await this.rawRequest(endpoint, modify);
|
|
94
98
|
if (options.method === "DELETE")
|
|
95
99
|
return;
|
|
96
100
|
if (request.statusCode === 404)
|
|
97
|
-
throw new Error(`Node Request resulted into an error, request-
|
|
101
|
+
throw new Error(`Node Request resulted into an error, request-PATH: ${options.path} | headers: ${JSON.stringify(request.headers)}`);
|
|
98
102
|
return parseAsText ? await request.body.text() : await request.body.json();
|
|
99
103
|
}
|
|
100
104
|
async search(query, requestUser) {
|
|
@@ -130,7 +134,7 @@ class LavalinkNode {
|
|
|
130
134
|
tracks: (resTracks.length ? resTracks.map(t => this.NodeManager.LavalinkManager.utils.buildTrack(t, requestUser)) : [])
|
|
131
135
|
};
|
|
132
136
|
}
|
|
133
|
-
async lavaSearch(query, requestUser) {
|
|
137
|
+
async lavaSearch(query, requestUser, throwOnEmpty = false) {
|
|
134
138
|
const Query = this.NodeManager.LavalinkManager.utils.transformLavaSearchQuery(query);
|
|
135
139
|
if (Query.source)
|
|
136
140
|
this.NodeManager.LavalinkManager.utils.validateSourceString(this, Query.source);
|
|
@@ -142,7 +146,10 @@ class LavalinkNode {
|
|
|
142
146
|
throw new RangeError(`there is no lavasearch-plugin available in the lavalink node: ${this.id}`);
|
|
143
147
|
if (!this.info.plugins.find(v => v.name === "lavasrc-plugin"))
|
|
144
148
|
throw new RangeError(`there is no lavasrc-plugin available in the lavalink node: ${this.id}`);
|
|
145
|
-
const
|
|
149
|
+
const { request } = await this.rawRequest(`/loadsearch?query=${Query.source ? `${Query.source}:` : ""}${encodeURIComponent(Query.query)}${Query.types?.length ? `&types=${Query.types.join(",")}` : ""}`);
|
|
150
|
+
if (throwOnEmpty === true)
|
|
151
|
+
throw new Error("Nothing found");
|
|
152
|
+
const res = (request.statusCode === 204 ? {} : await request.body.json());
|
|
146
153
|
return {
|
|
147
154
|
tracks: res.tracks?.map(v => this.NodeManager.LavalinkManager.utils.buildTrack(v, requestUser)) || [],
|
|
148
155
|
albums: res.albums?.map(v => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map(v => this.NodeManager.LavalinkManager.utils.buildTrack(v, requestUser)) })) || [],
|
|
@@ -130,6 +130,7 @@ export declare class LavalinkNode {
|
|
|
130
130
|
* @param manager
|
|
131
131
|
*/
|
|
132
132
|
constructor(options: LavalinkNodeOptions, manager: NodeManager);
|
|
133
|
+
private rawRequest;
|
|
133
134
|
/**
|
|
134
135
|
* Makes an API call to the Node
|
|
135
136
|
* @param endpoint The endpoint that we will make the call to
|
|
@@ -138,7 +139,7 @@ export declare class LavalinkNode {
|
|
|
138
139
|
*/
|
|
139
140
|
request(endpoint: string, modify?: ModifyRequest, parseAsText?: boolean): Promise<unknown>;
|
|
140
141
|
search(query: SearchQuery, requestUser: unknown): Promise<SearchResult>;
|
|
141
|
-
lavaSearch(query: LavaSearchQuery, requestUser: unknown): Promise<SearchResult | LavaSearchResponse>;
|
|
142
|
+
lavaSearch(query: LavaSearchQuery, requestUser: unknown, throwOnEmpty?: boolean): Promise<SearchResult | LavaSearchResponse>;
|
|
142
143
|
/**
|
|
143
144
|
* Update the Player State on the Lavalink Server
|
|
144
145
|
* @param data
|
|
@@ -66,13 +66,7 @@ export class LavalinkNode {
|
|
|
66
66
|
this.options.regions = (this.options.regions || []).map(a => a.toLowerCase());
|
|
67
67
|
Object.defineProperty(this, NodeSymbol, { configurable: true, value: true });
|
|
68
68
|
}
|
|
69
|
-
|
|
70
|
-
* Makes an API call to the Node
|
|
71
|
-
* @param endpoint The endpoint that we will make the call to
|
|
72
|
-
* @param modify Used to modify the request before being sent
|
|
73
|
-
* @returns The returned data
|
|
74
|
-
*/
|
|
75
|
-
async request(endpoint, modify, parseAsText = false) {
|
|
69
|
+
async rawRequest(endpoint, modify) {
|
|
76
70
|
const options = {
|
|
77
71
|
path: `/${this.version}/${endpoint.replace(/^\//gm, "")}`,
|
|
78
72
|
method: "GET",
|
|
@@ -87,10 +81,20 @@ export class LavalinkNode {
|
|
|
87
81
|
options.path = url.pathname + url.search;
|
|
88
82
|
const request = await this.rest.request(options);
|
|
89
83
|
this.calls++;
|
|
84
|
+
return { request, options };
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Makes an API call to the Node
|
|
88
|
+
* @param endpoint The endpoint that we will make the call to
|
|
89
|
+
* @param modify Used to modify the request before being sent
|
|
90
|
+
* @returns The returned data
|
|
91
|
+
*/
|
|
92
|
+
async request(endpoint, modify, parseAsText = false) {
|
|
93
|
+
const { request, options } = await this.rawRequest(endpoint, modify);
|
|
90
94
|
if (options.method === "DELETE")
|
|
91
95
|
return;
|
|
92
96
|
if (request.statusCode === 404)
|
|
93
|
-
throw new Error(`Node Request resulted into an error, request-
|
|
97
|
+
throw new Error(`Node Request resulted into an error, request-PATH: ${options.path} | headers: ${JSON.stringify(request.headers)}`);
|
|
94
98
|
return parseAsText ? await request.body.text() : await request.body.json();
|
|
95
99
|
}
|
|
96
100
|
async search(query, requestUser) {
|
|
@@ -126,7 +130,7 @@ export class LavalinkNode {
|
|
|
126
130
|
tracks: (resTracks.length ? resTracks.map(t => this.NodeManager.LavalinkManager.utils.buildTrack(t, requestUser)) : [])
|
|
127
131
|
};
|
|
128
132
|
}
|
|
129
|
-
async lavaSearch(query, requestUser) {
|
|
133
|
+
async lavaSearch(query, requestUser, throwOnEmpty = false) {
|
|
130
134
|
const Query = this.NodeManager.LavalinkManager.utils.transformLavaSearchQuery(query);
|
|
131
135
|
if (Query.source)
|
|
132
136
|
this.NodeManager.LavalinkManager.utils.validateSourceString(this, Query.source);
|
|
@@ -138,7 +142,10 @@ export class LavalinkNode {
|
|
|
138
142
|
throw new RangeError(`there is no lavasearch-plugin available in the lavalink node: ${this.id}`);
|
|
139
143
|
if (!this.info.plugins.find(v => v.name === "lavasrc-plugin"))
|
|
140
144
|
throw new RangeError(`there is no lavasrc-plugin available in the lavalink node: ${this.id}`);
|
|
141
|
-
const
|
|
145
|
+
const { request } = await this.rawRequest(`/loadsearch?query=${Query.source ? `${Query.source}:` : ""}${encodeURIComponent(Query.query)}${Query.types?.length ? `&types=${Query.types.join(",")}` : ""}`);
|
|
146
|
+
if (throwOnEmpty === true)
|
|
147
|
+
throw new Error("Nothing found");
|
|
148
|
+
const res = (request.statusCode === 204 ? {} : await request.body.json());
|
|
142
149
|
return {
|
|
143
150
|
tracks: res.tracks?.map(v => this.NodeManager.LavalinkManager.utils.buildTrack(v, requestUser)) || [],
|
|
144
151
|
albums: res.albums?.map(v => ({ info: v.info, pluginInfo: v?.plugin || v.pluginInfo, tracks: v.tracks.map(v => this.NodeManager.LavalinkManager.utils.buildTrack(v, requestUser)) })) || [],
|
|
@@ -130,6 +130,7 @@ export declare class LavalinkNode {
|
|
|
130
130
|
* @param manager
|
|
131
131
|
*/
|
|
132
132
|
constructor(options: LavalinkNodeOptions, manager: NodeManager);
|
|
133
|
+
private rawRequest;
|
|
133
134
|
/**
|
|
134
135
|
* Makes an API call to the Node
|
|
135
136
|
* @param endpoint The endpoint that we will make the call to
|
|
@@ -138,7 +139,7 @@ export declare class LavalinkNode {
|
|
|
138
139
|
*/
|
|
139
140
|
request(endpoint: string, modify?: ModifyRequest, parseAsText?: boolean): Promise<unknown>;
|
|
140
141
|
search(query: SearchQuery, requestUser: unknown): Promise<SearchResult>;
|
|
141
|
-
lavaSearch(query: LavaSearchQuery, requestUser: unknown): Promise<SearchResult | LavaSearchResponse>;
|
|
142
|
+
lavaSearch(query: LavaSearchQuery, requestUser: unknown, throwOnEmpty?: boolean): Promise<SearchResult | LavaSearchResponse>;
|
|
142
143
|
/**
|
|
143
144
|
* Update the Player State on the Lavalink Server
|
|
144
145
|
* @param data
|
package/package.json
CHANGED