use pagination

This commit is contained in:
SrGooglo 2025-04-24 12:25:35 +00:00
parent e188676dda
commit 85e1619e29
2 changed files with 372 additions and 372 deletions

View File

@ -2,87 +2,87 @@ import request from "../../request"
import Settings from "../../helpers/withSettings" import Settings from "../../helpers/withSettings"
export default class FeedModel { export default class FeedModel {
/** /**
* Retrieves music feed with optional trimming and limiting. * Retrieves music feed with optional trimming and limiting.
* *
* @param {Object} options - Optional parameters for trimming and limiting the feed * @param {Object} options - Optional parameters for trimming and limiting the feed
* @param {number} options.trim - The number of items to trim from the feed * @param {number} options.page - The number of items to page from the feed
* @param {number} options.limit - The maximum number of items to fetch from the feed * @param {number} options.limit - The maximum number of items to fetch from the feed
* @return {Promise<Object>} The music feed data * @return {Promise<Object>} The music feed data
*/ */
static async getMusicFeed({ trim, limit } = {}) { static async getMusicFeed({ page, limit } = {}) {
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/music/feed/my`, url: `/music/feed/my`,
params: { params: {
trim: trim ?? 0, page: page ?? 0,
limit: limit ?? Settings.get("feed_max_fetch"), limit: limit ?? Settings.get("feed_max_fetch"),
} },
}) })
return data return data
} }
/** /**
* Retrieves the global music feed with optional trimming and limiting. * Retrieves the global music feed with optional trimming and limiting.
* *
* @param {Object} options - An object containing optional parameters: * @param {Object} options - An object containing optional parameters:
* @param {number} options.trim - The number of items to trim from the feed * @param {number} options.page - The number of items to page from the feed
* @param {number} options.limit - The maximum number of items to fetch from the feed * @param {number} options.limit - The maximum number of items to fetch from the feed
* @return {Promise<Object>} The global music feed data * @return {Promise<Object>} The global music feed data
*/ */
static async getGlobalMusicFeed({ trim, limit } = {}) { static async getGlobalMusicFeed({ page, limit } = {}) {
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/music/feed`, url: `/music/feed`,
params: { params: {
trim: trim ?? 0, page: page ?? 0,
limit: limit ?? Settings.get("feed_max_fetch"), limit: limit ?? Settings.get("feed_max_fetch"),
} },
}) })
return data return data
} }
/** /**
* Retrieves the timeline feed with optional trimming and limiting. * Retrieves the timeline feed with optional trimming and limiting.
* *
* @param {object} options - Object containing trim and limit properties * @param {object} options - Object containing page and limit properties
* @param {number} options.trim - The number of feed items to trim * @param {number} options.page - The number of feed items to page
* @param {number} options.limit - The maximum number of feed items to retrieve * @param {number} options.limit - The maximum number of feed items to retrieve
* @return {Promise<object>} The timeline feed data * @return {Promise<object>} The timeline feed data
*/ */
static async getTimelineFeed({ trim, limit } = {}) { static async getTimelineFeed({ page, limit } = {}) {
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/posts/feed/timeline`, url: `/posts/feed/timeline`,
params: { params: {
trim: trim ?? 0, page: page ?? 0,
limit: limit ?? Settings.get("feed_max_fetch"), limit: limit ?? Settings.get("feed_max_fetch"),
} },
}) })
return data return data
} }
/** /**
* Retrieves the posts feed with options to trim and limit the results. * Retrieves the posts feed with options to page and limit the results.
* *
* @param {Object} options - An object containing optional parameters for trimming and limiting the feed. * @param {Object} options - An object containing optional parameters for trimming and limiting the feed.
* @param {number} options.trim - The number of characters to trim the feed content. * @param {number} options.page - The number of characters to page the feed content.
* @param {number} options.limit - The maximum number of posts to fetch from the feed. * @param {number} options.limit - The maximum number of posts to fetch from the feed.
* @return {Promise<Object>} The posts feed data. * @return {Promise<Object>} The posts feed data.
*/ */
static async getGlobalTimelineFeed({ trim, limit } = {}) { static async getGlobalTimelineFeed({ page, limit } = {}) {
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/posts/feed/global`, url: `/posts/feed/global`,
params: { params: {
trim: trim ?? 0, page: page ?? 0,
limit: limit ?? Settings.get("feed_max_fetch"), limit: limit ?? Settings.get("feed_max_fetch"),
} },
}) })
return data return data
} }
} }

