-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequires.js
117 lines (83 loc) · 2.88 KB
/
requires.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
const axios = require('axios');
// let c = requireurls("https://github.com/ganeshkbhat/requireurl/blob/a34a222d761bb70d51ff3267c8530f40918db53e/index.js");
function fetchURL(url) {
let h = url.includes("http://") ? require("http") : require("https");
}
function genGitURL() {
}
function genGitLabURL() {
}
function genSVNURL() {
}
function genFTPURL() {
}
function genMercurialURL() {
}
function getFilesGit() {
// https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28#get-a-tree
// https://stackoverflow.com/questions/25022016/get-all-file-names-from-a-github-repo-through-the-github-api
// https://docs.github.com/en/rest/git/trees?apiVersion=2022-11-28
}
async function getFilesGit(owner, repo, path = '', branch = 'master') {
let fileList = [];
try {
const url = `https://api.github.com/repos/${owner}/${repo}/contents/${path}?ref=${branch}`;
const response = await axios.get(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
}
});
if (response.status === 200) {
const files = response.data;
for (const file of files) {
if (file.type === 'file') {
console.log(file.download_url);
fileList.push(file.download_url)
} else if (file.type === 'dir') {
await getFilesGit(owner, repo, file.path, branch);
}
}
} else {
console.error(`Failed to fetch files. Status code: ${response.status}`);
}
return fileList;
} catch (error) {
console.error('Error fetching files:', error.message);
return JSON.stringify(error);
}
}
function getFilesFTP() {
}
function getFilesSVN() {
}
function getFilesMecurial() {
}
async function fetchMultipleUrls(urls) {
const fetchUrl = async (url) => {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`Failed to fetch ${url}: ${response.status} ${response.statusText}`);
}
return response.text();
};
}
function fetchUrls(fetchObj = ['https://www.google.com', 'http://www.paytm.com']) {
const requests = fetchObj.fetch.map(obj => {
return new Promise((resolve, reject) => {
const http = (obj.includes("http:")) ? require('http') : require("https");
http.get(obj.url, res => {
let data = '';
res.on('data', chunk => {
data += chunk;
});
res.on('end', () => {
resolve(data);
});
}).on('error', err => {
reject(err);
});
});
});
}
function requireurls(url, options) {
}