fix(release): scope the proxy to GitHub so the domestic channel stays direct
setGlobalDispatcher routed every request — including the Gitea release and channel PUTs — through the local proxy, which reset mid-upload once and left the channel half-written. The proxy agent is now passed explicitly on the GitHub requests only.
This commit is contained in:
1 parent
d7abbaad9c
commit
4b336360f8
2 files changed
+14
-10
No files matched your search
+1
-1
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"name": "open-terminal",
|
"name": "open-terminal",
|
||||||
"productName": "OpenTerminal",
|
"productName": "OpenTerminal",
|
||||||
"version": "1.0.8",
|
"version": "1.0.9",
|
||||||
"description": "Open-source terminal with SSH, split panes, themes and fonts",
|
"description": "Open-source terminal with SSH, split panes, themes and fonts",
|
||||||
"main": "out/main/index.js",
|
"main": "out/main/index.js",
|
||||||
"author": "Bill",
|
"author": "Bill",
|
||||||
|
|||||||
+13
-9
@@ -48,14 +48,16 @@ if (ymlVersion !== V) {
|
|||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Proxy applies to GitHub only. The domestic Gitea host is fastest — and most
|
||||||
|
// reliable — over a direct connection; routing it through a local proxy is
|
||||||
|
// what once broke a channel upload (ECONNRESET mid-PUT), and a proxy that is
|
||||||
|
// down would take the domestic channel with it. So no global dispatcher here:
|
||||||
|
// the agent is passed explicitly on GitHub requests.
|
||||||
const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || env.HTTPS_PROXY || env.PROXY
|
const proxy = process.env.HTTPS_PROXY || process.env.https_proxy || env.HTTPS_PROXY || env.PROXY
|
||||||
if (proxy) {
|
const proxyAgent = proxy ? new (require('undici').ProxyAgent)(proxy) : undefined
|
||||||
const { ProxyAgent, setGlobalDispatcher } = require('undici')
|
if (proxy) console.log('proxy for GitHub only:', proxy)
|
||||||
setGlobalDispatcher(new ProxyAgent(proxy))
|
|
||||||
console.log('using proxy:', proxy)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function upload(url, file, token, authScheme) {
|
async function upload(url, file, token, authScheme, viaProxy = false) {
|
||||||
const name = path.basename(file)
|
const name = path.basename(file)
|
||||||
const stat = fs.statSync(file)
|
const stat = fs.statSync(file)
|
||||||
const resp = await fetch(`${url}${url.includes('?') ? '&' : '?'}name=${encodeURIComponent(name)}`, {
|
const resp = await fetch(`${url}${url.includes('?') ? '&' : '?'}name=${encodeURIComponent(name)}`, {
|
||||||
@@ -66,7 +68,8 @@ async function upload(url, file, token, authScheme) {
|
|||||||
'Content-Length': String(stat.size)
|
'Content-Length': String(stat.size)
|
||||||
},
|
},
|
||||||
body: fs.createReadStream(file),
|
body: fs.createReadStream(file),
|
||||||
duplex: 'half'
|
duplex: 'half',
|
||||||
|
...(viaProxy && proxyAgent ? { dispatcher: proxyAgent } : {})
|
||||||
})
|
})
|
||||||
console.log(` upload ${name}: HTTP ${resp.status}`)
|
console.log(` upload ${name}: HTTP ${resp.status}`)
|
||||||
if (!resp.ok) {
|
if (!resp.ok) {
|
||||||
@@ -136,14 +139,15 @@ async function github() {
|
|||||||
'User-Agent': 'OpenTerminal',
|
'User-Agent': 'OpenTerminal',
|
||||||
Accept: 'application/vnd.github+json'
|
Accept: 'application/vnd.github+json'
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ tag_name: `v${V}`, name: `OpenTerminal v${V}`, body: notes, draft: false, prerelease: false })
|
body: JSON.stringify({ tag_name: `v${V}`, name: `OpenTerminal v${V}`, body: notes, draft: false, prerelease: false }),
|
||||||
|
...(proxyAgent ? { dispatcher: proxyAgent } : {})
|
||||||
})
|
})
|
||||||
if (!resp.ok) { throw new Error(`GitHub release create failed: ${resp.status} ${(await resp.text()).slice(0, 300)}`) }
|
if (!resp.ok) { throw new Error(`GitHub release create failed: ${resp.status} ${(await resp.text()).slice(0, 300)}`) }
|
||||||
const rel = await resp.json()
|
const rel = await resp.json()
|
||||||
console.log('release created, id =', rel.id)
|
console.log('release created, id =', rel.id)
|
||||||
const up = `https://uploads.github.com/repos/billowliu2/OpenTerminal/releases/${rel.id}/assets`
|
const up = `https://uploads.github.com/repos/billowliu2/OpenTerminal/releases/${rel.id}/assets`
|
||||||
for (const f of [...files, path.join(R, `OpenTerminal-${V}-setup.exe.blockmap`), path.join(R, 'latest.yml')]) {
|
for (const f of [...files, path.join(R, `OpenTerminal-${V}-setup.exe.blockmap`), path.join(R, 'latest.yml')]) {
|
||||||
await upload(up, f, env.GH_TOKEN, 'Bearer')
|
await upload(up, f, env.GH_TOKEN, 'Bearer', true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user