MCPcopy Create free account
hub / github.com/alibaba/open-code-review / download

Function download

scripts/install.js:94–116  ·  view source on GitHub ↗
(url, maxRedirects = 10)

Source from the content-addressed store, hash-verified

92}
93
94function download(url, maxRedirects = 10) {
95 if (!url.startsWith("https")) {
96 return Promise.reject(new Error(`Refusing non-HTTPS download: ${url}`));
97 }
98 if (maxRedirects <= 0) {
99 return Promise.reject(new Error(`Too many redirects fetching ${url}`));
100 }
101 return new Promise((resolve, reject) => {
102 https.get(url, (res) => {
103 if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
104 res.resume();
105 download(res.headers.location, maxRedirects - 1).then(resolve).catch(reject);
106 return;
107 }
108 if (res.statusCode !== 200) {
109 res.resume();
110 reject(new Error(`HTTP ${res.statusCode} fetching ${url}`));
111 return;
112 }
113 resolve(res);
114 }).on("error", reject);
115 });
116}
117
118async function downloadText(url) {
119 const res = await download(url);

Callers 2

downloadTextFunction · 0.85
downloadBinaryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected