Skip to content

Commit 005965d

Browse files
committed
optimize site proxy
1 parent 9466a9a commit 005965d

4 files changed

Lines changed: 10 additions & 44 deletions

File tree

src/EIDEProjectExplorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ import { SevenZipper, CompressOption } from './Compress';
8383
import { DependenceManager } from './DependenceManager';
8484
import { ArrayDelRepetition } from '../lib/node-utility/Utility';
8585
import {
86-
copyObject, downloadFileWithProgress, getDownloadUrlFromGitea,
86+
copyObject, downloadFileWithProgress,
8787
runShellCommand, redirectHost, readGithubRepoFolder, FileCache,
8888
genGithubHash, md5, toArray, newMarkdownString, newFileTooltipString, FileTooltipInfo, escapeXml,
8989
readGithubRepoTxtFile, downloadFile, notifyReloadWindow, formatPath, execInternalCommand,

src/OperationExplorer.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,11 +1103,9 @@ export class OperationExplorer {
11031103
netReq.emit('abort');
11041104
});
11051105

1106-
const headers: any = {
1106+
const headers: any = utility.setProxyHeader({
11071107
'User-Agent': 'Mozilla/5.0'
1108-
};
1109-
1110-
utility.setProxyHeader(headers);
1108+
});
11111109

11121110
if (acToken) { // if token is enabled, use it
11131111
headers['Authorization'] = `token ${acToken}`;

src/extension.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -576,19 +576,19 @@ async function tryInstallBinaries(binFolder: File, binVersion: string): Promise<
576576
const binType = '7z';
577577

578578
// binaries download site
579-
const downloadSites: string[] = [
579+
let downloadSites: string[] = [
580580
`https://raw-github.github0null.io/github0null/eide-resource/master/binaries/${platform.getRuntimeId()}/bin-${binVersion}.${binType}`,
581581
`https://raw-github.em-ide.com/github0null/eide-resource/master/binaries/${platform.getRuntimeId()}/bin-${binVersion}.${binType}`,
582+
`https://raw.githubusercontent.com/github0null/eide-resource/master/binaries/${platform.getRuntimeId()}/bin-${binVersion}.${binType}`
582583
];
583584

584-
/* random select the order of site */
585-
if (Math.random() > 0.5) {
586-
downloadSites.reverse();
585+
// random order
586+
{
587+
const sValMap: Map<string, number> = new Map();
588+
downloadSites.forEach(s => sValMap.set(s, Math.floor(Math.random() * 100)));
589+
downloadSites = downloadSites.sort((a, b) => (sValMap.get(a) || 0) - (sValMap.get(b) || 0));
587590
}
588591

589-
// add github default download url
590-
downloadSites.push(`https://raw.githubusercontent.com/github0null/eide-resource/master/binaries/${platform.getRuntimeId()}/bin-${binVersion}.${binType}`);
591-
592592
let installedDone = false;
593593

594594
try {

src/utility.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -497,38 +497,6 @@ export async function downloadFileWithProgress(url: string, fileLable: string,
497497
});
498498
}
499499

500-
export async function getDownloadUrlFromGitea(repo: string, folder: string, fileName: string): Promise<any | Error | undefined> {
501-
502-
return new Promise(async (resolve) => {
503-
504-
const req = new NetRequest();
505-
506-
const res = await req.Request<any, any>({
507-
host: `git.github0null.io`,
508-
path: `/api/v1/repos/root/${repo}/contents/${folder}`,
509-
timeout: 3000,
510-
headers: setProxyHeader({ 'User-Agent': 'Mozilla/5.0' }),
511-
rejectUnauthorized: false, // ignore cert failed
512-
}, 'https');
513-
514-
if (res.success == false || res.content == undefined) {
515-
resolve(new Error(res.msg || `Can't connect to git repo !`));
516-
return;
517-
}
518-
519-
let fInfo: any | undefined;
520-
521-
for (const fileInfo of res.content) {
522-
if (fileInfo['name'] == fileName) {
523-
fInfo = fileInfo;
524-
break;
525-
}
526-
}
527-
528-
resolve(fInfo);
529-
});
530-
}
531-
532500
export async function readGithubRepoFolder(repo_url: string, token?: vscode.CancellationToken): Promise<GitFileInfo[] | Error> {
533501

534502
// URL: https://api.github.com/repos/github0null/eide-doc/contents/eide-template-list

0 commit comments

Comments
 (0)