2022-06-21 21:42:09 +00:00
|
|
|
import { ClassConstructor, deserialize, serialize } from "class-transformer";
|
2021-12-06 19:44:10 +00:00
|
|
|
import fetch from "node-fetch";
|
2020-08-20 02:25:21 +00:00
|
|
|
import {
|
2021-09-28 10:38:49 +00:00
|
|
|
CommentReportResponse,
|
2020-12-20 17:33:14 +00:00
|
|
|
CommentResponse,
|
|
|
|
CreateComment,
|
|
|
|
CreateCommentLike,
|
2021-09-28 10:38:49 +00:00
|
|
|
CreateCommentReport,
|
2020-12-20 17:33:14 +00:00
|
|
|
DeleteComment,
|
|
|
|
EditComment,
|
|
|
|
GetComments,
|
|
|
|
GetCommentsResponse,
|
2021-09-28 10:38:49 +00:00
|
|
|
ListCommentReports,
|
|
|
|
ListCommentReportsResponse,
|
2020-12-20 17:33:14 +00:00
|
|
|
MarkCommentAsRead,
|
|
|
|
RemoveComment,
|
2021-09-28 10:38:49 +00:00
|
|
|
ResolveCommentReport,
|
2020-12-20 17:33:14 +00:00
|
|
|
SaveComment,
|
2021-12-06 19:44:10 +00:00
|
|
|
} from "./interfaces/api/comment";
|
2020-12-20 17:33:14 +00:00
|
|
|
import {
|
|
|
|
AddModToCommunity,
|
|
|
|
AddModToCommunityResponse,
|
|
|
|
BanFromCommunity,
|
|
|
|
BanFromCommunityResponse,
|
2021-08-20 00:49:15 +00:00
|
|
|
BlockCommunity,
|
|
|
|
BlockCommunityResponse,
|
2020-12-20 17:33:14 +00:00
|
|
|
CommunityResponse,
|
|
|
|
CreateCommunity,
|
|
|
|
DeleteCommunity,
|
|
|
|
EditCommunity,
|
|
|
|
FollowCommunity,
|
|
|
|
GetCommunity,
|
|
|
|
GetCommunityResponse,
|
|
|
|
ListCommunities,
|
|
|
|
ListCommunitiesResponse,
|
|
|
|
RemoveCommunity,
|
|
|
|
TransferCommunity,
|
2021-12-06 19:44:10 +00:00
|
|
|
} from "./interfaces/api/community";
|
|
|
|
import {
|
|
|
|
AddAdmin,
|
|
|
|
AddAdminResponse,
|
2022-01-06 16:19:36 +00:00
|
|
|
BannedPersonsResponse,
|
2021-12-06 19:44:10 +00:00
|
|
|
BanPerson,
|
|
|
|
BanPersonResponse,
|
|
|
|
BlockPerson,
|
|
|
|
BlockPersonResponse,
|
|
|
|
ChangePassword,
|
|
|
|
CreatePrivateMessage,
|
|
|
|
DeleteAccount,
|
2021-12-30 15:27:05 +00:00
|
|
|
DeleteAccountResponse,
|
2021-12-06 19:44:10 +00:00
|
|
|
DeletePrivateMessage,
|
|
|
|
EditPrivateMessage,
|
2022-01-06 16:19:36 +00:00
|
|
|
GetBannedPersons,
|
2021-12-06 19:44:10 +00:00
|
|
|
GetCaptchaResponse,
|
|
|
|
GetPersonDetails,
|
|
|
|
GetPersonDetailsResponse,
|
|
|
|
GetPersonMentions,
|
|
|
|
GetPersonMentionsResponse,
|
|
|
|
GetPrivateMessages,
|
|
|
|
GetReplies,
|
|
|
|
GetRepliesResponse,
|
|
|
|
GetReportCount,
|
|
|
|
GetReportCountResponse,
|
|
|
|
GetUnreadCount,
|
|
|
|
GetUnreadCountResponse,
|
|
|
|
Login,
|
|
|
|
LoginResponse,
|
|
|
|
MarkAllAsRead,
|
|
|
|
MarkPersonMentionAsRead,
|
|
|
|
MarkPrivateMessageAsRead,
|
|
|
|
PasswordChange,
|
|
|
|
PasswordReset,
|
|
|
|
PasswordResetResponse,
|
|
|
|
PersonMentionResponse,
|
|
|
|
PrivateMessageResponse,
|
|
|
|
PrivateMessagesResponse,
|
|
|
|
Register,
|
|
|
|
SaveUserSettings,
|
2021-12-30 15:27:05 +00:00
|
|
|
VerifyEmail,
|
|
|
|
VerifyEmailResponse,
|
2021-12-06 19:44:10 +00:00
|
|
|
} from "./interfaces/api/person";
|
2020-12-20 17:33:14 +00:00
|
|
|
import {
|
|
|
|
CreatePost,
|
|
|
|
CreatePostLike,
|
2021-12-06 19:44:10 +00:00
|
|
|
CreatePostReport,
|
2020-12-20 17:33:14 +00:00
|
|
|
DeletePost,
|
|
|
|
EditPost,
|
|
|
|
GetPost,
|
|
|
|
GetPostResponse,
|
|
|
|
GetPosts,
|
|
|
|
GetPostsResponse,
|
2021-08-19 15:14:39 +00:00
|
|
|
GetSiteMetadata,
|
|
|
|
GetSiteMetadataResponse,
|
2021-12-06 19:44:10 +00:00
|
|
|
ListPostReports,
|
|
|
|
ListPostReportsResponse,
|
2020-12-20 17:33:14 +00:00
|
|
|
LockPost,
|
2022-05-22 19:46:20 +00:00
|
|
|
MarkPostAsRead,
|
2021-09-28 10:38:49 +00:00
|
|
|
PostReportResponse,
|
2020-12-20 17:33:14 +00:00
|
|
|
PostResponse,
|
|
|
|
RemovePost,
|
2021-12-06 19:44:10 +00:00
|
|
|
ResolvePostReport,
|
2020-12-20 17:33:14 +00:00
|
|
|
SavePost,
|
|
|
|
StickyPost,
|
2021-12-06 19:44:10 +00:00
|
|
|
} from "./interfaces/api/post";
|
2020-12-20 17:33:14 +00:00
|
|
|
import {
|
2021-12-30 15:27:05 +00:00
|
|
|
ApproveRegistrationApplication,
|
2020-12-20 17:33:14 +00:00
|
|
|
CreateSite,
|
|
|
|
EditSite,
|
|
|
|
GetModlog,
|
|
|
|
GetModlogResponse,
|
|
|
|
GetSite,
|
|
|
|
GetSiteResponse,
|
2021-12-30 15:27:05 +00:00
|
|
|
GetUnreadRegistrationApplicationCount,
|
|
|
|
GetUnreadRegistrationApplicationCountResponse,
|
2022-03-01 16:54:51 +00:00
|
|
|
LeaveAdmin,
|
2021-12-30 15:27:05 +00:00
|
|
|
ListRegistrationApplications,
|
|
|
|
ListRegistrationApplicationsResponse,
|
|
|
|
RegistrationApplicationResponse,
|
2021-08-23 20:15:24 +00:00
|
|
|
ResolveObject,
|
|
|
|
ResolveObjectResponse,
|
2020-12-20 17:33:14 +00:00
|
|
|
Search,
|
2020-08-20 02:25:21 +00:00
|
|
|
SearchResponse,
|
2020-12-20 17:33:14 +00:00
|
|
|
SiteResponse,
|
2021-12-06 19:44:10 +00:00
|
|
|
} from "./interfaces/api/site";
|
|
|
|
import { VERSION } from "./interfaces/others";
|
2021-03-29 14:29:27 +00:00
|
|
|
|
2020-08-20 02:25:21 +00:00
|
|
|
enum HttpType {
|
2021-12-06 19:44:10 +00:00
|
|
|
Get = "GET",
|
|
|
|
Post = "POST",
|
|
|
|
Put = "PUT",
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Helps build lemmy HTTP requests.
|
|
|
|
*/
|
2020-08-20 02:25:21 +00:00
|
|
|
export class LemmyHttp {
|
2021-03-29 14:29:27 +00:00
|
|
|
private apiUrl: string;
|
2020-11-12 19:42:31 +00:00
|
|
|
private headers: { [key: string]: string } = {};
|
2020-08-20 02:25:21 +00:00
|
|
|
|
2021-01-24 17:37:04 +00:00
|
|
|
/**
|
2021-08-23 01:01:40 +00:00
|
|
|
* Generates a new instance of LemmyHttp.
|
2021-03-29 14:29:27 +00:00
|
|
|
* @param baseUrl the base url, without the vX version: https://lemmy.ml -> goes to https://lemmy.ml/api/vX
|
2021-08-23 01:01:40 +00:00
|
|
|
* @param headers optional headers. Should contain `x-real-ip` and `x-forwarded-for` .
|
2021-01-24 17:37:04 +00:00
|
|
|
*/
|
2020-11-12 19:42:31 +00:00
|
|
|
constructor(baseUrl: string, headers?: { [key: string]: string }) {
|
2021-03-29 14:29:27 +00:00
|
|
|
this.apiUrl = `${baseUrl}/api/${VERSION}`;
|
2020-11-12 19:42:31 +00:00
|
|
|
|
|
|
|
if (headers) {
|
|
|
|
this.headers = headers;
|
|
|
|
}
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Gets the site, and your user data.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /site`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getSite(form: GetSite) {
|
|
|
|
return this.wrapper(HttpType.Get, "/site", form, GetSiteResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Create your site.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /site`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async createSite(form: CreateSite) {
|
|
|
|
return this.wrapper(HttpType.Post, "/site", form, SiteResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Edit your site.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /site`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async editSite(form: EditSite) {
|
|
|
|
return this.wrapper(HttpType.Put, "/site", form, SiteResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
2022-03-01 16:54:51 +00:00
|
|
|
* Leave the Site admins.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/leave_admin`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async leaveAdmin(form: LeaveAdmin) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/user/leave_admin",
|
|
|
|
form,
|
|
|
|
GetSiteResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Get the modlog.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /modlog`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getModlog(form: GetModlog) {
|
|
|
|
return this.wrapper(HttpType.Get, "/modlog", form, GetModlogResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Search lemmy.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /search`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async search(form: Search) {
|
|
|
|
return this.wrapper(HttpType.Get, "/search", form, SearchResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 20:15:24 +00:00
|
|
|
/**
|
|
|
|
* Fetch a non-local / federated object.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /resolve_object`
|
2021-08-23 20:15:24 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async resolveObject(form: ResolveObject) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/resolve_object",
|
|
|
|
form,
|
|
|
|
ResolveObjectResponse
|
|
|
|
);
|
2021-08-23 20:15:24 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Create a new community.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /community`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async createCommunity(form: CreateCommunity) {
|
|
|
|
return this.wrapper(HttpType.Post, "/community", form, CommunityResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Get / fetch a community.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /community`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getCommunity(form: GetCommunity) {
|
|
|
|
return this.wrapper(HttpType.Get, "/community", form, GetCommunityResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Edit a community.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /community`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async editCommunity(form: EditCommunity) {
|
|
|
|
return this.wrapper(HttpType.Put, "/community", form, CommunityResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* List communities, with various filters.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /community/list`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async listCommunities(form: ListCommunities) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/community/list",
|
|
|
|
form,
|
|
|
|
ListCommunitiesResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Follow / subscribe to a community.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /community/follow`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async followCommunity(form: FollowCommunity) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/community/follow",
|
|
|
|
form,
|
|
|
|
CommunityResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Block a community.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /community/block`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async blockCommunity(form: BlockCommunity) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/community/block",
|
|
|
|
form,
|
|
|
|
BlockCommunityResponse
|
|
|
|
);
|
2021-08-20 00:49:15 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Delete a community.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /community/delete`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async deleteCommunity(form: DeleteCommunity) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/community/delete",
|
|
|
|
form,
|
|
|
|
CommunityResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* A moderator remove for a community.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /community/remove`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async removeCommunity(form: RemoveCommunity) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/community/remove",
|
|
|
|
form,
|
|
|
|
CommunityResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Transfer your community to an existing moderator.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /community/transfer`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async transferCommunity(form: TransferCommunity) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/community/transfer",
|
|
|
|
form,
|
|
|
|
GetCommunityResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Ban a user from a community.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /community/ban_user`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async banFromCommunity(form: BanFromCommunity) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/community/ban_user",
|
|
|
|
form,
|
|
|
|
BanFromCommunityResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Add a moderator to your community.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /community/mod`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async addModToCommunity(form: AddModToCommunity) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/community/mod",
|
|
|
|
form,
|
|
|
|
AddModToCommunityResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Create a post.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /post`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async createPost(form: CreatePost) {
|
|
|
|
return this.wrapper(HttpType.Post, "/post", form, PostResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Get / fetch a post.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /post`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getPost(form: GetPost) {
|
|
|
|
return this.wrapper(HttpType.Get, "/post", form, GetPostResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Edit a post.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /post`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async editPost(form: EditPost) {
|
|
|
|
return this.wrapper(HttpType.Put, "/post", form, PostResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Delete a post.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /post/delete`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async deletePost(form: DeletePost) {
|
|
|
|
return this.wrapper(HttpType.Post, "/post/delete", form, PostResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* A moderator remove for a post.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /post/remove`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async removePost(form: RemovePost) {
|
|
|
|
return this.wrapper(HttpType.Post, "/post/remove", form, PostResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2022-05-22 19:46:20 +00:00
|
|
|
/**
|
|
|
|
* Mark a post as read.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:46:20 +00:00
|
|
|
* `HTTP.POST /post/mark_as_read`
|
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async markPostAsRead(form: MarkPostAsRead) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/post/mark_as_read",
|
|
|
|
form,
|
|
|
|
PostResponse
|
|
|
|
);
|
2022-05-22 19:46:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* A moderator can lock a post ( IE disable new comments ).
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /post/lock`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async lockPost(form: LockPost) {
|
|
|
|
return this.wrapper(HttpType.Post, "/post/lock", form, PostResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* A moderator can sticky a post ( IE stick it to the top of a community ).
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /post/sticky`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async stickyPost(form: StickyPost) {
|
|
|
|
return this.wrapper(HttpType.Post, "/post/sticky", form, PostResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Get / fetch posts, with various filters.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /post/list`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getPosts(form: GetPosts) {
|
|
|
|
return this.wrapper(HttpType.Get, "/post/list", form, GetPostsResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Like / vote on a post.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /post/like`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async likePost(form: CreatePostLike) {
|
|
|
|
return this.wrapper(HttpType.Post, "/post/like", form, PostResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Save a post.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /post/save`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async savePost(form: SavePost) {
|
|
|
|
return this.wrapper(HttpType.Put, "/post/save", form, PostResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 10:38:49 +00:00
|
|
|
/**
|
|
|
|
* Report a post.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /post/report`
|
2021-09-28 10:38:49 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async createPostReport(form: CreatePostReport) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/post/report",
|
|
|
|
form,
|
|
|
|
PostReportResponse
|
|
|
|
);
|
2021-09-28 10:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve a post report. Only a mod can do this.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /post/report/resolve`
|
2021-09-28 10:38:49 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async resolvePostReport(form: ResolvePostReport) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Put,
|
|
|
|
"/post/report/resolve",
|
|
|
|
form,
|
|
|
|
PostReportResponse
|
|
|
|
);
|
2021-09-28 10:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List post reports.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /post/report/list`
|
2021-09-28 10:38:49 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async listPostReports(form: ListPostReports) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/post/report/list",
|
|
|
|
form,
|
|
|
|
ListPostReportsResponse
|
|
|
|
);
|
2021-09-28 10:38:49 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Fetch metadata for any given site.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /post/site_metadata`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getSiteMetadata(form: GetSiteMetadata) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/post/site_metadata",
|
|
|
|
form,
|
|
|
|
GetSiteMetadataResponse
|
|
|
|
);
|
2021-08-19 15:14:39 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Create a comment.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /comment`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async createComment(form: CreateComment) {
|
|
|
|
return this.wrapper(HttpType.Post, "/comment", form, CommentResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Edit a comment.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /comment`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async editComment(form: EditComment) {
|
|
|
|
return this.wrapper(HttpType.Put, "/comment", form, CommentResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Delete a comment.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /comment/delete`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async deleteComment(form: DeleteComment) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/comment/delete",
|
|
|
|
form,
|
|
|
|
CommentResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* A moderator remove for a comment.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /comment/remove`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async removeComment(form: RemoveComment) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/comment/remove",
|
|
|
|
form,
|
|
|
|
CommentResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Mark a comment as read.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /comment/mark_as_read`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async markCommentAsRead(form: MarkCommentAsRead) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/comment/mark_as_read",
|
|
|
|
form,
|
|
|
|
CommentResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Like / vote on a comment.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /comment/like`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async likeComment(form: CreateCommentLike) {
|
|
|
|
return this.wrapper(HttpType.Post, "/comment/like", form, CommentResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Save a comment.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /comment/save`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async saveComment(form: SaveComment) {
|
|
|
|
return this.wrapper(HttpType.Put, "/comment/save", form, CommentResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Get / fetch comments.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /comment/list`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getComments(form: GetComments) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/comment/list",
|
|
|
|
form,
|
|
|
|
GetCommentsResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 10:38:49 +00:00
|
|
|
/**
|
|
|
|
* Report a comment.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /comment/report`
|
2021-09-28 10:38:49 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async createCommentReport(form: CreateCommentReport) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/comment/report",
|
|
|
|
form,
|
|
|
|
CommentReportResponse
|
|
|
|
);
|
2021-09-28 10:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Resolve a comment report. Only a mod can do this.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /comment/report/resolve`
|
2021-09-28 10:38:49 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async resolveCommentReport(form: ResolveCommentReport) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Put,
|
|
|
|
"/comment/report/resolve",
|
|
|
|
form,
|
|
|
|
CommentReportResponse
|
|
|
|
);
|
2021-09-28 10:38:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List comment reports.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /comment/report/list`
|
2021-09-28 10:38:49 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async listCommentReports(form: ListCommentReports) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/comment/report/list",
|
|
|
|
form,
|
|
|
|
ListCommentReportsResponse
|
|
|
|
);
|
2021-09-28 10:38:49 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Get / fetch private messages.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /private_message/list`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getPrivateMessages(form: GetPrivateMessages) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/private_message/list",
|
|
|
|
form,
|
|
|
|
PrivateMessagesResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Create a private message.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /private_message`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async createPrivateMessage(form: CreatePrivateMessage) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/private_message",
|
|
|
|
form,
|
|
|
|
PrivateMessageResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Edit a private message.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /private_message`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async editPrivateMessage(form: EditPrivateMessage) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Put,
|
|
|
|
"/private_message",
|
|
|
|
form,
|
|
|
|
PrivateMessageResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Delete a private message.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /private_message/delete`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async deletePrivateMessage(form: DeletePrivateMessage) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/private_message/delete",
|
|
|
|
form,
|
|
|
|
PrivateMessageResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Mark a private message as read.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /private_message/mark_as_read`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async markPrivateMessageAsRead(form: MarkPrivateMessageAsRead) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/private_message/mark_as_read",
|
|
|
|
form,
|
|
|
|
PrivateMessageResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Register a new user.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/register`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async register(form: Register) {
|
|
|
|
return this.wrapper(HttpType.Post, "/user/register", form, LoginResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Log into lemmy.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/login`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async login(form: Login) {
|
|
|
|
return this.wrapper(HttpType.Post, "/user/login", form, LoginResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Get the details for a person.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /user`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getPersonDetails(form: GetPersonDetails) {
|
|
|
|
return this.wrapper(HttpType.Get, "/user", form, GetPersonDetailsResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Get mentions for your user.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /user/mention`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getPersonMentions(form: GetPersonMentions) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/user/mention",
|
|
|
|
form,
|
|
|
|
GetPersonMentionsResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Mark a person mention as read.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/mention/mark_as_read`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async markPersonMentionAsRead(form: MarkPersonMentionAsRead) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/user/mention/mark_as_read",
|
|
|
|
form,
|
|
|
|
PersonMentionResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Get comment replies.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /user/replies`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getReplies(form: GetReplies) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/user/replies",
|
|
|
|
form,
|
|
|
|
GetRepliesResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Ban a person from your site.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/ban`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async banPerson(form: BanPerson) {
|
|
|
|
return this.wrapper(HttpType.Post, "/user/ban", form, BanPersonResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2022-01-06 16:19:36 +00:00
|
|
|
/**
|
|
|
|
* Get a list of banned users
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /user/banned`
|
2022-01-06 16:19:36 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getBannedPersons(form: GetBannedPersons) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/user/banned",
|
|
|
|
form,
|
|
|
|
BannedPersonsResponse
|
|
|
|
);
|
2022-01-06 16:19:36 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Block a person.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/block`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async blockPerson(form: BlockPerson) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/user/block",
|
|
|
|
form,
|
|
|
|
BlockPersonResponse
|
|
|
|
);
|
2021-08-20 00:49:15 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Fetch a Captcha.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /user/get_captcha`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getCaptcha() {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/user/get_captcha",
|
|
|
|
{},
|
|
|
|
GetCaptchaResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Delete your account.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/delete_account`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async deleteAccount(form: DeleteAccount) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/user/delete_account",
|
|
|
|
form,
|
|
|
|
DeleteAccountResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Reset your password.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/password_reset`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async passwordReset(form: PasswordReset) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/user/password_reset",
|
|
|
|
form,
|
|
|
|
PasswordResetResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Change your password from an email / token based reset.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/password_change`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async passwordChange(form: PasswordChange) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/user/password_change",
|
|
|
|
form,
|
|
|
|
LoginResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Mark all replies as read.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/mark_all_as_read`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async markAllAsRead(form: MarkAllAsRead) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/user/mark_all_as_read",
|
|
|
|
form,
|
|
|
|
GetRepliesResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Save your user settings.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /user/save_user_settings`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async saveUserSettings(form: SaveUserSettings) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Put,
|
|
|
|
"/user/save_user_settings",
|
|
|
|
form,
|
|
|
|
LoginResponse
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Change your user password.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /user/change_password`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async changePassword(form: ChangePassword) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Put,
|
|
|
|
"/user/change_password",
|
|
|
|
form,
|
|
|
|
LoginResponse
|
|
|
|
);
|
2021-04-01 21:35:37 +00:00
|
|
|
}
|
|
|
|
|
2021-09-28 10:38:49 +00:00
|
|
|
/**
|
|
|
|
* Get counts for your reports
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /user/report_count`
|
2021-09-28 10:38:49 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getReportCount(form: GetReportCount) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/user/report_count",
|
|
|
|
form,
|
|
|
|
GetReportCountResponse
|
|
|
|
);
|
2021-09-28 10:38:49 +00:00
|
|
|
}
|
|
|
|
|
2021-10-17 17:42:40 +00:00
|
|
|
/**
|
|
|
|
* Get your unread counts
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /user/unread_count`
|
2021-10-17 17:42:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async getUnreadCount(form: GetUnreadCount) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/user/unread_count",
|
|
|
|
form,
|
|
|
|
GetUnreadCountResponse
|
|
|
|
);
|
2021-10-17 17:42:40 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 15:27:05 +00:00
|
|
|
/**
|
|
|
|
* Verify your email
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /user/verify_email`
|
2021-12-30 15:27:05 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async verifyEmail(form: VerifyEmail) {
|
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Post,
|
|
|
|
"/user/verify_email",
|
|
|
|
form,
|
|
|
|
VerifyEmailResponse
|
|
|
|
);
|
2021-12-30 15:27:05 +00:00
|
|
|
}
|
|
|
|
|
2021-08-23 01:01:40 +00:00
|
|
|
/**
|
|
|
|
* Add an admin to your site.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.POST /admin/add`
|
2021-08-23 01:01:40 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async addAdmin(form: AddAdmin) {
|
|
|
|
return this.wrapper(HttpType.Post, "/admin/add", form, AddAdminResponse);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2021-12-30 15:27:05 +00:00
|
|
|
/**
|
|
|
|
* Get the unread registration applications count.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /admin/registration_application/count`
|
2021-12-30 15:27:05 +00:00
|
|
|
*/
|
|
|
|
async getUnreadRegistrationApplicationCount(
|
|
|
|
form: GetUnreadRegistrationApplicationCount
|
2022-06-21 21:42:09 +00:00
|
|
|
) {
|
2021-12-30 15:27:05 +00:00
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/admin/registration_application/count",
|
2022-06-21 21:42:09 +00:00
|
|
|
form,
|
|
|
|
GetUnreadRegistrationApplicationCountResponse
|
2021-12-30 15:27:05 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2022-05-22 19:45:53 +00:00
|
|
|
* List the registration applications.
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.GET /admin/registration_application/list`
|
2021-12-30 15:27:05 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async listRegistrationApplications(form: ListRegistrationApplications) {
|
2021-12-30 15:27:05 +00:00
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Get,
|
|
|
|
"/admin/registration_application/list",
|
2022-06-21 21:42:09 +00:00
|
|
|
form,
|
|
|
|
ListRegistrationApplicationsResponse
|
2021-12-30 15:27:05 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Approve a registration application
|
2022-06-21 21:42:09 +00:00
|
|
|
*
|
2022-05-22 19:45:53 +00:00
|
|
|
* `HTTP.PUT /admin/registration_application/approve`
|
2021-12-30 15:27:05 +00:00
|
|
|
*/
|
2022-06-21 21:42:09 +00:00
|
|
|
async approveRegistrationApplication(form: ApproveRegistrationApplication) {
|
2021-12-30 15:27:05 +00:00
|
|
|
return this.wrapper(
|
|
|
|
HttpType.Put,
|
|
|
|
"/admin/registration_application/approve",
|
2022-06-21 21:42:09 +00:00
|
|
|
form,
|
|
|
|
RegistrationApplicationResponse
|
2021-12-30 15:27:05 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-20 02:25:21 +00:00
|
|
|
private buildFullUrl(endpoint: string): string {
|
2021-03-29 14:29:27 +00:00
|
|
|
return `${this.apiUrl}${endpoint}`;
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:09 +00:00
|
|
|
private async wrapper<ResponseType, BodyType>(
|
2020-08-20 02:25:21 +00:00
|
|
|
type_: HttpType,
|
|
|
|
endpoint: string,
|
2022-06-21 21:42:09 +00:00
|
|
|
form: BodyType,
|
|
|
|
responseClass: ClassConstructor<ResponseType>
|
2020-12-20 19:21:26 +00:00
|
|
|
): Promise<ResponseType> {
|
2020-08-20 02:25:21 +00:00
|
|
|
if (type_ == HttpType.Get) {
|
2020-08-20 03:51:57 +00:00
|
|
|
let getUrl = `${this.buildFullUrl(endpoint)}?${encodeGetParams(form)}`;
|
2022-06-21 21:42:09 +00:00
|
|
|
return (
|
|
|
|
fetch(getUrl, {
|
|
|
|
method: "GET",
|
|
|
|
headers: this.headers,
|
|
|
|
})
|
|
|
|
// TODO test this
|
|
|
|
.then(
|
|
|
|
d =>
|
|
|
|
d
|
|
|
|
.text()
|
|
|
|
.then(a =>
|
|
|
|
deserialize(responseClass, a)
|
|
|
|
) as Promise<ResponseType>
|
|
|
|
)
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
} else {
|
|
|
|
return fetch(this.buildFullUrl(endpoint), {
|
|
|
|
method: type_,
|
|
|
|
headers: {
|
2021-12-06 19:44:10 +00:00
|
|
|
"Content-Type": "application/json",
|
2020-11-12 19:42:31 +00:00
|
|
|
...this.headers,
|
2020-08-20 02:25:21 +00:00
|
|
|
},
|
2022-06-21 21:42:09 +00:00
|
|
|
body: serialize(form),
|
2021-09-28 16:08:22 +00:00
|
|
|
}).then(d => d.json() as Promise<ResponseType>);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-21 21:42:09 +00:00
|
|
|
function encodeGetParams<BodyType>(p: BodyType): string {
|
|
|
|
// Necessary to remove the Options
|
|
|
|
let serialized = JSON.parse(serialize(p));
|
|
|
|
return (
|
|
|
|
Object.entries(serialized)
|
|
|
|
// TODO test this, it might serialize the undefineds
|
|
|
|
.map(kv => kv.map(encodeURIComponent).join("="))
|
|
|
|
.join("&")
|
|
|
|
);
|
2020-08-20 02:25:21 +00:00
|
|
|
}
|