diff --git a/app/javascript/mastodon/api.ts b/app/javascript/mastodon/api.ts index e133125a2..24672290c 100644 --- a/app/javascript/mastodon/api.ts +++ b/app/javascript/mastodon/api.ts @@ -59,16 +59,49 @@ export default function api(withAuthorization = true) { }); } +type RequestParamsOrData = Record; + export async function apiRequest( method: Method, url: string, - params?: Record, + args: { + params?: RequestParamsOrData; + data?: RequestParamsOrData; + } = {}, ) { const { data } = await api().request({ method, url: '/api/' + url, - data: params, + ...args, }); return data; } + +export async function apiRequestGet( + url: string, + params?: RequestParamsOrData, +) { + return apiRequest('GET', url, { params }); +} + +export async function apiRequestPost( + url: string, + data?: RequestParamsOrData, +) { + return apiRequest('POST', url, { data }); +} + +export async function apiRequestPut( + url: string, + data?: RequestParamsOrData, +) { + return apiRequest('PUT', url, { data }); +} + +export async function apiRequestDelete( + url: string, + params?: RequestParamsOrData, +) { + return apiRequest('DELETE', url, { params }); +} diff --git a/app/javascript/mastodon/api/accounts.ts b/app/javascript/mastodon/api/accounts.ts index 3d89e44b2..e58608785 100644 --- a/app/javascript/mastodon/api/accounts.ts +++ b/app/javascript/mastodon/api/accounts.ts @@ -1,7 +1,9 @@ -import { apiRequest } from 'mastodon/api'; +import { apiRequestPost } from 'mastodon/api'; import type { ApiRelationshipJSON } from 'mastodon/api_types/relationships'; export const apiSubmitAccountNote = (id: string, value: string) => - apiRequest('post', `v1/accounts/${id}/note`, { - comment: value, + apiRequestPost(`v1/accounts/${id}/note`, { + data: { + comment: value, + }, }); diff --git a/app/javascript/mastodon/api/interactions.ts b/app/javascript/mastodon/api/interactions.ts index 4c466a1b4..0bdaffbda 100644 --- a/app/javascript/mastodon/api/interactions.ts +++ b/app/javascript/mastodon/api/interactions.ts @@ -1,10 +1,12 @@ -import { apiRequest } from 'mastodon/api'; +import { apiRequestPost } from 'mastodon/api'; import type { Status, StatusVisibility } from 'mastodon/models/status'; export const apiReblog = (statusId: string, visibility: StatusVisibility) => - apiRequest<{ reblog: Status }>('post', `v1/statuses/${statusId}/reblog`, { - visibility, + apiRequestPost<{ reblog: Status }>(`v1/statuses/${statusId}/reblog`, { + data: { + visibility, + }, }); export const apiUnreblog = (statusId: string) => - apiRequest('post', `v1/statuses/${statusId}/unreblog`); + apiRequestPost(`v1/statuses/${statusId}/unreblog`); diff --git a/app/javascript/mastodon/api/notification_policies.ts b/app/javascript/mastodon/api/notification_policies.ts index b2a1e5ac3..5c1ef9c1d 100644 --- a/app/javascript/mastodon/api/notification_policies.ts +++ b/app/javascript/mastodon/api/notification_policies.ts @@ -1,10 +1,12 @@ -import { apiRequest } from 'mastodon/api'; +import { apiRequestGet, apiRequestPut } from 'mastodon/api'; import type { NotificationPolicyJSON } from 'mastodon/api_types/notification_policies'; export const apiGetNotificationPolicy = () => - apiRequest('GET', '/v1/notifications/policy'); + apiRequestGet('/v1/notifications/policy'); export const apiUpdateNotificationsPolicy = ( policy: Partial, ) => - apiRequest('PUT', '/v1/notifications/policy', policy); + apiRequestPut('/v1/notifications/policy', { + data: policy, + });