mirror of
https://github.com/LuanRT/YouTube.js.git
synced 2026-07-03 09:35:05 +00:00
refactor!: change getSearchSuggestions response schema
This commit is contained in:
@@ -5,10 +5,15 @@ const Proto = require('../proto');
|
||||
const Utils = require('../utils/Utils');
|
||||
const Constants = require('../utils/Constants');
|
||||
|
||||
/** namespace **/
|
||||
class Actions {
|
||||
#session;
|
||||
#request;
|
||||
|
||||
/**
|
||||
* @param {Innertube} session
|
||||
* @constructor
|
||||
*/
|
||||
constructor(session) {
|
||||
this.#session = session;
|
||||
this.#request = session.request;
|
||||
@@ -102,7 +107,7 @@ class Actions {
|
||||
throw new Utils.InnertubeError('Action not implemented', action);
|
||||
}
|
||||
|
||||
const response = await this.#request.post(action, data);
|
||||
const response = await this.#request.post(`/${action}`, data);
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -133,7 +138,7 @@ class Actions {
|
||||
throw new Utils.InnertubeError('Action not implemented', action);
|
||||
}
|
||||
|
||||
const response = await this.#request.post(action, data);
|
||||
const response = await this.#request.post(`/${action}`, data);
|
||||
return response;
|
||||
}
|
||||
|
||||
@@ -219,7 +224,7 @@ class Actions {
|
||||
throw new Utils.InnertubeError('Action not implemented', action);
|
||||
}
|
||||
|
||||
const response = await this.#request.post(action, data);
|
||||
const response = await this.#request.post(`/${action}`, data);
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -267,7 +272,7 @@ class Actions {
|
||||
throw new Utils.InnertubeError('Action not implemented', action);
|
||||
}
|
||||
|
||||
const response = await this.#request.post(action, data);
|
||||
const response = await this.#request.post(`/${action}`, data);
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -351,7 +356,7 @@ class Actions {
|
||||
throw new Utils.InnertubeError('Action not implemented', action);
|
||||
}
|
||||
|
||||
const response = await this.#request.post(action, data);
|
||||
const response = await this.#request.post(`/${action}`, data);
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -432,7 +437,7 @@ class Actions {
|
||||
throw new Utils.InnertubeError('Action not implemented', action);
|
||||
}
|
||||
|
||||
const response = await this.#request.post(action, data);
|
||||
const response = await this.#request.post(`/${action}`, data);
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -524,17 +529,25 @@ class Actions {
|
||||
*
|
||||
* @returns {Promise.<{ success: boolean; status_code: number; data: object; }>}
|
||||
*/
|
||||
async getSearchSuggestions(client, input) {
|
||||
async getSearchSuggestions(client, query) {
|
||||
if (!['YOUTUBE', 'YTMUSIC'].includes(client))
|
||||
throw new Utils.InnertubeError('Invalid client', client);
|
||||
|
||||
const response = await ({
|
||||
YOUTUBE: () => this.#request({
|
||||
baseURL: Constants.URLS.YT_SUGGESTIONS + `search?client=firefox&ds=yt&q=${encodeURIComponent(input)}`,
|
||||
url: 'search',
|
||||
baseURL: Constants.URLS.YT_SUGGESTIONS,
|
||||
params: {
|
||||
q: query,
|
||||
ds: 'yt',
|
||||
client: 'youtube',
|
||||
xssi: 't',
|
||||
oe: 'UTF',
|
||||
gl: this.#session.context.client.gl,
|
||||
hl: this.#session.context.client.hl
|
||||
}
|
||||
}),
|
||||
YTMUSIC: () => this.music('get_search_suggestions', {
|
||||
input
|
||||
})
|
||||
YTMUSIC: () => this.music('get_search_suggestions', { input: query })
|
||||
}[client])();
|
||||
|
||||
return response;
|
||||
@@ -565,7 +578,8 @@ class Actions {
|
||||
#needsLogin(id) {
|
||||
return [
|
||||
'FElibrary', 'FEhistory', 'FEsubscriptions',
|
||||
'SPaccount_notifications', 'SPaccount_privacy'
|
||||
'SPaccount_notifications', 'SPaccount_privacy',
|
||||
'SPtime_watched'
|
||||
].includes(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user