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,
|
|
|
|
|
withCredentials: false
|
2025-11-10 21:22:58 +00:00
|
|
|
})
|
2025-11-10 20:13:22 +00:00
|
|
|
|
2025-11-10 21:22:58 +00:00
|
|
|
const getInitData = () => window.Telegram?.WebApp?.initData || null
|
2025-11-10 20:13:22 +00:00
|
|
|
|
|
|
|
|
api.interceptors.request.use((config) => {
|
2025-11-10 21:22:58 +00:00
|
|
|
const initData = getInitData()
|
|
|
|
|
|
2025-11-10 20:13:22 +00:00
|
|
|
if (initData) {
|
2025-11-10 21:22:58 +00:00
|
|
|
config.headers['x-telegram-init-data'] = initData
|
2025-11-10 20:13:22 +00:00
|
|
|
}
|
|
|
|
|
|
2025-11-10 21:22:58 +00:00
|
|
|
return config
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export const verifyAuth = () => api.post('/mod-app/auth/verify')
|
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
|
|
|
|