View File

@ -2,344 +2,344 @@ import request from "../../request"
import Settings from "../../helpers/withSettings" import Settings from "../../helpers/withSettings"
export default class Post { export default class Post {
/** /**
* Retrieves the maximum length allowed for the post text. * Retrieves the maximum length allowed for the post text.
* *
* @return {number} The maximum length allowed for the post text. * @return {number} The maximum length allowed for the post text.
*/ */
static get maxPostTextLength() { static get maxPostTextLength() {
return 3200 return 3200
} }
/** /**
* Returns the maximum length allowed for a comment. * Returns the maximum length allowed for a comment.
* *
* @return {number} The maximum length allowed for a comment. * @return {number} The maximum length allowed for a comment.
*/ */
static get maxCommentLength() { static get maxCommentLength() {
return 1200 return 1200
} }
/** /**
* Retrieves the posting policy from the server. * Retrieves the posting policy from the server.
* *
* @return {Promise<Object>} The posting policy data. * @return {Promise<Object>} The posting policy data.
*/ */
static async getPostingPolicy() { static async getPostingPolicy() {
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: "/posting_policy", url: "/posting_policy",
}) })
return data return data
} }
/** /**
* Retrieves the data of a post by its ID. * Retrieves the data of a post by its ID.
* *
* @param {Object} options - The options for retrieving the post. * @param {Object} options - The options for retrieving the post.
* @param {string} options.post_id - The ID of the post to retrieve. * @param {string} options.post_id - The ID of the post to retrieve.
* @throws {Error} If the post_id is not provided. * @throws {Error} If the post_id is not provided.
* @return {Promise<Object>} The data of the post. * @return {Promise<Object>} The data of the post.
*/ */
static async post({ post_id }) { static async post({ post_id }) {
if (!post_id) { if (!post_id) {
throw new Error("Post ID is required") throw new Error("Post ID is required")
} }
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/posts/${post_id}/data`, url: `/posts/${post_id}/data`,
}) })
return data return data
} }
static getPost = Post.post static getPost = Post.post
/** /**
* Retrieves the replies of a post by its ID. * Retrieves the replies of a post by its ID.
* *
* @param {Object} options - The options for retrieving the replies. * @param {Object} options - The options for retrieving the replies.
* @param {string} options.post_id - The ID of the post to retrieve replies for. * @param {string} options.post_id - The ID of the post to retrieve replies for.
* @param {number} [options.trim=0] - The number of characters to trim the reply content. * @param {number} [options.page=0] - The number of characters to page the reply content.
* @param {number} [options.limit=Settings.get("feed_max_fetch")] - The maximum number of replies to fetch. * @param {number} [options.limit=Settings.get("feed_max_fetch")] - The maximum number of replies to fetch.
* @throws {Error} If the post_id is not provided. * @throws {Error} If the post_id is not provided.
* @return {Promise<Object>} The data of the replies. * @return {Promise<Object>} The data of the replies.
*/ */
static async replies({ post_id, trim, limit }) { static async replies({ post_id, page, limit }) {
if (!post_id) { if (!post_id) {
throw new Error("Post ID is required") throw new Error("Post ID is required")
} }
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/posts/${post_id}/replies`, url: `/posts/${post_id}/replies`,
params: { params: {
trim: trim ?? 0, page: page ?? 0,
limit: limit ?? Settings.get("feed_max_fetch"), limit: limit ?? Settings.get("feed_max_fetch"),
} },
}) })
return data return data
} }
/** /**
* Retrieves the saved posts with optional trimming and limiting. * Retrieves the saved posts with optional trimming and limiting.
* *
* @param {Object} options - The options for retrieving the saved posts. * @param {Object} options - The options for retrieving the saved posts.
* @param {number} [options.trim=0] - The number of posts to trim from the result. * @param {number} [options.page=0] - The number of posts to page from the result.
* @param {number} [options.limit=Settings.get("feed_max_fetch")] - The maximum number of posts to fetch. * @param {number} [options.limit=Settings.get("feed_max_fetch")] - The maximum number of posts to fetch.
* @return {Promise<Object>} The data of the saved posts. * @return {Promise<Object>} The data of the saved posts.
*/ */
static async getSavedPosts({ trim, limit }) { static async getSavedPosts({ page, limit }) {
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/posts/saved`, url: `/posts/saved`,
params: { params: {
trim: trim ?? 0, page: page ?? 0,
limit: limit ?? Settings.get("feed_max_fetch"), limit: limit ?? Settings.get("feed_max_fetch"),
} },
}) })
return data return data
} }
/** /**
* Retrieves the liked posts with optional trimming and limiting. * Retrieves the liked posts with optional trimming and limiting.
* *
* @param {number} trim - The number of characters to trim the post content. * @param {number} page - The number of characters to page the post content.
* @param {number} limit - The maximum number of liked posts to fetch. * @param {number} limit - The maximum number of liked posts to fetch.
* @return {Promise<Object>} The data of the liked posts. * @return {Promise<Object>} The data of the liked posts.
*/ */
static async getLikedPosts({ trim, limit }) { static async getLikedPosts({ page, limit }) {
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/posts/liked`, url: `/posts/liked`,
params: { params: {
trim: trim ?? 0, page: page ?? 0,
limit: limit ?? Settings.get("feed_max_fetch"), limit: limit ?? Settings.get("feed_max_fetch"),
} },
}) })
return data return data
} }
/** /**
* Retrieves the posts of a user with optional trimming and limiting. * Retrieves the posts of a user with optional trimming and limiting.
* *
* @param {Object} options - The options for retrieving the user's posts. * @param {Object} options - The options for retrieving the user's posts.
* @param {string} options.user_id - The ID of the user whose posts to retrieve. If not provided, the current user's ID will be used. * @param {string} options.user_id - The ID of the user whose posts to retrieve. If not provided, the current user's ID will be used.
* @param {number} [options.trim=0] - The number of characters to trim the post content. * @param {number} [options.page=0] - The number of characters to page the post content.
* @param {number} [options.limit=Settings.get("feed_max_fetch")] - The maximum number of posts to fetch. * @param {number} [options.limit=Settings.get("feed_max_fetch")] - The maximum number of posts to fetch.
* @return {Promise<Object>} The data of the user's posts. * @return {Promise<Object>} The data of the user's posts.
*/ */
static async getUserPosts({ user_id, trim, limit }) { static async getUserPosts({ user_id, page, limit }) {
if (!user_id) { if (!user_id) {
// use current user_id // use current user_id
user_id = app.userData?._id user_id = app.userData?._id
} }
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/posts/user/${user_id}`, url: `/posts/user/${user_id}`,
params: { params: {
trim: trim ?? 0, page: page ?? 0,
limit: limit ?? Settings.get("feed_max_fetch"), limit: limit ?? Settings.get("feed_max_fetch"),
} },
}) })
return data return data
} }
/** /**
* Toggles the like status of a post. * Toggles the like status of a post.
* *
* @param {Object} options - The options for toggling the like status. * @param {Object} options - The options for toggling the like status.
* @param {string} options.post_id - The ID of the post to toggle the like status. * @param {string} options.post_id - The ID of the post to toggle the like status.
* @throws {Error} If the post_id is not provided. * @throws {Error} If the post_id is not provided.
* @return {Promise<Object>} The response data after toggling the like status. * @return {Promise<Object>} The response data after toggling the like status.
*/ */
static async toggleLike({ post_id }) { static async toggleLike({ post_id }) {
if (!post_id) { if (!post_id) {
throw new Error("Post ID is required") throw new Error("Post ID is required")
} }
const { data } = await request({ const { data } = await request({
method: "POST", method: "POST",
url: `/posts/${post_id}/toggle_like`, url: `/posts/${post_id}/toggle_like`,
}) })
return data return data
} }
/** /**
* Toggles the save status of a post. * Toggles the save status of a post.
* *
* @param {string} post_id - The ID of the post to toggle the save status. * @param {string} post_id - The ID of the post to toggle the save status.
* @return {Promise<Object>} The response data after toggling the save status. * @return {Promise<Object>} The response data after toggling the save status.
*/ */
static async toggleSave({ post_id }) { static async toggleSave({ post_id }) {
if (!post_id) { if (!post_id) {
throw new Error("Post ID is required") throw new Error("Post ID is required")
} }
const { data } = await request({ const { data } = await request({
method: "POST", method: "POST",
url: `/posts/${post_id}/toggle_save`, url: `/posts/${post_id}/toggle_save`,
}) })
return data return data
} }
/** /**
* Creates a new post with the given payload. * Creates a new post with the given payload.
* *
* @param {Object} payload - The data to create the post with. * @param {Object} payload - The data to create the post with.
* @return {Promise<Object>} The response data after creating the post. * @return {Promise<Object>} The response data after creating the post.
*/ */
static async create(payload) { static async create(payload) {
const { data } = await request({ const { data } = await request({
method: "POST", method: "POST",
url: `/posts/new`, url: `/posts/new`,
data: payload, data: payload,
}) })
return data return data
} }
static createPost = Post.create static createPost = Post.create
/** /**
* Updates a post with the given post ID and update payload. * Updates a post with the given post ID and update payload.
* *
* @param {string} post_id - The ID of the post to update. * @param {string} post_id - The ID of the post to update.
* @param {Object} update - The data to update the post with. * @param {Object} update - The data to update the post with.
* @throws {Error} If the post_id is not provided. * @throws {Error} If the post_id is not provided.
* @return {Promise<Object>} The response data after updating the post. * @return {Promise<Object>} The response data after updating the post.
*/ */
static async update(post_id, update) { static async update(post_id, update) {
if (!post_id) { if (!post_id) {
throw new Error("Post ID is required") throw new Error("Post ID is required")
} }
const { data } = await request({ const { data } = await request({
method: "PUT", method: "PUT",
url: `/posts/${post_id}/update`, url: `/posts/${post_id}/update`,
data: update, data: update,
}) })
return data return data
} }
static updatePost = Post.update static updatePost = Post.update
/** /**
* Deletes a post with the given post ID. * Deletes a post with the given post ID.
* *
* @param {string} post_id - The ID of the post to delete. * @param {string} post_id - The ID of the post to delete.
* @return {Object} The response data after deleting the post. * @return {Object} The response data after deleting the post.
*/ */
static async delete({ post_id }) { static async delete({ post_id }) {
if (!post_id) { if (!post_id) {
throw new Error("Post ID is required") throw new Error("Post ID is required")
} }
const { data } = await request({ const { data } = await request({
method: "DELETE", method: "DELETE",
url: `/posts/${post_id}`, url: `/posts/${post_id}`,
}) })
return data return data
} }
static deletePost = Post.delete static deletePost = Post.delete
/** /**
* Votes for a poll with the given post ID and option ID. * Votes for a poll with the given post ID and option ID.
* *
* @param {Object} options - The options for voting. * @param {Object} options - The options for voting.
* @param {string} options.post_id - The ID of the post to vote for. * @param {string} options.post_id - The ID of the post to vote for.
* @param {string} options.option_id - The ID of the option to vote for. * @param {string} options.option_id - The ID of the option to vote for.
* @throws {Error} If the post_id or option_id is not provided. * @throws {Error} If the post_id or option_id is not provided.
* @return {Promise<Object>} The response data after voting. * @return {Promise<Object>} The response data after voting.
*/ */
static async votePoll({ post_id, option_id }) { static async votePoll({ post_id, option_id }) {
if (!post_id) { if (!post_id) {
throw new Error("post_id is required") throw new Error("post_id is required")
} }
if (!option_id) { if (!option_id) {
throw new Error("option_id is required") throw new Error("option_id is required")
} }
const { data } = await request({ const { data } = await request({
method: "POST", method: "POST",
url: `/posts/${post_id}/vote_poll/${option_id}`, url: `/posts/${post_id}/vote_poll/${option_id}`,
}) })
return data return data
} }
/** /**
* Deletes a vote for a poll with the given post ID and option ID. * Deletes a vote for a poll with the given post ID and option ID.
* *
* @param {Object} options - The options for deleting a vote. * @param {Object} options - The options for deleting a vote.
* @param {string} options.post_id - The ID of the post to delete the vote from. * @param {string} options.post_id - The ID of the post to delete the vote from.
* @param {string} options.option_id - The ID of the option to delete the vote from. * @param {string} options.option_id - The ID of the option to delete the vote from.
* @throws {Error} If the post_id or option_id is not provided. * @throws {Error} If the post_id or option_id is not provided.
* @return {Promise<Object>} The response data after deleting the vote. * @return {Promise<Object>} The response data after deleting the vote.
*/ */
static async deleteVotePoll({ post_id, option_id }) { static async deleteVotePoll({ post_id, option_id }) {
if (!post_id) { if (!post_id) {
throw new Error("post_id is required") throw new Error("post_id is required")
} }
if (!option_id) { if (!option_id) {
throw new Error("option_id is required") throw new Error("option_id is required")
} }
const { data } = await request({ const { data } = await request({
method: "DELETE", method: "DELETE",
url: `/posts/${post_id}/vote_poll/${option_id}`, url: `/posts/${post_id}/vote_poll/${option_id}`,
}) })
return data return data
} }
/** /**
* Retrieves the trending hashtags and their counts. * Retrieves the trending hashtags and their counts.
* *
* @return {Promise<Object[]>} An array of objects with two properties: "hashtag" and "count". * @return {Promise<Object[]>} An array of objects with two properties: "hashtag" and "count".
*/ */
static async getTrendings() { static async getTrendings() {
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/posts/trendings`, url: `/posts/trendings`,
}) })
return data return data
} }
/** /**
* Retrieves the trending posts for a specific hashtag with optional trimming and limiting. * Retrieves the trending posts for a specific hashtag with optional trimming and limiting.
* *
* @param {Object} options - The options for retrieving trending posts. * @param {Object} options - The options for retrieving trending posts.
* @param {string} options.trending - The hashtag to retrieve trending posts for. * @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.page=0] - The number of characters to page the post content.
* @param {number} [options.limit=Settings.get("feed_max_fetch")] - The maximum number of posts to fetch. * @param {number} [options.limit=Settings.get("feed_max_fetch")] - The maximum number of posts to fetch.
* @return {Promise<Object[]>} An array of posts that are trending for the given hashtag. * @return {Promise<Object[]>} An array of posts that are trending for the given hashtag.
*/ */
static async getTrending({ trending, trim, limit } = {}) { static async getTrending({ trending, page, limit } = {}) {
const { data } = await request({ const { data } = await request({
method: "GET", method: "GET",
url: `/posts/trending/${trending}`, url: `/posts/trending/${trending}`,
params: { params: {
trim: trim ?? 0, page: page ?? 0,
limit: limit ?? Settings.get("feed_max_fetch"), limit: limit ?? Settings.get("feed_max_fetch"),
} },
}) })
return data return data
} }
} }