fix: proxy configuration and update command hook dependencies (#3327)
* fix: proxy configuration and update dependencies in command hooks * fix: test
This commit is contained in:
@@ -18,6 +18,7 @@ vi.mock("./store", () => ({
|
||||
store: {
|
||||
set: vi.fn(),
|
||||
get: vi.fn(),
|
||||
delete: vi.fn(),
|
||||
},
|
||||
}))
|
||||
|
||||
@@ -40,6 +41,13 @@ describe("proxy", () => {
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it("should set sock proxy config", () => {
|
||||
const proxy = "socks://localhost:8080"
|
||||
const result = setProxyConfig(proxy)
|
||||
expect(store.set).toHaveBeenCalledWith("proxy", "socks://localhost:8080")
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
|
||||
it("should handle default port", () => {
|
||||
// https://github.com/RSSNext/Follow/issues/1197
|
||||
const proxy = "http://example.com:80"
|
||||
@@ -51,7 +59,7 @@ describe("proxy", () => {
|
||||
it("should return false for invalid proxy", () => {
|
||||
const proxy = "invalid-proxy"
|
||||
const result = setProxyConfig(proxy)
|
||||
expect(store.set).toHaveBeenCalledWith("proxy", undefined)
|
||||
expect(store.delete).toHaveBeenCalledWith("proxy")
|
||||
expect(result).toBe(false)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -17,10 +17,11 @@ import { store } from "./store"
|
||||
|
||||
export const setProxyConfig = (inputProxy: string) => {
|
||||
const proxyUri = normalizeProxyUri(inputProxy)
|
||||
store.set("proxy", proxyUri)
|
||||
if (!proxyUri) {
|
||||
store.delete("proxy")
|
||||
return false
|
||||
}
|
||||
store.set("proxy", proxyUri)
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -37,7 +38,7 @@ const URL_SCHEME = new Set(["http:", "https:", "ftp:", "socks:", "socks4:", "soc
|
||||
|
||||
const normalizeProxyUri = (userProxy: string) => {
|
||||
if (!userProxy) {
|
||||
return ""
|
||||
return
|
||||
}
|
||||
// Only use the first proxy if there are multiple urls
|
||||
const firstInput = userProxy.split(",")[0]!
|
||||
@@ -78,6 +79,14 @@ export const updateProxy = () => {
|
||||
proxyRules,
|
||||
proxyBypassRules: BYPASS_RULES,
|
||||
})
|
||||
|
||||
// https://github.com/nodejs/undici/issues/2224
|
||||
// Error occurred in handler for 'setProxyConfig': InvalidArgumentError: Invalid URL protocol: the URL must start with `http:` or `https:`.
|
||||
if (new URL(proxyUri).protocol === "socks:") {
|
||||
// undici doesn't support socks proxy
|
||||
logger.warn("undici doesn't support socks proxy")
|
||||
return
|
||||
}
|
||||
// Currently, Session.setProxy is not working for native fetch, which is used by readability.
|
||||
// So we need to set proxy for native fetch manually, refer to https://stackoverflow.com/a/76503362/14676508
|
||||
const dispatcher = new ProxyAgent({ uri: new URL(proxyUri).toString() })
|
||||
|
||||
@@ -164,7 +164,7 @@ const useRegisterReadwiseCommands = () => {
|
||||
},
|
||||
}),
|
||||
{
|
||||
deps: [isReadwiseAvailable],
|
||||
deps: [isReadwiseAvailable, readwiseToken],
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -234,7 +234,7 @@ const useRegisterInstapaperCommands = () => {
|
||||
},
|
||||
}),
|
||||
{
|
||||
deps: [isInstapaperAvailable],
|
||||
deps: [isInstapaperAvailable, instapaperUsername, instapaperPassword],
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -316,7 +316,7 @@ const useRegisterObsidianCommands = () => {
|
||||
},
|
||||
}),
|
||||
{
|
||||
deps: [isObsidianAvailable],
|
||||
deps: [isObsidianAvailable, obsidianVaultPath],
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -381,7 +381,7 @@ const useRegisterOutlineCommands = () => {
|
||||
},
|
||||
}),
|
||||
{
|
||||
deps: [outlineAvailable],
|
||||
deps: [outlineAvailable, outlineToken, outlineEndpoint, outlineCollection],
|
||||
},
|
||||
)
|
||||
}
|
||||
@@ -449,7 +449,7 @@ const useRegisterReadeckCommands = () => {
|
||||
},
|
||||
}),
|
||||
{
|
||||
deps: [readeckAvailable],
|
||||
deps: [readeckAvailable, readeckToken, readeckEndpoint],
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user