api-client/functions/strategies/ExtensionStrategy.js

26 lines
741 B
JavaScript
Raw Normal View History

export const hasExtensionInstalled = () =>
typeof window.__POSTWOMAN_EXTENSION_HOOK__ !== "undefined"
2020-02-16 14:48:10 +00:00
const extensionWithProxy = async (req, { state }) => {
const { data } = await window.__POSTWOMAN_EXTENSION_HOOK__.sendRequest({
method: "post",
url: state.postwoman.settings.PROXY_URL || "https://postwoman.apollotv.xyz/",
2020-02-24 18:44:50 +00:00
data: req,
})
return data
}
2020-02-16 14:48:10 +00:00
const extensionWithoutProxy = async (req, _store) => {
2020-02-24 18:44:50 +00:00
const res = await window.__POSTWOMAN_EXTENSION_HOOK__.sendRequest(req)
return res
}
2020-02-16 14:48:10 +00:00
const extensionStrategy = (req, store) => {
if (store.state.postwoman.settings.PROXY_ENABLED) {
2020-02-24 18:44:50 +00:00
return extensionWithProxy(req, store)
2020-02-16 14:48:10 +00:00
}
2020-02-24 18:44:50 +00:00
return extensionWithoutProxy(req, store)
}
2020-02-16 14:48:10 +00:00
2020-02-24 18:44:50 +00:00
export default extensionStrategy