diff --git a/packages/pl-api/lib/client.ts b/packages/pl-api/lib/client.ts index 26bc5200d..a18c9fd2a 100644 --- a/packages/pl-api/lib/client.ts +++ b/packages/pl-api/lib/client.ts @@ -78,7 +78,7 @@ import { import { circleSchema } from './entities/circle'; import { type GroupedNotificationsResults, groupedNotificationsResultsSchema, type NotificationGroup } from './entities/grouped-notifications-results'; import { filteredArray } from './entities/utils'; -import { AKKOMA, type Features, getFeatures, GOTOSOCIAL, MITRA } from './features'; +import { AKKOMA, type Features, getFeatures, GOTOSOCIAL, MITRA, PIXELFED } from './features'; import request, { getNextLink, getPrevLink, type RequestBody, type RequestMeta } from './request'; import { buildFullPath } from './utils/url'; @@ -492,7 +492,7 @@ class PlApiClient { getToken: async (params: GetTokenParams) => { const response = await this.request('/oauth/token', { method: 'POST', body: params }); - return v.parse(tokenSchema, { scope: params.scope, ...response.json }); + return v.parse(tokenSchema, { scope: params.scope || '', ...response.json }); }, /** @@ -1015,7 +1015,11 @@ class PlApiClient { */ getSuggestions: async (limit?: number) => { const response = await this.request( - this.features.suggestionsV2 ? '/api/v2/suggestions' : '/api/v1/suggestions', + this.features.version.software === PIXELFED + ? '/api/v1.1/discover/accounts/popular' + : this.features.suggestionsV2 + ? '/api/v2/suggestions' + : '/api/v1/suggestions', { params: { limit } }, ); @@ -3212,7 +3216,10 @@ class PlApiClient { * @see {@link https://docs.joinmastodon.org/methods/trends/#tags} */ getTrendingTags: async (params?: GetTrendingTags) => { - const response = await this.request('/api/v1/trends/tags', { params }); + const response = await this.request( + this.features.version.software === PIXELFED ? '/api/v1.1/discover/posts/hashtags' : '/api/v1/trends/tags', + { params }, + ); return v.parse(filteredArray(tagSchema), response.json); }, @@ -3223,7 +3230,10 @@ class PlApiClient { * @see {@link https://docs.joinmastodon.org/methods/trends/#statuses} */ getTrendingStatuses: async (params?: GetTrendingStatuses) => { - const response = await this.request('/api/v1/trends/statuses', { params }); + const response = await this.request( + this.features.version.software === PIXELFED ? '/api/pixelfed/v2/discover/posts/trending' : '/api/v1/trends/statuses', + { params }, + ); return v.parse(filteredArray(statusSchema), response.json); }, diff --git a/packages/pl-api/lib/entities/tag.ts b/packages/pl-api/lib/entities/tag.ts index ae3aba9c8..2895ee193 100644 --- a/packages/pl-api/lib/entities/tag.ts +++ b/packages/pl-api/lib/entities/tag.ts @@ -14,10 +14,12 @@ const historySchema = v.array(v.object({ * @see {@link https://docs.joinmastodon.org/entities/tag} */ const tagSchema = v.object({ - name: v.pipe(v.string(), v.minLength(1)), + name: v.pipe(v.string(), v.transform(name => name.startsWith('#') ? name.slice(1) : name), v.minLength(1)), url: v.fallback(v.pipe(v.string(), v.url()), ''), history: v.fallback(v.nullable(historySchema), null), following: v.fallback(v.optional(v.boolean()), undefined), + + total: v.fallback(v.nullable(v.number()), null), }); /** diff --git a/packages/pl-api/lib/features.ts b/packages/pl-api/lib/features.ts index c0fdd6849..6ec24c436 100644 --- a/packages/pl-api/lib/features.ts +++ b/packages/pl-api/lib/features.ts @@ -1254,6 +1254,7 @@ const getFeatures = (instance: Instance) => { v.software === FRIENDICA, v.software === ICESHRIMP, v.software === MASTODON, + v.software === PIXELFED, instance.api_versions['v2_suggestions.pleroma.pl-api'] >= 1, ]), @@ -1302,8 +1303,15 @@ const getFeatures = (instance: Instance) => { v.software === FRIENDICA && gte(v.version, '2022.12.0'), v.software === ICESHRIMP, v.software === MASTODON, + v.software === PIXELFED, ]), + /** + * Display trends from a given time range. + * @see GET /api/pixelfed/v2/discover/posts/trending + */ + trendingStatusesRange: v.software === PIXELFED, + /** * Can display trending hashtags. * @see GET /api/v1/trends @@ -1314,6 +1322,7 @@ const getFeatures = (instance: Instance) => { v.software === FRIENDICA && gte(v.version, '2022.12.0'), v.software === ICESHRIMP, v.software === MASTODON, + v.software === PIXELFED, ]), /** diff --git a/packages/pl-api/lib/params/trends.ts b/packages/pl-api/lib/params/trends.ts index b4ff665c5..9f5cc6680 100644 --- a/packages/pl-api/lib/params/trends.ts +++ b/packages/pl-api/lib/params/trends.ts @@ -16,7 +16,14 @@ type GetTrendingTags = GetTrends; /** * @category Request params */ -type GetTrendingStatuses = GetTrends; +interface GetTrendingStatuses extends GetTrends { + /** + * Display trends from a given time range. + * + * Requires features{@link Features['trendingStatusesRange']}. + */ + range?: 'daily' | 'monthly' | 'yearly'; +} /** * @category Request params