diff --git a/package.json b/package.json index 99d2004..9481be3 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "lemmy-js-client", "description": "A javascript / typescript client for Lemmy", - "version": "0.17.0-rc.32", + "version": "0.17.0-rc.33", "author": "Dessalines ", "license": "AGPL-3.0", "main": "./dist/index.js", diff --git a/src/http.ts b/src/http.ts index dbcb7b0..2fc5e69 100644 --- a/src/http.ts +++ b/src/http.ts @@ -115,6 +115,11 @@ import { LeaveAdmin, ListRegistrationApplications, ListRegistrationApplicationsResponse, + PurgeComment, + PurgeCommunity, + PurgeItemResponse, + PurgePerson, + PurgePost, RegistrationApplicationResponse, ResolveObject, ResolveObjectResponse, @@ -1025,6 +1030,62 @@ export class LemmyHttp { ); } + /** + * Purge / Delete a person from the database. + * + * `HTTP.POST /admin/purge/person` + */ + async purgePerson(form: PurgePerson) { + return this.wrapper( + HttpType.Post, + "/admin/purge/person", + form, + PurgeItemResponse + ); + } + + /** + * Purge / Delete a community from the database. + * + * `HTTP.POST /admin/purge/community` + */ + async purgeCommunity(form: PurgeCommunity) { + return this.wrapper( + HttpType.Post, + "/admin/purge/community", + form, + PurgeItemResponse + ); + } + + /** + * Purge / Delete a post from the database. + * + * `HTTP.POST /admin/purge/post` + */ + async purgePost(form: PurgePost) { + return this.wrapper( + HttpType.Post, + "/admin/purge/post", + form, + PurgeItemResponse + ); + } + + /** + * Purge / Delete a comment from the database. + * + * `HTTP.POST /admin/purge/comment` + */ + async purgeComment(form: PurgeComment) { + return this.wrapper( + HttpType.Post, + "/admin/purge/comment", + form, + PurgeItemResponse + ); + } + private buildFullUrl(endpoint: string): string { return `${this.apiUrl}${endpoint}`; } diff --git a/src/interfaces/api/site.ts b/src/interfaces/api/site.ts index b7089ec..63423a2 100644 --- a/src/interfaces/api/site.ts +++ b/src/interfaces/api/site.ts @@ -4,6 +4,10 @@ import "reflect-metadata"; import { toOption, toUndefined } from "../../utils"; import { ListingType, SearchType, SortType } from "../others"; import { + AdminPurgeCommentView, + AdminPurgeCommunityView, + AdminPurgePersonView, + AdminPurgePostView, CommentView, CommunityBlockView, CommunityFollowerView, @@ -140,6 +144,14 @@ export class GetModlogResponse { transferred_to_community: ModTransferCommunityView[]; @Type(() => ModAddView) added: ModAddView[]; + @Type(() => AdminPurgePersonView) + admin_purged_persons: AdminPurgePersonView[]; + @Type(() => AdminPurgeCommunityView) + admin_purged_communities: AdminPurgeCommunityView[]; + @Type(() => AdminPurgePostView) + admin_purged_posts: AdminPurgePostView[]; + @Type(() => AdminPurgeCommentView) + admin_purged_comments: AdminPurgeCommentView[]; } export class CreateSite { @@ -398,6 +410,62 @@ export class ResolveObjectResponse { person: Option; } +export class PurgePerson { + person_id: number; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + reason: Option; + auth: string; + + constructor(init: PurgePerson) { + Object.assign(this, init); + } +} + +export class PurgeCommunity { + community_id: number; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + reason: Option; + auth: string; + + constructor(init: PurgeCommunity) { + Object.assign(this, init); + } +} + +export class PurgePost { + post_id: number; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + reason: Option; + auth: string; + + constructor(init: PurgePost) { + Object.assign(this, init); + } +} + +export class PurgeComment { + comment_id: number; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + reason: Option; + auth: string; + + constructor(init: PurgeComment) { + Object.assign(this, init); + } +} + +export class PurgeItemResponse { + success: boolean; +} + export class ListRegistrationApplications { /** * Only shows the unread applications (IE those without an admin actor) diff --git a/src/interfaces/others.ts b/src/interfaces/others.ts index b88f2bc..5068485 100644 --- a/src/interfaces/others.ts +++ b/src/interfaces/others.ts @@ -73,6 +73,10 @@ export enum UserOperation { GetSiteMetadata, BlockCommunity, BlockPerson, + PurgePerson, + PurgeCommunity, + PurgePost, + PurgeComment, CreateCommentReport, ResolveCommentReport, ListCommentReports, diff --git a/src/interfaces/source.ts b/src/interfaces/source.ts index cf542cb..5831120 100644 --- a/src/interfaces/source.ts +++ b/src/interfaces/source.ts @@ -350,6 +350,48 @@ export class ModAdd { when_: string; } +export class AdminPurgePerson { + id: number; + admin_person_id: number; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + reason: Option; + when_: string; +} + +export class AdminPurgeCommunity { + id: number; + admin_person_id: number; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + reason: Option; + when_: string; +} + +export class AdminPurgePost { + id: number; + admin_person_id: number; + community_id: number; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + reason: Option; + when_: string; +} + +export class AdminPurgeComment { + id: number; + admin_person_id: number; + post_id: number; + @Transform(({ value }) => toOption(value), { toClassOnly: true }) + @Transform(({ value }) => toUndefined(value), { toPlainOnly: true }) + @Expose() + reason: Option; + when_: string; +} + export class CommunitySafe { id: number; name: string; diff --git a/src/interfaces/views.ts b/src/interfaces/views.ts index 1fd4059..331d8b6 100644 --- a/src/interfaces/views.ts +++ b/src/interfaces/views.ts @@ -11,6 +11,10 @@ import { } from "./aggregates"; import { SubscribedType } from "./others"; import { + AdminPurgeComment, + AdminPurgeCommunity, + AdminPurgePerson, + AdminPurgePost, Comment, CommentReport, CommunitySafe, @@ -289,6 +293,38 @@ export class ModStickyPostView { community: CommunitySafe; } +export class AdminPurgeCommunityView { + @Type(() => AdminPurgeCommunity) + admin_purge_community: AdminPurgeCommunity; + @Type(() => PersonSafe) + admin: PersonSafe; +} + +export class AdminPurgePersonView { + @Type(() => AdminPurgePerson) + admin_purge_person: AdminPurgePerson; + @Type(() => PersonSafe) + admin: PersonSafe; +} + +export class AdminPurgePostView { + @Type(() => AdminPurgePost) + admin_purge_post: AdminPurgePost; + @Type(() => PersonSafe) + admin: PersonSafe; + @Type(() => CommunitySafe) + community: CommunitySafe; +} + +export class AdminPurgeCommentView { + @Type(() => AdminPurgeComment) + admin_purge_comment: AdminPurgeComment; + @Type(() => PersonSafe) + admin: PersonSafe; + @Type(() => Post) + post: Post; +} + export class CommunityFollowerView { @Type(() => CommunitySafe) community: CommunitySafe; diff --git a/src/websocket.ts b/src/websocket.ts index b3b97d7..9657633 100644 --- a/src/websocket.ts +++ b/src/websocket.ts @@ -77,6 +77,10 @@ import { GetUnreadRegistrationApplicationCount, LeaveAdmin, ListRegistrationApplications, + PurgeComment, + PurgeCommunity, + PurgePerson, + PurgePost, ResolveObject, Search, } from "./interfaces/api/site"; @@ -627,6 +631,34 @@ export class LemmyWebsocket { blockCommunity(form: BlockCommunity) { return wrapper(UserOperation.BlockCommunity, form); } + + /** + * Purge / Delete a person from the database. + */ + purgePerson(form: PurgePerson) { + return wrapper(UserOperation.PurgePerson, form); + } + + /** + * Purge / Delete a community from the database. + */ + purgeCommunity(form: PurgeCommunity) { + return wrapper(UserOperation.PurgeCommunity, form); + } + + /** + * Purge / Delete a post from the database. + */ + purgePost(form: PurgePost) { + return wrapper(UserOperation.PurgePost, form); + } + + /** + * Purge / Delete a comment from the database. + */ + purgeComment(form: PurgeComment) { + return wrapper(UserOperation.PurgeComment, form); + } } function wrapper(op: UserOperation, data: MessageType) {