2021-05-18 09:27:29 +00:00
|
|
|
import AxiosStrategy, {
|
|
|
|
|
cancelRunningAxiosRequest,
|
|
|
|
|
} from "./strategies/AxiosStrategy"
|
2020-05-30 22:28:13 +00:00
|
|
|
import ExtensionStrategy, {
|
|
|
|
|
cancelRunningExtensionRequest,
|
|
|
|
|
hasExtensionInstalled,
|
|
|
|
|
} from "./strategies/ExtensionStrategy"
|
2021-03-23 15:18:14 +00:00
|
|
|
import { settingsStore } from "~/newstore/settings"
|
2020-05-30 22:28:13 +00:00
|
|
|
|
2021-03-23 15:18:14 +00:00
|
|
|
export const cancelRunningRequest = () => {
|
|
|
|
|
if (isExtensionsAllowed() && hasExtensionInstalled()) {
|
2020-05-30 22:28:13 +00:00
|
|
|
cancelRunningExtensionRequest()
|
|
|
|
|
} else {
|
|
|
|
|
cancelRunningAxiosRequest()
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-01-16 06:25:43 +00:00
|
|
|
|
2021-03-23 15:18:14 +00:00
|
|
|
const isExtensionsAllowed = () => settingsStore.value.EXTENSIONS_ENABLED
|
2020-02-04 18:13:20 +00:00
|
|
|
|
2021-03-23 15:18:14 +00:00
|
|
|
const runAppropriateStrategy = (req) => {
|
|
|
|
|
if (isExtensionsAllowed() && hasExtensionInstalled()) {
|
|
|
|
|
return ExtensionStrategy(req)
|
2020-01-16 06:26:25 +00:00
|
|
|
}
|
2020-01-14 04:47:28 +00:00
|
|
|
|
2021-03-23 15:18:14 +00:00
|
|
|
return AxiosStrategy(req)
|
2020-02-24 18:44:50 +00:00
|
|
|
}
|
2020-01-16 06:25:43 +00:00
|
|
|
|
2021-07-06 00:02:29 +00:00
|
|
|
/**
|
|
|
|
|
* Returns an identifier for how a request will be ran
|
|
|
|
|
* if the system is asked to fire a request
|
|
|
|
|
*
|
|
|
|
|
* @returns {"normal" | "extension" | "proxy"}
|
|
|
|
|
*/
|
|
|
|
|
export function getCurrentStrategyID() {
|
|
|
|
|
if (isExtensionsAllowed() && hasExtensionInstalled()) {
|
|
|
|
|
return "extension"
|
|
|
|
|
} else if (settingsStore.value.PROXY_ENABLED) {
|
|
|
|
|
return "proxy"
|
|
|
|
|
} else {
|
|
|
|
|
return "normal"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-23 15:18:14 +00:00
|
|
|
export const sendNetworkRequest = (req) =>
|
|
|
|
|
runAppropriateStrategy(req).finally(() => window.$nuxt.$loading.finish())
|