Files
parcer/src/api/proxy.ts

58 lines
1.9 KiB
TypeScript
Raw Normal View History

2024-09-30 23:53:35 +05:30
import { default as axios } from "axios";
2024-11-01 08:25:14 +05:30
import { apiUrl } from "../apiConfig";
2024-09-30 23:53:35 +05:30
2024-10-02 23:41:08 +05:30
export const sendProxyConfig = async (proxyConfig: { server_url: string, username?: string, password?: string }): Promise<boolean> => {
2024-09-30 23:53:35 +05:30
try {
2024-11-01 08:25:14 +05:30
const response = await axios.post(`${apiUrl}/proxy/config`, proxyConfig);
2024-09-30 23:55:37 +05:30
if (response.status === 200) {
return response.data;
} else {
2024-10-26 19:11:31 +05:30
throw new Error(`Failed to submit proxy configuration. Status code: ${response.status}`);
2024-09-30 23:55:37 +05:30
}
} catch (error: any) {
2024-10-26 19:11:31 +05:30
console.error('Error sending proxy configuration:', error.message || error);
2024-09-30 23:55:37 +05:30
return false;
2024-09-30 23:53:35 +05:30
}
2024-10-26 05:32:44 +05:30
}
export const getProxyConfig = async (): Promise<{ proxy_url: string, auth: boolean }> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.get(`${apiUrl}/proxy/config`);
2024-10-26 05:32:44 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error(`Failed to fetch proxy configuration. Try again.`);
}
} catch (error: any) {
console.log(error);
return { proxy_url: '', auth: false };
}
2024-10-26 05:34:19 +05:30
}
2024-10-26 05:34:35 +05:30
export const testProxyConfig = async (): Promise<{ success: boolean }> => {
2024-10-26 05:34:19 +05:30
try {
2024-11-01 08:25:14 +05:30
const response = await axios.get(`${apiUrl}/proxy/test`);
2024-10-26 05:34:19 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error(`Failed to test proxy configuration. Try again.`);
}
} catch (error: any) {
console.log(error);
return { success: false };
}
2024-10-26 06:20:40 +05:30
}
export const deleteProxyConfig = async (): Promise<boolean> => {
try {
2024-11-01 08:25:14 +05:30
const response = await axios.delete(`${apiUrl}/proxy/config`);
2024-10-26 06:20:40 +05:30
if (response.status === 200) {
return response.data;
} else {
throw new Error(`Failed to delete proxy configuration. Try again.`);
}
} catch (error: any) {
console.log(error);
return false;
}
2024-09-30 23:55:37 +05:30
}