nakama/moderation/frontend/src/utils/api.js

61 lines
1.8 KiB
JavaScript
Raw Normal View History

2025-11-10 21:22:58 +00:00
import axios from 'axios'
2025-11-10 20:13:22 +00:00
const API_URL =
import.meta.env.VITE_API_URL ||
2025-11-10 21:22:58 +00:00
(import.meta.env.PROD ? '/api' : 'http://localhost:3000/api')
2025-11-10 20:13:22 +00:00
const api = axios.create({
baseURL: API_URL,
2025-11-10 21:56:36 +00:00
withCredentials: true
2025-11-10 21:22:58 +00:00
})
2025-11-10 20:13:22 +00:00
2025-11-10 22:19:37 +00:00
api.interceptors.request.use((config) => {
const initData = window.Telegram?.WebApp?.initData;
if (initData) {
config.headers = config.headers || {};
if (!config.headers.Authorization) {
config.headers.Authorization = `tma ${initData}`;
}
}
return config;
});
2025-11-10 21:56:36 +00:00
export const verifyAuth = () => api.post('/mod-app/auth/verify').then((res) => res.data.user)
2025-11-10 20:13:22 +00:00
export const fetchUsers = (params = {}) =>
2025-11-10 21:22:58 +00:00
api.get('/mod-app/users', { params }).then((res) => res.data)
2025-11-10 20:13:22 +00:00
export const banUser = (userId, data) =>
2025-11-10 21:22:58 +00:00
api.put(`/mod-app/users/${userId}/ban`, data).then((res) => res.data)
2025-11-10 20:13:22 +00:00
export const fetchPosts = (params = {}) =>
2025-11-10 21:22:58 +00:00
api.get('/mod-app/posts', { params }).then((res) => res.data)
2025-11-10 20:13:22 +00:00
export const updatePost = (postId, data) =>
2025-11-10 21:22:58 +00:00
api.put(`/mod-app/posts/${postId}`, data).then((res) => res.data)
2025-11-10 20:13:22 +00:00
export const deletePost = (postId) =>
2025-11-10 21:22:58 +00:00
api.delete(`/mod-app/posts/${postId}`).then((res) => res.data)
2025-11-10 20:13:22 +00:00
export const removePostImage = (postId, index) =>
2025-11-10 21:22:58 +00:00
api.delete(`/mod-app/posts/${postId}/images/${index}`).then((res) => res.data)
2025-11-10 20:13:22 +00:00
export const banPostAuthor = (postId, data) =>
2025-11-10 21:22:58 +00:00
api.post(`/mod-app/posts/${postId}/ban`, data).then((res) => res.data)
2025-11-10 20:13:22 +00:00
export const fetchReports = (params = {}) =>
2025-11-10 21:22:58 +00:00
api.get('/mod-app/reports', { params }).then((res) => res.data)
2025-11-10 20:13:22 +00:00
export const updateReportStatus = (reportId, data) =>
2025-11-10 21:22:58 +00:00
api.put(`/mod-app/reports/${reportId}`, data).then((res) => res.data)
2025-11-10 20:13:22 +00:00
export const publishToChannel = (formData) =>
api.post('/mod-app/channel/publish', formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
2025-11-10 21:22:58 +00:00
})
2025-11-10 20:13:22 +00:00
2025-11-10 21:22:58 +00:00
export default api
2025-11-10 20:13:22 +00:00