Merge branch 'master' into feat/gql-query-errors
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import AxiosStrategy from "./strategies/AxiosStrategy";
|
||||
import ProxyStrategy from "./strategies/ProxyStrategy";
|
||||
import FirefoxStrategy from "./strategies/FirefoxStrategy";
|
||||
|
||||
|
||||
@@ -10,10 +9,6 @@ const runAppropriateStrategy = (req, store) => {
|
||||
return FirefoxStrategy(req, store);
|
||||
}
|
||||
|
||||
if (store.state.postwoman.settings.PROXY_ENABLED) {
|
||||
return ProxyStrategy(req, store);
|
||||
}
|
||||
|
||||
return AxiosStrategy(req, store);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,8 +1,24 @@
|
||||
import axios from "axios";
|
||||
|
||||
const axiosStrategy = async (req, _store) => {
|
||||
const axiosWithProxy = async (req, store) => {
|
||||
const { data } = await axios.post(
|
||||
store.state.postwoman.settings.PROXY_URL ||
|
||||
"https://postwoman.apollotv.xyz/",
|
||||
req
|
||||
);
|
||||
return data;
|
||||
}
|
||||
|
||||
const axiosWithoutProxy = async (req, _store) => {
|
||||
const res = await axios(req);
|
||||
return res;
|
||||
};
|
||||
|
||||
const axiosStrategy = (req, store) => {
|
||||
if (store.state.postwoman.settings.PROXY_ENABLED) {
|
||||
return axiosWithProxy(req, store);
|
||||
}
|
||||
return axiosWithoutProxy(req, store);
|
||||
}
|
||||
|
||||
export default axiosStrategy;
|
||||
|
||||
@@ -1,10 +1,33 @@
|
||||
const firefoxStrategy = (req, _store) => new Promise((resolve, reject) => {
|
||||
|
||||
const firefoxWithProxy = (req, store) => new Promise((resolve, reject) => {
|
||||
const eventListener = (event) => {
|
||||
window.removeEventListener("firefoxExtSendRequestComplete", event);
|
||||
|
||||
if (event.detail.error) {
|
||||
reject(JSON.parse(event.detail.error));
|
||||
} else {
|
||||
resolve(JSON.parse(event.detail.response));
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("firefoxExtSendRequestComplete", eventListener);
|
||||
|
||||
window.firefoxExtSendRequest({
|
||||
method: "post",
|
||||
url: store.state.postwoman.settings.PROXY_URL || "https://postwoman.apollotv.xyz/",
|
||||
data: req
|
||||
});
|
||||
});
|
||||
|
||||
const firefoxWithoutProxy = (req, _store) => new Promise((resolve, reject) => {
|
||||
const eventListener = (event) => {
|
||||
window.removeEventListener("firefoxExtSendRequestComplete", eventListener);
|
||||
|
||||
if (event.detail.error) reject(JSON.parse(event.detail.error));
|
||||
else resolve(JSON.parse(event.detail.response));
|
||||
if (event.detail.error) {
|
||||
reject(JSON.parse(event.detail.error));
|
||||
} else {
|
||||
resolve(JSON.parse(event.detail.response));
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener("firefoxExtSendRequestComplete", eventListener);
|
||||
@@ -12,4 +35,11 @@ const firefoxStrategy = (req, _store) => new Promise((resolve, reject) => {
|
||||
window.firefoxExtSendRequest(req);
|
||||
});
|
||||
|
||||
const firefoxStrategy = (req, store) => {
|
||||
if (store.state.postwoman.settings.PROXY_ENABLED) {
|
||||
return firefoxWithProxy(req, store);
|
||||
}
|
||||
return firefoxWithoutProxy(req, store);
|
||||
}
|
||||
|
||||
export default firefoxStrategy;
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
import axios from "axios";
|
||||
|
||||
const proxyStrategy = async (req, store) => {
|
||||
const { data } = await axios.post(
|
||||
store.state.postwoman.settings.PROXY_URL ||
|
||||
"https://postwoman.apollotv.xyz/",
|
||||
req
|
||||
);
|
||||
return data;
|
||||
};
|
||||
|
||||
export default proxyStrategy;
|
||||
Reference in New Issue
Block a user