From e833038542b54fcaa6e48d5b3eec78d8c7affbbe Mon Sep 17 00:00:00 2001 From: SrGooglo Date: Sun, 17 Nov 2024 20:35:35 +0000 Subject: [PATCH] merge from local --- src/models/post/index.js | 27 +++++++++++++++++++++++++++ src/models/search/index.js | 20 ++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/src/models/post/index.js b/src/models/post/index.js index ca3270d..8c6da95 100755 --- a/src/models/post/index.js +++ b/src/models/post/index.js @@ -307,6 +307,11 @@ export default class Post { return data } + /** + * Retrieves the trending hashtags and their counts. + * + * @return {Promise} An array of objects with two properties: "hashtag" and "count". + */ static async getTrendings() { const { data } = await request({ method: "GET", @@ -315,4 +320,26 @@ export default class Post { return data } + + /** + * Retrieves the trending posts for a specific hashtag with optional trimming and limiting. + * + * @param {Object} options - The options for retrieving trending posts. + * @param {string} options.trending - The hashtag to retrieve trending posts for. + * @param {number} [options.trim=0] - The number of characters to trim the post content. + * @param {number} [options.limit=Settings.get("feed_max_fetch")] - The maximum number of posts to fetch. + * @return {Promise} An array of posts that are trending for the given hashtag. + */ + static async getTrending({ trending, trim, limit } = {}) { + const { data } = await request({ + method: "GET", + url: `/posts/trending/${trending}`, + params: { + trim: trim ?? 0, + limit: limit ?? Settings.get("feed_max_fetch"), + } + }) + + return data + } } \ No newline at end of file diff --git a/src/models/search/index.js b/src/models/search/index.js index b7551fb..dd54480 100755 --- a/src/models/search/index.js +++ b/src/models/search/index.js @@ -21,6 +21,26 @@ export default class Search { return data } + /** + * Searches for users with the given keywords and optional parameters. + * + * @param {string} keywords - The keywords to search for. + * @param {Object} [params={}] - Optional parameters for the search. + * @return {Promise} A promise that resolves with the search results. + */ + static async userSearch(keywords, {limit = 50} = {}) { + const { data } = await request({ + method: "GET", + url: `/users/search`, + params: { + keywords: keywords, + limit: limit, + } + }) + + return data + } + /** * Performs a quick search using the provided parameters. *