index.js (2849B)
1 /* 2 GoToSocial 3 Copyright (C) GoToSocial Authors admin@gotosocial.org 4 SPDX-License-Identifier: AGPL-3.0-or-later 5 6 This program is free software: you can redistribute it and/or modify 7 it under the terms of the GNU Affero General Public License as published by 8 the Free Software Foundation, either version 3 of the License, or 9 (at your option) any later version. 10 11 This program is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU Affero General Public License for more details. 15 16 You should have received a copy of the GNU Affero General Public License 17 along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 "use strict"; 21 22 const { 23 replaceCacheOnMutation, 24 removeFromCacheOnMutation, 25 domainListToObject 26 } = require("../lib"); 27 const base = require("../base"); 28 29 const endpoints = (build) => ({ 30 updateInstance: build.mutation({ 31 query: (formData) => ({ 32 method: "PATCH", 33 url: `/api/v1/instance`, 34 asForm: true, 35 body: formData, 36 discardEmpty: true 37 }), 38 ...replaceCacheOnMutation("instance") 39 }), 40 mediaCleanup: build.mutation({ 41 query: (days) => ({ 42 method: "POST", 43 url: `/api/v1/admin/media_cleanup`, 44 params: { 45 remote_cache_days: days 46 } 47 }) 48 }), 49 instanceBlocks: build.query({ 50 query: () => ({ 51 url: `/api/v1/admin/domain_blocks` 52 }), 53 transformResponse: domainListToObject 54 }), 55 addInstanceBlock: build.mutation({ 56 query: (formData) => ({ 57 method: "POST", 58 url: `/api/v1/admin/domain_blocks`, 59 asForm: true, 60 body: formData, 61 discardEmpty: true 62 }), 63 transformResponse: (data) => { 64 return { 65 [data.domain]: data 66 }; 67 }, 68 ...replaceCacheOnMutation("instanceBlocks") 69 }), 70 removeInstanceBlock: build.mutation({ 71 query: (id) => ({ 72 method: "DELETE", 73 url: `/api/v1/admin/domain_blocks/${id}`, 74 }), 75 ...removeFromCacheOnMutation("instanceBlocks", { 76 findKey: (_draft, newData) => { 77 return newData.domain; 78 } 79 }) 80 }), 81 getAccount: build.query({ 82 query: (id) => ({ 83 url: `/api/v1/accounts/${id}` 84 }), 85 providesTags: (_, __, id) => [{ type: "Account", id }] 86 }), 87 actionAccount: build.mutation({ 88 query: ({ id, action, reason }) => ({ 89 method: "POST", 90 url: `/api/v1/admin/accounts/${id}/action`, 91 asForm: true, 92 body: { 93 type: action, 94 text: reason 95 } 96 }), 97 invalidatesTags: (_, __, { id }) => [{ type: "Account", id }] 98 }), 99 searchAccount: build.mutation({ 100 query: (username) => ({ 101 url: `/api/v2/search?q=${encodeURIComponent(username)}&resolve=true` 102 }), 103 transformResponse: (res) => { 104 return res.accounts ?? []; 105 } 106 }), 107 ...require("./import-export")(build), 108 ...require("./custom-emoji")(build), 109 ...require("./reports")(build) 110 }); 111 112 module.exports = base.injectEndpoints({ endpoints });