Skip to content

Commit

Permalink
feat: Support /api/v1/admin/domain_blocks (#741)
Browse files Browse the repository at this point in the history
* Add support for new v4 admin API endpoint - /api/v1/admin/domain_blocks

* Add support for new v4 admin API endpoint - /api/v1/admin/domain_blocks

* Add support for new v4 admin API endpoint - /api/v1/admin/domain_blocks

* Add support for new v4 admin API endpoint - /api/v1/admin/domain_blocks

* fixe the implementation of admin domain block

* change interface domainBlocks to domainBlock

* pasimg snake_case to camelCase

* fixing snake_case to camel_case and type name

* adding limit param as optional
  • Loading branch information
JacksonSamuel42 committed Dec 4, 2022
1 parent 6cd50d3 commit 005e749
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/clients/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { AdminRepositories } from '../repositories';
export class MastoAdminClient {
readonly account: AdminRepositories.AccountRepository;
readonly report: AdminRepositories.ReportRepository;
readonly domainBlocks: AdminRepositories.DomainBlocksRepository;

constructor(
private readonly http: Http,
Expand All @@ -22,6 +23,12 @@ export class MastoAdminClient {
this.version,
this.config,
);

this.domainBlocks = new AdminRepositories.DomainBlocksRepository(
this.http,
this.version,
this.config,
);
}
}

Expand Down
22 changes: 22 additions & 0 deletions src/entities/admin/domain-block.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export type SeverityType = 'silence' | 'suspend' | 'noop';

export interface DomainBlock {
/** The ID of the domain block in the database. */
id: string;
/** The domain of the domain block in the database. */
domain: string;
/** The create date of the domain block in the database. */
createdAt: string;
/** The date of the application that created this account. */
severity: SeverityType;
/** The reject media of the domain. */
rejectMedia: boolean;
/** The reject report of the domain. */
rejectReposts: boolean;
/** The private comment of the domain. */
privateComment?: string | null;
/** The public comment of the domain. */
publicComment?: string | null;
/** The obfuscate of the domain block. */
obfuscate: boolean;
}
1 change: 1 addition & 0 deletions src/entities/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export type { AccountRole, Account } from './account';
export type { Report } from './report';
export type { DomainBlock } from './domain-block';
95 changes: 95 additions & 0 deletions src/repositories/admin/domain-blocks-repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import type { MastoConfig } from '../../config';
import { version } from '../../decorators';
import type { Admin } from '../../entities';
import type { SeverityType } from '../../entities/admin/domain-block';
import type { Http } from '../../http';

export interface AdminBlockDomainParams {
/** The domain to block federation required*/
readonly domain: string;
/** Whether to apply a silence, suspend, or noop to the domain?*/
readonly severity?: SeverityType;
/** Whether media attachments should be rejected*/
readonly rejectMedia?: boolean;
/** Whether reports from this domain should be rejected*/
readonly rejectReports?: boolean;
/** A private note about this domain block, visible only to admins*/
readonly privateComment?: string | null;
/** A public note about this domain block, optionally shown on the about page*/
readonly publicComment?: string | null;
/** Whether to partially censor the domain when shown in public*/
readonly obfuscate?: boolean;
}

export type FetchAllBlockedDomainParams = {
limit?: number;
};

export type AdminDomainBlockUpdate = Omit<AdminBlockDomainParams, 'domain'>;

export class DomainBlocksRepository {
constructor(
private readonly http: Http,
readonly version: string,
readonly config: MastoConfig,
) {}

/**
*
* @param params Parameters
* @return Array of DomainBlocks
* @see https://docs.joinmastodon.org/methods/admin/
*/
@version({ since: '4.0.0' })
fetchAll(params?: FetchAllBlockedDomainParams): Promise<Admin.DomainBlock[]> {
return this.http.get('/api/v1/admin/domain_blocks', params);
}

/**
* Show information about a single blocked domain.
* @param id ID of the account
* @return DomainBlocks
* @see https://docs.joinmastodon.org/methods/admin/
*/
@version({ since: '4.0.0' })
fetch(id: string): Promise<Admin.DomainBlock> {
return this.http.get(`/api/v1/admin/domain_blocks/${id}`);
}

/**
* Add a domain to the list of domains blocked from federating.
* @param params Parameters
* @return DomainBlocks
* @see https://docs.joinmastodon.org/methods/admin/
*/
@version({ since: '4.0.0' })
block(params: AdminBlockDomainParams): Promise<Admin.DomainBlock> {
return this.http.post('/api/v1/admin/domain_blocks', params);
}

/**
* Change parameters for an existing domain block.
* @param id id of domain
* @param params Parameters
* @return DomainBlocks
* @see https://docs.joinmastodon.org/methods/admin/
*/
@version({ since: '4.0.0' })
update(
id: string,
params?: AdminDomainBlockUpdate,
): Promise<Admin.DomainBlock> {
return this.http.put(`/api/v1/admin/domain_blocks/${id}`, params);
}

/**
* Lift a block against a domain.
* @param id id of domain
* @return DomainBlocks
* @see https://docs.joinmastodon.org/methods/admin/
*/
@version({ since: '4.0.0' })
remove(id: string): Promise<void> {
return this.http.delete(`/api/v1/admin/domain_blocks/${id}`);
}
}
1 change: 1 addition & 0 deletions src/repositories/admin/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './report-repository';
export * from './account-repository';
export * from './domain-blocks-repository';

0 comments on commit 005e749

Please sign in to comment.