feat: add support for piefed new types

This commit is contained in:
James Xylight authored and xylight committed 2025-09-17 00:27:11 +00:00
1 parent 46e40abeee
commit 1a948281a8
6 files changed
+4037 -4570

No files matched your search

+145 -91
View File
@@ -31,6 +31,7 @@ import {
toSortType, toSortType,
} from './rewrite' } from './rewrite'
import type { paths } from './schema' import type { paths } from './schema'
import type { SubscribedType } from '../types'
export class PiefedClient implements BaseClient { export class PiefedClient implements BaseClient {
type: ClientType = { name: 'piefed', baseUrl: '/api/alpha' } type: ClientType = { name: 'piefed', baseUrl: '/api/alpha' }
@@ -45,7 +46,7 @@ export class PiefedClient implements BaseClient {
}, },
) { ) {
this.#client = createClient({ this.#client = createClient({
baseUrl: `${baseUrl}/api/alpha`, baseUrl: baseUrl,
// @ts-expect-error i dont feel like fixing this right now // @ts-expect-error i dont feel like fixing this right now
fetch: args.fetchFunction, fetch: args.fetchFunction,
headers: args.headers, headers: args.headers,
@@ -53,7 +54,7 @@ export class PiefedClient implements BaseClient {
} }
async getSite(): ReturnType<BaseClient['getSite']> { async getSite(): ReturnType<BaseClient['getSite']> {
const response = (await this.#client.GET('/site')).data! const response = (await this.#client.GET('/api/alpha/site', {})).data!
return { return {
admins: response.admins.map(toPersonView), admins: response.admins.map(toPersonView),
@@ -91,7 +92,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['createPost']>[0], params: Parameters<BaseClient['createPost']>[0],
): ReturnType<BaseClient['createPost']> { ): ReturnType<BaseClient['createPost']> {
const response = ( const response = (
await this.#client.POST('/post', { await this.#client.POST('/api/alpha/post', {
body: fromCreatePost(params), body: fromCreatePost(params),
}) })
).data! ).data!
@@ -104,16 +105,15 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['getPost']>[0], params: Parameters<BaseClient['getPost']>[0],
): ReturnType<BaseClient['getPost']> { ): ReturnType<BaseClient['getPost']> {
const response = ( const response = (
await this.#client.GET('/post', { await this.#client.GET('/api/alpha/post', {
// @ts-expect-error same here what is happening
params: { query: fromGetPost(params) }, params: { query: fromGetPost(params) },
}) })
).data! ).data!
return { return {
community_view: toCommunityView(response.community_view), community_view: toCommunityView(response.community_view!),
cross_posts: response.cross_posts.map(toPostView), cross_posts: response.cross_posts!.map(toPostView),
moderators: response.moderators.map((i) => ({ moderators: response.moderators!.map((i) => ({
community: toCommunity(i.community), community: toCommunity(i.community),
moderator: toPerson(i.moderator), moderator: toPerson(i.moderator),
})), })),
@@ -124,7 +124,9 @@ export class PiefedClient implements BaseClient {
async editPost( async editPost(
params: Parameters<BaseClient['editPost']>[0], params: Parameters<BaseClient['editPost']>[0],
): ReturnType<BaseClient['editPost']> { ): ReturnType<BaseClient['editPost']> {
const response = (await this.#client.PUT('/post', { body: params })).data! const response = (
await this.#client.PUT('/api/alpha/post', { body: params })
).data!
return { return {
post_view: toPostView(response.post_view), post_view: toPostView(response.post_view),
@@ -133,8 +135,9 @@ export class PiefedClient implements BaseClient {
async deletePost( async deletePost(
params: Parameters<BaseClient['deletePost']>[0], params: Parameters<BaseClient['deletePost']>[0],
): ReturnType<BaseClient['deletePost']> { ): ReturnType<BaseClient['deletePost']> {
const response = (await this.#client.POST('/post/delete', { body: params })) const response = (
.data! await this.#client.POST('/api/alpha/post/delete', { body: params })
).data!
return { return {
post_view: toPostView(response.post_view), post_view: toPostView(response.post_view),
@@ -144,8 +147,9 @@ export class PiefedClient implements BaseClient {
async removePost( async removePost(
params: Parameters<BaseClient['removePost']>[0], params: Parameters<BaseClient['removePost']>[0],
): ReturnType<BaseClient['removePost']> { ): ReturnType<BaseClient['removePost']> {
const response = (await this.#client.POST('/post/remove', { body: params })) const response = (
.data! await this.#client.POST('/api/alpha/post/remove', { body: params })
).data!
return { return {
post_view: toPostView(response.post_view), post_view: toPostView(response.post_view),
@@ -156,8 +160,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['getPosts']>[0], params: Parameters<BaseClient['getPosts']>[0],
): ReturnType<BaseClient['getPosts']> { ): ReturnType<BaseClient['getPosts']> {
const response = ( const response = (
await this.#client.GET('/post/list', { await this.#client.GET('/api/alpha/post/list', {
// @ts-expect-error same here what is happening
params: { query: fromGetPosts(params) }, params: { query: fromGetPosts(params) },
}) })
).data! ).data!
@@ -171,7 +174,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['likePost']>[0], params: Parameters<BaseClient['likePost']>[0],
): ReturnType<BaseClient['likePost']> { ): ReturnType<BaseClient['likePost']> {
const response = ( const response = (
await this.#client.POST('/post/like', { await this.#client.POST('/api/alpha/post/like', {
body: { ...params }, body: { ...params },
}) })
).data! ).data!
@@ -200,9 +203,8 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['search']>[0], params: Parameters<BaseClient['search']>[0],
): ReturnType<BaseClient['search']> { ): ReturnType<BaseClient['search']> {
const response = ( const response = (
await this.#client.GET('/search', { await this.#client.GET('/api/alpha/search', {
params: { params: {
// @ts-expect-error same here what is happening
query: fromSearch(params), query: fromSearch(params),
}, },
}) })
@@ -220,8 +222,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['resolveObject']>[0], params: Parameters<BaseClient['resolveObject']>[0],
): ReturnType<BaseClient['resolveObject']> { ): ReturnType<BaseClient['resolveObject']> {
const response = ( const response = (
await this.#client.GET('/resolve_object', { await this.#client.GET('/api/alpha/resolve_object', {
// @ts-expect-error same here what is happening
params: { query: params }, params: { query: params },
}) })
).data! ).data!
@@ -238,8 +239,9 @@ export class PiefedClient implements BaseClient {
async createCommunity( async createCommunity(
params: Parameters<BaseClient['createCommunity']>[0], params: Parameters<BaseClient['createCommunity']>[0],
): ReturnType<BaseClient['createCommunity']> { ): ReturnType<BaseClient['createCommunity']> {
const response = (await this.#client.POST('/community', { body: params })) const response = (
.data! await this.#client.POST('/api/alpha/community', { body: params })
).data!
return { return {
...response, ...response,
@@ -250,9 +252,8 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['getCommunity']>[0], params: Parameters<BaseClient['getCommunity']>[0],
): ReturnType<BaseClient['getCommunity']> { ): ReturnType<BaseClient['getCommunity']> {
const response = ( const response = (
await this.#client.GET('/community', { await this.#client.GET('/api/alpha/community', {
params: { params: {
// @ts-expect-error same here what is happening
query: params, query: params,
}, },
}) })
@@ -271,8 +272,8 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['editCommunity']>[0], params: Parameters<BaseClient['editCommunity']>[0],
): ReturnType<BaseClient['editCommunity']> { ): ReturnType<BaseClient['editCommunity']> {
const response = ( const response = (
await this.#client.PUT('/community', { await this.#client.PUT('/api/alpha/community', {
body: { ...params, id: params.community_id }, body: params,
}) })
).data! ).data!
@@ -285,9 +286,8 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['listCommunities']>[0], params: Parameters<BaseClient['listCommunities']>[0],
): ReturnType<BaseClient['listCommunities']> { ): ReturnType<BaseClient['listCommunities']> {
const response = ( const response = (
await this.#client.GET('/community/list', { await this.#client.GET('/api/alpha/community/list', {
params: { params: {
// @ts-expect-error same here what is happening
query: fromListCommunities(params), query: fromListCommunities(params),
}, },
}) })
@@ -301,7 +301,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['followCommunity']>[0], params: Parameters<BaseClient['followCommunity']>[0],
): ReturnType<BaseClient['followCommunity']> { ): ReturnType<BaseClient['followCommunity']> {
const response = ( const response = (
await this.#client.POST('/community/follow', { body: params }) await this.#client.POST('/api/alpha/community/follow', { body: params })
).data! ).data!
return { return {
@@ -313,7 +313,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['blockCommunity']>[0], params: Parameters<BaseClient['blockCommunity']>[0],
): ReturnType<BaseClient['blockCommunity']> { ): ReturnType<BaseClient['blockCommunity']> {
const response = ( const response = (
await this.#client.POST('/community/block', { body: params }) await this.#client.POST('/api/alpha/community/block', { body: params })
).data! ).data!
return { return {
@@ -325,7 +325,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['deleteCommunity']>[0], params: Parameters<BaseClient['deleteCommunity']>[0],
): ReturnType<BaseClient['deleteCommunity']> { ): ReturnType<BaseClient['deleteCommunity']> {
const response = ( const response = (
await this.#client.POST('/community/delete', { body: params }) await this.#client.POST('/api/alpha/community/delete', { body: params })
).data! ).data!
return { return {
@@ -345,7 +345,7 @@ export class PiefedClient implements BaseClient {
const response = // piefed has separate methods for ban/unban const response = // piefed has separate methods for ban/unban
( (
params.ban params.ban
? await this.#client.POST('/community/moderate/ban', { ? await this.#client.POST('/api/alpha/community/moderate/ban', {
body: { body: {
...params, ...params,
expiredAt: new Date( expiredAt: new Date(
@@ -355,7 +355,7 @@ export class PiefedClient implements BaseClient {
reason: params.reason ?? 'No reason provided.', reason: params.reason ?? 'No reason provided.',
}, },
}) })
: await this.#client.PUT('/community/moderate/unban', { : await this.#client.PUT('/api/alpha/community/moderate/unban', {
body: { body: {
community_id: params.community_id, community_id: params.community_id,
user_id: params.person_id, user_id: params.person_id,
@@ -366,7 +366,7 @@ export class PiefedClient implements BaseClient {
return { return {
banned: params.ban, banned: params.ban,
person_view: { person_view: {
person: toPerson(response.bannedUser), person: toPerson(response.banned_user!),
counts: { comment_count: -1, person_id: -1, post_count: -1 }, counts: { comment_count: -1, person_id: -1, post_count: -1 },
is_admin: false, is_admin: false,
}, },
@@ -376,7 +376,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['addModToCommunity']>[0], params: Parameters<BaseClient['addModToCommunity']>[0],
): ReturnType<BaseClient['addModToCommunity']> { ): ReturnType<BaseClient['addModToCommunity']> {
const response = ( const response = (
await this.#client.POST('/community/mod', { body: params }) await this.#client.POST('/api/alpha/community/mod', { body: params })
).data! ).data!
return { return {
@@ -389,7 +389,7 @@ export class PiefedClient implements BaseClient {
async markPostAsRead( async markPostAsRead(
params: Parameters<BaseClient['markPostAsRead']>[0], params: Parameters<BaseClient['markPostAsRead']>[0],
): ReturnType<BaseClient['markPostAsRead']> { ): ReturnType<BaseClient['markPostAsRead']> {
await this.#client.POST('/post/mark_as_read', { await this.#client.POST('/api/alpha/post/mark_as_read', {
body: { ...params }, body: { ...params },
}) })
@@ -403,8 +403,9 @@ export class PiefedClient implements BaseClient {
async lockPost( async lockPost(
params: Parameters<BaseClient['lockPost']>[0], params: Parameters<BaseClient['lockPost']>[0],
): ReturnType<BaseClient['lockPost']> { ): ReturnType<BaseClient['lockPost']> {
const response = (await this.#client.POST('/post/lock', { body: params })) const response = (
.data! await this.#client.POST('/api/alpha/post/lock', { body: params })
).data!
return { return {
...response, ...response,
@@ -415,7 +416,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['featurePost']>[0], params: Parameters<BaseClient['featurePost']>[0],
): ReturnType<BaseClient['featurePost']> { ): ReturnType<BaseClient['featurePost']> {
const response = ( const response = (
await this.#client.POST('/post/feature', { body: params }) await this.#client.POST('/api/alpha/post/feature', { body: params })
).data! ).data!
return { return {
@@ -423,14 +424,29 @@ export class PiefedClient implements BaseClient {
post_view: toPostView(response.post_view), post_view: toPostView(response.post_view),
} }
} }
async listPostLikes(): ReturnType<BaseClient['listPostLikes']> { async listPostLikes(
throw new Error('unsupported') params: Parameters<BaseClient['listPostLikes']>[0],
): ReturnType<BaseClient['listPostLikes']> {
const response = (
await this.#client.GET('/api/alpha/post/like/list', {
params: { query: params },
})
).data!
return {
post_likes: response.post_likes!.map((i) => ({
...i,
creator_banned_from_community: false,
creator: toPerson(i.creator),
})),
}
} }
async savePost( async savePost(
params: Parameters<BaseClient['savePost']>[0], params: Parameters<BaseClient['savePost']>[0],
): ReturnType<BaseClient['savePost']> { ): ReturnType<BaseClient['savePost']> {
const response = (await this.#client.PUT('/post/save', { body: params })) const response = (
.data! await this.#client.PUT('/api/alpha/post/save', { body: params })
).data!
return { return {
post_view: toPostView(response.post_view), post_view: toPostView(response.post_view),
@@ -439,8 +455,9 @@ export class PiefedClient implements BaseClient {
async createPostReport( async createPostReport(
params: Parameters<BaseClient['createPostReport']>[0], params: Parameters<BaseClient['createPostReport']>[0],
): ReturnType<BaseClient['createPostReport']> { ): ReturnType<BaseClient['createPostReport']> {
const response = (await this.#client.POST('/post/report', { body: params })) const response = (
.data! await this.#client.POST('/api/alpha/post/report', { body: params })
).data!
return { return {
post_report_view: { post_report_view: {
@@ -448,8 +465,9 @@ export class PiefedClient implements BaseClient {
community: toCommunity(response.post_report_view.community), community: toCommunity(response.post_report_view.community),
post: toPost(response.post_report_view.post), post: toPost(response.post_report_view.post),
creator: toPerson(response.post_report_view.creator), creator: toPerson(response.post_report_view.creator),
// TODO figure out if this is a bug or not
resolver: response.post_report_view.resolver resolver: response.post_report_view.resolver
? toPerson(response.post_report_view.resolver) ? toPerson(response.post_report_view.resolver!)
: undefined, : undefined,
post_creator: toPerson(response.post_report_view.post_creator), post_creator: toPerson(response.post_report_view.post_creator),
read: false, read: false,
@@ -473,7 +491,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['createComment']>[0], params: Parameters<BaseClient['createComment']>[0],
): ReturnType<BaseClient['createComment']> { ): ReturnType<BaseClient['createComment']> {
const response = ( const response = (
await this.#client.POST('/comment', { await this.#client.POST('/api/alpha/comment', {
body: fromCreateComment(params), body: fromCreateComment(params),
}) })
).data! ).data!
@@ -487,8 +505,11 @@ export class PiefedClient implements BaseClient {
async editComment( async editComment(
params: Parameters<BaseClient['editComment']>[0], params: Parameters<BaseClient['editComment']>[0],
): ReturnType<BaseClient['editComment']> { ): ReturnType<BaseClient['editComment']> {
const response = (await this.#client.PUT('/comment', { body: params })) const response = (
.data! await this.#client.PUT('/api/alpha/comment', {
body: { ...params, body: params.content },
})
).data!
return { return {
comment_view: toCommentView(response.comment_view), comment_view: toCommentView(response.comment_view),
@@ -499,7 +520,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['deleteComment']>[0], params: Parameters<BaseClient['deleteComment']>[0],
): ReturnType<BaseClient['deleteComment']> { ): ReturnType<BaseClient['deleteComment']> {
const response = ( const response = (
await this.#client.POST('/comment/delete', { body: params }) await this.#client.POST('/api/alpha/comment/delete', { body: params })
).data! ).data!
return { return {
@@ -511,7 +532,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['removeComment']>[0], params: Parameters<BaseClient['removeComment']>[0],
): ReturnType<BaseClient['removeComment']> { ): ReturnType<BaseClient['removeComment']> {
const response = ( const response = (
await this.#client.POST('/comment/remove', { body: params }) await this.#client.POST('/api/alpha/comment/remove', { body: params })
).data! ).data!
return { return {
@@ -522,17 +543,20 @@ export class PiefedClient implements BaseClient {
async markCommentReplyAsRead( async markCommentReplyAsRead(
params: Parameters<BaseClient['markCommentReplyAsRead']>[0], params: Parameters<BaseClient['markCommentReplyAsRead']>[0],
): ReturnType<BaseClient['markCommentReplyAsRead']> { ): ReturnType<BaseClient['markCommentReplyAsRead']> {
await this.#client.POST('/comment/mark_as_read', { await this.#client.POST('/api/alpha/comment/mark_as_read', {
body: params, body: params,
}) })
} }
async likeComment( async likeComment(
params: Parameters<BaseClient['likeComment']>[0], params: Parameters<BaseClient['likeComment']>[0],
): ReturnType<BaseClient['likeComment']> { ): ReturnType<BaseClient['likeComment']> {
// TODO remove any
const response = ( const response = (
await this.#client.POST('/comment/like', { await this.#client.POST('/api/alpha/comment/like', {
body: params, body: {
...params,
// TODO add private votes
private: false,
},
}) })
).data! ).data!
@@ -542,14 +566,28 @@ export class PiefedClient implements BaseClient {
} }
} }
async listCommentLikes(): ReturnType<BaseClient['listCommentLikes']> { async listCommentLikes(
throw new Error('unsupported') params: Parameters<BaseClient['listCommentLikes']>[0],
): ReturnType<BaseClient['listCommentLikes']> {
const response = (
await this.#client.GET('/api/alpha/comment/like/list', {
params: { query: params },
})
).data!
return {
comment_likes: response.comment_likes!.map((i) => ({
...i,
creator: toPerson(i.creator),
})),
}
} }
async saveComment( async saveComment(
params: Parameters<BaseClient['saveComment']>[0], params: Parameters<BaseClient['saveComment']>[0],
): ReturnType<BaseClient['saveComment']> { ): ReturnType<BaseClient['saveComment']> {
const response = (await this.#client.PUT('/comment/save', { body: params })) const response = (
.data! await this.#client.PUT('/api/alpha/comment/save', { body: params })
).data!
return { return {
...response, ...response,
@@ -565,8 +603,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['getComments']>[0], params: Parameters<BaseClient['getComments']>[0],
): ReturnType<BaseClient['getComments']> { ): ReturnType<BaseClient['getComments']> {
const response = ( const response = (
await this.#client.GET('/comment/list', { await this.#client.GET('/api/alpha/comment/list', {
// @ts-expect-error same here what is happening
params: { query: fromGetComments(params) }, params: { query: fromGetComments(params) },
}) })
).data! ).data!
@@ -579,9 +616,11 @@ export class PiefedClient implements BaseClient {
async getComment( async getComment(
params: Parameters<BaseClient['getComment']>[0], params: Parameters<BaseClient['getComment']>[0],
): ReturnType<BaseClient['getComment']> { ): ReturnType<BaseClient['getComment']> {
const response = const response = (
// @ts-expect-error same here what is happening await this.#client.GET('/api/alpha/comment', {
(await this.#client.GET('/comment', { params: { query: params } })).data! params: { query: params },
})
).data!
return { return {
...response, ...response,
@@ -593,7 +632,13 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['createCommentReport']>[0], params: Parameters<BaseClient['createCommentReport']>[0],
): ReturnType<BaseClient['createCommentReport']> { ): ReturnType<BaseClient['createCommentReport']> {
const response = ( const response = (
await this.#client.POST('/comment/report', { body: params }) await this.#client.POST('/api/alpha/comment/report', {
body: {
...params,
// TODO add remote reports
report_remote: false,
},
})
).data! ).data!
return { return {
@@ -605,9 +650,11 @@ export class PiefedClient implements BaseClient {
comment_creator: toPerson(response.comment_report_view.comment_creator), comment_creator: toPerson(response.comment_report_view.comment_creator),
creator: toPerson(response.comment_report_view.creator), creator: toPerson(response.comment_report_view.creator),
post: toPost(response.comment_report_view.post), post: toPost(response.comment_report_view.post),
// TODO figure out what's wrong here
resolver: response.comment_report_view.resolver resolver: response.comment_report_view.resolver
? toPerson(response.comment_report_view.resolver) ? toPerson(response.comment_report_view.resolver)
: undefined, : undefined,
subscribed: response.comment_report_view.subscribed as SubscribedType,
}, },
} }
} }
@@ -621,8 +668,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['getPrivateMessages']>[0], params: Parameters<BaseClient['getPrivateMessages']>[0],
): ReturnType<BaseClient['getPrivateMessages']> { ): ReturnType<BaseClient['getPrivateMessages']> {
const response = ( const response = (
await this.#client.GET('/private_message/list', { await this.#client.GET('/api/alpha/private_message/list', {
// @ts-expect-error query params are screwed up
params: { query: params }, params: { query: params },
}) })
).data! ).data!
@@ -635,7 +681,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['createPrivateMessage']>[0], params: Parameters<BaseClient['createPrivateMessage']>[0],
): ReturnType<BaseClient['createPrivateMessage']> { ): ReturnType<BaseClient['createPrivateMessage']> {
const response = ( const response = (
await this.#client.POST('/private_message', { body: params }) await this.#client.POST('/api/alpha/private_message', { body: params })
).data! ).data!
return { return {
@@ -647,7 +693,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['editPrivateMessage']>[0], params: Parameters<BaseClient['editPrivateMessage']>[0],
): ReturnType<BaseClient['editPrivateMessage']> { ): ReturnType<BaseClient['editPrivateMessage']> {
const response = ( const response = (
await this.#client.PUT('/private_message', { body: params }) await this.#client.PUT('/api/alpha/private_message', { body: params })
).data! ).data!
return { return {
@@ -659,7 +705,9 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['deletePrivateMessage']>[0], params: Parameters<BaseClient['deletePrivateMessage']>[0],
): ReturnType<BaseClient['deletePrivateMessage']> { ): ReturnType<BaseClient['deletePrivateMessage']> {
const response = ( const response = (
await this.#client.POST('/private_message/delete', { body: params }) await this.#client.POST('/api/alpha/private_message/delete', {
body: params,
})
).data! ).data!
return { return {
@@ -671,7 +719,9 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['markPrivateMessageAsRead']>[0], params: Parameters<BaseClient['markPrivateMessageAsRead']>[0],
): ReturnType<BaseClient['markPrivateMessageAsRead']> { ): ReturnType<BaseClient['markPrivateMessageAsRead']> {
const response = ( const response = (
await this.#client.POST('/private_message/mark_as_read', { body: params }) await this.#client.POST('/api/alpha/private_message/mark_as_read', {
body: params,
})
).data! ).data!
return { return {
@@ -700,7 +750,7 @@ export class PiefedClient implements BaseClient {
async login( async login(
params: Parameters<BaseClient['login']>[0], params: Parameters<BaseClient['login']>[0],
): ReturnType<BaseClient['login']> { ): ReturnType<BaseClient['login']> {
const response = await this.#client.POST('/user/login', { const response = await this.#client.POST('/api/alpha/user/login', {
body: { username: params.username_or_email, password: params.password }, body: { username: params.username_or_email, password: params.password },
})! })!
@@ -717,11 +767,10 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['getPersonDetails']>[0], params: Parameters<BaseClient['getPersonDetails']>[0],
): ReturnType<BaseClient['getPersonDetails']> { ): ReturnType<BaseClient['getPersonDetails']> {
const response = ( const response = (
await this.#client.GET('/user', { await this.#client.GET('/api/alpha/user', {
params: { params: {
query: { query: {
...params, ...params,
// @ts-expect-error more param cursedness
include_content: true, include_content: true,
sort: toSortType(params.sort), sort: toSortType(params.sort),
}, },
@@ -743,8 +792,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['getPersonMentions']>[0], params: Parameters<BaseClient['getPersonMentions']>[0],
): ReturnType<BaseClient['getPersonMentions']> { ): ReturnType<BaseClient['getPersonMentions']> {
const response = ( const response = (
await this.#client.GET('/user/mentions', { await this.#client.GET('/api/alpha/user/mentions', {
// @ts-expect-error yet another query param bug
params: { query: { ...params, sort: toCommentSortType(params.sort) } }, params: { query: { ...params, sort: toCommentSortType(params.sort) } },
}) })
).data! ).data!
@@ -757,7 +805,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['markPersonMentionAsRead']>[0], params: Parameters<BaseClient['markPersonMentionAsRead']>[0],
): ReturnType<BaseClient['markPersonMentionAsRead']> { ): ReturnType<BaseClient['markPersonMentionAsRead']> {
// @ts-expect-error this method isnt documented // @ts-expect-error this method isnt documented
await this.#client.POST('/mention/mark_as_read', { await this.#client.POST('/api/alpha/mention/mark_as_read', {
body: params, body: params,
}) })
} }
@@ -765,8 +813,7 @@ export class PiefedClient implements BaseClient {
params: Parameters<BaseClient['getReplies']>[0], params: Parameters<BaseClient['getReplies']>[0],
): ReturnType<BaseClient['getReplies']> { ): ReturnType<BaseClient['getReplies']> {
const response = ( const response = (
await this.#client.GET('/user/replies', { await this.#client.GET('/api/alpha/user/replies', {
// @ts-expect-error same here what is happening
params: { query: fromGetReplies(params) }, params: { query: fromGetReplies(params) },
}) })
).data! ).data!
@@ -786,8 +833,9 @@ export class PiefedClient implements BaseClient {
async blockPerson( async blockPerson(
params: Parameters<BaseClient['blockPerson']>[0], params: Parameters<BaseClient['blockPerson']>[0],
): ReturnType<BaseClient['blockPerson']> { ): ReturnType<BaseClient['blockPerson']> {
const response = (await this.#client.POST('/user/block', { body: params })) const response = (
.data! await this.#client.POST('/api/alpha/user/block', { body: params })
).data!
return { return {
...response, ...response,
@@ -809,7 +857,9 @@ export class PiefedClient implements BaseClient {
throw new Error('unsupported') throw new Error('unsupported')
} }
async markAllAsRead(): ReturnType<BaseClient['markAllAsRead']> { async markAllAsRead(): ReturnType<BaseClient['markAllAsRead']> {
const response = (await this.#client.POST('/user/mark_all_as_read')).data! const response = (
await this.#client.POST('/api/alpha/user/mark_all_as_read')
).data!
return { return {
replies: response.replies.map(toCommentReplyView), replies: response.replies.map(toCommentReplyView),
@@ -818,9 +868,12 @@ export class PiefedClient implements BaseClient {
async saveUserSettings( async saveUserSettings(
params: Parameters<BaseClient['saveUserSettings']>[0], params: Parameters<BaseClient['saveUserSettings']>[0],
): ReturnType<BaseClient['saveUserSettings']> { ): ReturnType<BaseClient['saveUserSettings']> {
return ( await this.#client.PUT('/api/alpha/user/save_user_settings', {
await this.#client.PUT('/user/save_user_settings', { body: params }) body: params,
).data! })
return {
success: true,
}
} }
async changePassword(): ReturnType<BaseClient['changePassword']> { async changePassword(): ReturnType<BaseClient['changePassword']> {
throw new Error('unsupported') throw new Error('unsupported')
@@ -829,7 +882,7 @@ export class PiefedClient implements BaseClient {
throw new Error('unsupported') throw new Error('unsupported')
} }
async getUnreadCount(): ReturnType<BaseClient['getUnreadCount']> { async getUnreadCount(): ReturnType<BaseClient['getUnreadCount']> {
return (await this.#client.GET('/user/unread_count')).data! return (await this.#client.GET('/api/alpha/user/unread_count')).data!
} }
async verifyEmail(): ReturnType<BaseClient['verifyEmail']> { async verifyEmail(): ReturnType<BaseClient['verifyEmail']> {
throw new Error('unsupported') throw new Error('unsupported')
@@ -872,13 +925,14 @@ export class PiefedClient implements BaseClient {
async getFederatedInstances(): ReturnType< async getFederatedInstances(): ReturnType<
BaseClient['getFederatedInstances'] BaseClient['getFederatedInstances']
> { > {
return (await this.#client.GET('/federated_instances')).data! return (await this.#client.GET('/api/alpha/federated_instances')).data!
} }
async blockInstance( async blockInstance(
params: Parameters<BaseClient['blockInstance']>[0], params: Parameters<BaseClient['blockInstance']>[0],
): ReturnType<BaseClient['blockInstance']> { ): ReturnType<BaseClient['blockInstance']> {
return (await this.#client.POST('/site/block', { body: { ...params } }))! return (await this.#client.POST('/api/alpha/site/block', {
.data! body: { ...params },
}))!.data!
} }
async uploadImage( async uploadImage(
params: Parameters<BaseClient['uploadImage']>[0], params: Parameters<BaseClient['uploadImage']>[0],
@@ -887,7 +941,7 @@ export class PiefedClient implements BaseClient {
formData.append('file', params.image as File) formData.append('file', params.image as File)
const response = ( const response = (
await this.#client.POST('/upload/image', { await this.#client.POST('/api/alpha/upload/image', {
// @ts-expect-error this is the only working way to do this // @ts-expect-error this is the only working way to do this
body: formData, body: formData,
}) })
@@ -903,7 +957,7 @@ export class PiefedClient implements BaseClient {
params: NullableFnArg<BaseClient['setFlair']>[0], params: NullableFnArg<BaseClient['setFlair']>[0],
): NullableFnReturn<BaseClient['setFlair']> { ): NullableFnReturn<BaseClient['setFlair']> {
const response = ( const response = (
await this.#client.POST('/user/set_flair', { body: params }) await this.#client.POST('/api/alpha/user/set_flair', { body: params })
).data! ).data!
return toPersonView(response.person_view) return toPersonView(response.person_view)
+7 -6
View File
@@ -22,6 +22,7 @@ import type {
PrivateMessageView, PrivateMessageView,
Search, Search,
SortType, SortType,
SubscribedType,
} from '../types' } from '../types'
import type { components } from './schema' import type { components } from './schema'
@@ -63,10 +64,10 @@ export function toCommunityView(
published: communityView.community.published, published: communityView.community.published,
community_id: communityView.community.id, community_id: communityView.community.id,
subscribers_local: communityView.counts.subscriptions_count, subscribers_local: communityView.counts.subscriptions_count,
users_active_day: communityView.counts.active_daily, users_active_day: communityView.counts.active_daily ?? -1,
users_active_half_year: communityView.counts.active_6monthly, users_active_half_year: communityView.counts.active_6monthly ?? -1,
users_active_month: communityView.counts.active_monthly, users_active_month: communityView.counts.active_monthly ?? -1,
users_active_week: communityView.counts.active_weekly, users_active_week: communityView.counts.active_weekly ?? -1,
}, },
} }
} }
@@ -152,6 +153,7 @@ export function toCommentView(
creator: toPerson(commentView.creator), creator: toPerson(commentView.creator),
post: toPost(commentView.post), post: toPost(commentView.post),
community: toCommunity(commentView.community), community: toCommunity(commentView.community),
subscribed: commentView.subscribed as SubscribedType,
} }
} }
@@ -260,10 +262,9 @@ export function fromCreatePost(
export function fromListCommunities( export function fromListCommunities(
listCommunities: ListCommunities, listCommunities: ListCommunities,
): components['schemas']['ListCommunities'] { ): components['schemas']['CommunityRequest'] {
return { return {
...listCommunities, ...listCommunities,
// @ts-expect-error ok so the api tells me something different than the actual dev api tells me to do
sort: toCommunitiesSortType(listCommunities.sort), sort: toCommunitiesSortType(listCommunities.sort),
} }
} }
+3854 -4467
View File
File diff suppressed because it is too large. Load diff
+14 -3
View File
@@ -165,7 +165,7 @@ export interface CommentReport {
creator_id: PersonId creator_id: PersonId
comment_id: CommentId comment_id: CommentId
original_comment_text: string original_comment_text: string
reason: string reason?: string
resolved: boolean resolved: boolean
resolver_id?: PersonId resolver_id?: PersonId
published: string published: string
@@ -280,7 +280,7 @@ export interface CreateCommentLike {
export interface CreateCommentReport { export interface CreateCommentReport {
comment_id: CommentId comment_id: CommentId
reason: string reason?: string
} }
export interface CreateCommunity { export interface CreateCommunity {
@@ -436,7 +436,7 @@ export interface DistinguishComment {
export interface EditComment { export interface EditComment {
comment_id: CommentId comment_id: CommentId
content?: string content: string
language_id?: LanguageId language_id?: LanguageId
} }
@@ -1685,6 +1685,7 @@ export interface PostView {
creator_blocked: boolean creator_blocked: boolean
my_vote?: number my_vote?: number
unread_comments: number unread_comments: number
flair_list?: CommunityFlair[]
} }
export interface PrivateMessage { export interface PrivateMessage {
@@ -1990,3 +1991,13 @@ export interface SetPersonFlair {
community_id: number community_id: number
flair_text: string flair_text: string
} }
export interface CommunityFlair {
id: number
community_id: number
flair_title: string
text_color: string
background_color: string
blur_images: boolean
ap_id: string | null
}
+15 -1
View File
@@ -50,7 +50,21 @@
onhide, onhide,
}: Props = $props() }: Props = $props()
let tags = $derived(parseTags(post.post.name)) let tags = $derived.by<{ title?: string; tags: Tag[] }>(() => {
const parsed = parseTags(post.post.name)
return {
title: parsed.title,
tags: [
...parsed.tags,
...(post.flair_list?.map((i) => ({
content: i.flair_title,
color: i.background_color,
icon: null,
})) ?? []),
],
}
})
let type = $derived(mediaType(post.post.url)) let type = $derived(mediaType(post.post.url))
let rule = $derived(getTagRule(tags.tags)) let rule = $derived(getTagRule(tags.tags))
let hideTitle = $derived( let hideTitle = $derived(
@@ -11,7 +11,7 @@
export interface Tag { export interface Tag {
content: string content: string
color?: string color?: string
icon?: IconSource icon?: IconSource | null
} }
export const textToTag: Map<string, Tag> = new Map<string, Tag>([ export const textToTag: Map<string, Tag> = new Map<string, Tag>([
@@ -323,7 +323,7 @@
{#snippet icon()} {#snippet icon()}
{#if tag.icon} {#if tag.icon}
<Icon src={tag.icon} micro size="14" /> <Icon src={tag.icon} micro size="14" />
{:else} {:else if tag !== null}
<Icon src={Tag} micro size="14" /> <Icon src={Tag} micro size="14" />
{/if} {/if}
{/snippet} {/snippet}