65 lines
1.8 KiB
JavaScript
65 lines
1.8 KiB
JavaScript
|
|
import axios from 'axios';
|
||
|
|
|
||
|
|
const API_URL =
|
||
|
|
import.meta.env.VITE_API_URL ||
|
||
|
|
(import.meta.env.PROD ? '/api' : 'http://localhost:3000/api');
|
||
|
|
|
||
|
|
const api = axios.create({
|
||
|
|
baseURL: API_URL,
|
||
|
|
withCredentials: false
|
||
|
|
});
|
||
|
|
|
||
|
|
const getInitData = () => {
|
||
|
|
if (typeof window === 'undefined') {
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
return window.Telegram?.WebApp?.initData || null;
|
||
|
|
};
|
||
|
|
|
||
|
|
api.interceptors.request.use((config) => {
|
||
|
|
const initData = getInitData();
|
||
|
|
if (initData) {
|
||
|
|
config.headers['x-telegram-init-data'] = initData;
|
||
|
|
}
|
||
|
|
return config;
|
||
|
|
});
|
||
|
|
|
||
|
|
export const verifyAuth = () => api.post('/mod-app/auth/verify');
|
||
|
|
|
||
|
|
export const fetchUsers = (params = {}) =>
|
||
|
|
api.get('/mod-app/users', { params }).then((res) => res.data);
|
||
|
|
|
||
|
|
export const banUser = (userId, data) =>
|
||
|
|
api.put(`/mod-app/users/${userId}/ban`, data).then((res) => res.data);
|
||
|
|
|
||
|
|
export const fetchPosts = (params = {}) =>
|
||
|
|
api.get('/mod-app/posts', { params }).then((res) => res.data);
|
||
|
|
|
||
|
|
export const updatePost = (postId, data) =>
|
||
|
|
api.put(`/mod-app/posts/${postId}`, data).then((res) => res.data);
|
||
|
|
|
||
|
|
export const deletePost = (postId) =>
|
||
|
|
api.delete(`/mod-app/posts/${postId}`).then((res) => res.data);
|
||
|
|
|
||
|
|
export const removePostImage = (postId, index) =>
|
||
|
|
api.delete(`/mod-app/posts/${postId}/images/${index}`).then((res) => res.data);
|
||
|
|
|
||
|
|
export const banPostAuthor = (postId, data) =>
|
||
|
|
api.post(`/mod-app/posts/${postId}/ban`, data).then((res) => res.data);
|
||
|
|
|
||
|
|
export const fetchReports = (params = {}) =>
|
||
|
|
api.get('/mod-app/reports', { params }).then((res) => res.data);
|
||
|
|
|
||
|
|
export const updateReportStatus = (reportId, data) =>
|
||
|
|
api.put(`/mod-app/reports/${reportId}`, data).then((res) => res.data);
|
||
|
|
|
||
|
|
export const publishToChannel = (formData) =>
|
||
|
|
api.post('/mod-app/channel/publish', formData, {
|
||
|
|
headers: {
|
||
|
|
'Content-Type': 'multipart/form-data'
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
export default api;
|
||
|
|
|