-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Support
/api/v1/admin/domain_blocks
(#741)
* 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
1 parent
6cd50d3
commit 005e749
Showing
5 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; |