diff options
author | Paul Frazee <pfrazee@gmail.com> | 2023-06-13 13:10:42 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-06-13 13:10:42 -0500 |
commit | 1a12fa57754e32f7d5c3887e7fa35fcfd92bac39 (patch) | |
tree | 64df300119443904cf05f0e18f69a0c82863e34c /src/lib/api | |
parent | 6efbe820d9bb2f3f539676d17a084dc3c7855f54 (diff) | |
download | voidsky-1a12fa57754e32f7d5c3887e7fa35fcfd92bac39.tar.zst |
Add temporary appview-proxy header toggle (#874)
Diffstat (limited to 'src/lib/api')
-rw-r--r-- | src/lib/api/debug-appview-proxy-header.ts | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/lib/api/debug-appview-proxy-header.ts b/src/lib/api/debug-appview-proxy-header.ts new file mode 100644 index 000000000..d84f65cc1 --- /dev/null +++ b/src/lib/api/debug-appview-proxy-header.ts @@ -0,0 +1,57 @@ +/** + * APP-700 + * + * This is a temporary debug setting we're running on the Web build to + * help the protocol team test some changes. + * + * It should be removed in ~2 weeks. It should only be used on the Web + * version of the app. + */ + +import {useState, useCallback} from 'react' +import {BskyAgent} from '@atproto/api' +import {isWeb} from 'platform/detection' + +export function useDebugHeaderSetting(agent: BskyAgent): [boolean, () => void] { + const [enabled, setEnabled] = useState<boolean>(isEnabled()) + + const toggle = useCallback(() => { + if (!enabled) { + localStorage.setItem('set-header-x-appview-proxy', 'yes') + agent.api.xrpc.setHeader('x-appview-proxy', 'true') + setEnabled(true) + } else { + localStorage.removeItem('set-header-x-appview-proxy') + agent.api.xrpc.unsetHeader('x-appview-proxy') + setEnabled(false) + } + }, [setEnabled, enabled, agent]) + + return [enabled, toggle] +} + +export function setDebugHeader(agent: BskyAgent, enabled: boolean) { + if (!isWeb) { + return + } + if (enabled) { + localStorage.setItem('set-header-x-appview-proxy', 'yes') + agent.api.xrpc.setHeader('x-appview-proxy', 'true') + } else { + localStorage.removeItem('set-header-x-appview-proxy') + agent.api.xrpc.unsetHeader('x-appview-proxy') + } +} + +export function applyDebugHeader(agent: BskyAgent) { + if (!isWeb) { + return + } + if (isEnabled()) { + agent.api.xrpc.setHeader('x-appview-proxy', 'true') + } +} + +function isEnabled() { + return localStorage.getItem('set-header-x-appview-proxy') === 'yes' +} |