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

Function download

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

Source from the content-addressed store, hash-verified

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

Callers 2

downloadTextFunction · 0.85
downloadBinaryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected