partial refactor for files regarding the ISSUE#898 request to fetch besides mariadb

This commit is contained in:
MichalTirpak
2024-12-15 06:51:44 +00:00
committed by AJ ONeal
parent 801df24541
commit ba94ad883b
8 changed files with 208 additions and 112 deletions
+10 -7
View File
@@ -53,7 +53,7 @@ var channelMap = {};
// ]
// }
module.exports = async function (request) {
module.exports = async function () {
let all = {
download: '',
releases: [],
@@ -61,13 +61,17 @@ module.exports = async function (request) {
};
for (let osname of FLUTTER_OSES) {
let resp = await request({
url: `https://storage.googleapis.com/flutter_infra_release/releases/releases_${osname}.json`,
json: true,
const response = await fetch(`https://storage.googleapis.com/flutter_infra_release/releases/releases_${osname}.json`, {
method: 'GET',
headers: { Accept: 'application/json' },
});
if (!response.ok) {
throw new Error(`Failed to fetch data for ${osname}: ${response.statusText}`);
}
const respBody = await response.json();
let osBaseUrl = resp.body.base_url;
let osReleases = resp.body.releases;
let osBaseUrl = respBody.base_url;
let osReleases = respBody.releases;
for (let asset of osReleases) {
if (!channelMap[asset.channel]) {
@@ -80,7 +84,6 @@ module.exports = async function (request) {
lts: false,
channel: asset.channel,
date: asset.release_date.replace(/T.*/, ''),
//sha256: asset.sha256,
download: `${osBaseUrl}/${asset.archive}`,
_filename: asset.archive,
});
+26 -26
View File
@@ -18,7 +18,7 @@ function isOdd(filename) {
}
}
function getDistributables(request) {
async function getDistributables() {
/*
{
version: 'go1.13.8',
@@ -37,54 +37,54 @@ function getDistributables(request) {
]
};
*/
return request({
url: 'https://golang.org/dl/?mode=json&include=all',
json: true,
}).then((resp) => {
var goReleases = resp.body;
var all = {
const response = await fetch('https://golang.org/dl/?mode=json&include=all', {
method: 'GET',
headers: { Accept: 'application/json' },
});
if (!response.ok) {
throw new Error(`Failed to fetch Go releases: ${response.statusText}`);
}
const goReleases = await response.json();
const all = {
releases: [],
download: '',
};
goReleases.forEach((release) => {
// strip 'go' prefix, standardize version
var parts = release.version.slice(2).split('.');
// Strip 'go' prefix and standardize version
const parts = release.version.slice(2).split('.');
while (parts.length < 3) {
parts.push('0');
}
var version = parts.join('.');
// nix 'go' prefix
var fileversion = release.version.slice(2);
const version = parts.join('.');
const fileversion = release.version.slice(2);
release.files.forEach((asset) => {
let odd = isOdd(asset.filename);
if (odd) {
if (isOdd(asset.filename)) {
return;
}
var filename = asset.filename;
var os = osMap[asset.os] || asset.os || '-';
var arch = archMap[asset.arch] || asset.arch || '-';
const filename = asset.filename;
const os = osMap[asset.os] || asset.os || '-';
const arch = archMap[asset.arch] || asset.arch || '-';
all.releases.push({
version: version,
_version: fileversion,
// all go versions >= 1.0.0 are effectively LTS
lts: (parts[0] > 0 && release.stable) || false,
channel: (release.stable && 'stable') || 'beta',
date: '1970-01-01', // the world may never know
date: '1970-01-01', // Placeholder
os: os,
arch: arch,
ext: '', // let normalize run the split/test/join
hash: '-', // not ready to standardize this yet
ext: '', // Let normalize run the split/test/join
hash: '-', // Placeholder for hash
download: `https://dl.google.com/go/${filename}`,
});
});
});
return all;
});
}
}
module.exports = getDistributables;
+20 -4
View File
@@ -16,15 +16,31 @@ function createUrlMatcher() {
);
}
async function getRawReleases(request) {
async function getRawReleases() {
let matcher = createRssMatcher();
let resp = await request({
url: 'https://sourceforge.net/projects/gpgosx/rss?path=/',
const response = await fetch('https://sourceforge.net/projects/gpgosx/rss?path=/', {
method: 'GET',
headers: {
'Accept': 'application/rss+xml', // Ensure the correct content type is requested
},
});
// Validate the response status
if (!response.ok) {
throw new Error(`Failed to fetch RSS feed: HTTP ${response.status} - ${response.statusText}`);
}
const contentType = response.headers.get('Content-Type');
if (!contentType || !contentType.includes('xml')) {
throw new Error(`Unexpected content type: ${contentType}`);
}
const body = await response.text(); // Fetch RSS feed as plain text
let links = [];
for (;;) {
let m = matcher.exec(resp.body);
let m = matcher.exec(body);
if (!m) {
break;
}
+32 -16
View File
@@ -1,22 +1,38 @@
'use strict';
function getRawReleases(request) {
return request({ url: 'https://iterm2.com/downloads.html' }).then(
function (resp) {
var links = resp.body
.split(/[<>]+/g)
.map(function (str) {
var m = str.match(
/href="(https:\/\/iterm2\.com\/downloads\/.*\.zip)"/,
);
if (m && /iTerm2-[34]/.test(m[1])) {
return m[1];
}
})
.filter(Boolean);
return links;
async function getRawReleases() {
const response = await fetch('https://iterm2.com/downloads.html', {
method: 'GET',
headers: {
'Accept': 'text/html', // Explicitly request HTML content
},
);
});
// Validate HTTP response
if (!response.ok) {
throw new Error(`Failed to fetch releases: HTTP ${response.status} - ${response.statusText}`);
}
// Validate Content-Type header
const contentType = response.headers.get('Content-Type');
if (!contentType || !contentType.includes('text/html')) {
throw new Error(`Unexpected Content-Type: ${contentType}`);
}
// Parse HTML content
const body = await response.text();
var links = body
.split(/[<>]+/g)
.map(function (str) {
var m = str.match(
/href="(https:\/\/iterm2\.com\/downloads\/.*\.zip)"/,
);
if (m && /iTerm2-[34]/.test(m[1])) {
return m[1];
}
})
.filter(Boolean);
return links;
}
function transformReleases(links) {
+47 -28
View File
@@ -40,23 +40,41 @@ var headers = {
'Accept-Language': 'en-US,en;q=0.9,sq;q=0.8',
};
module.exports = function (request) {
var all = {
async function fetchReleasesForOS(os) {
// Fetch the webpage for the given OS
const response = await fetch(os.url, {
method: 'GET',
headers: headers,
});
// Validate HTTP response
if (!response.ok) {
throw new Error(`Failed to fetch URL: ${os.url}. HTTP ${response.status} - ${response.statusText}`);
}
// Parse the response body
const body = await response.text();
// Extract the download link
const match = body.match(/(http[^>]+Install[^>]+\.dmg)/);
return match ? match[1] : null;
}
async function getDistributables() {
const all = {
_names: ['InstallOS'],
download: '',
releases: [],
};
return Promise.all(
oses.map(function (os) {
return request({
method: 'GET',
url: os.url,
headers: headers,
}).then(function (resp) {
var m = resp.body.match(/(http[^>]+Install[^>]+.dmg)/);
var download = m && m[1];
['macos', 'linux'].forEach(function (osname) {
// Fetch data for each OS and populate the releases array
await Promise.all(
oses.map(async (os) => {
try {
const download = await fetchReleasesForOS(os);
// Add releases for macOS and Linux
['macos', 'linux'].forEach((osname) => {
all.releases.push({
version: os.version,
lts: os.lts || false,
@@ -65,27 +83,28 @@ module.exports = function (request) {
os: osname,
arch: 'amd64',
ext: 'dmg',
hash: '-',
hash: '-', // Placeholder for hash
download: download,
});
});
});
} catch (err) {
console.error(`Error fetching for ${os.name}: ${err.message}`);
}
}),
).then(function () {
all.releases.sort(function (a, b) {
if ('10.11.6' === a.version) {
return -1;
}
if (a.date > b.date) {
return 1;
}
if (a.date < b.date) {
return -1;
}
});
return all;
);
// Sort releases
all.releases.sort((a, b) => {
if (a.version === '10.11.6') {
return -1;
}
return a.date > b.date ? 1 : -1;
});
};
return all;
}
module.exports = getDistributables;
if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {
+30 -16
View File
@@ -40,7 +40,7 @@ let pkgMap = {
musl: ['tar.gz', 'tar.xz'],
};
async function getDistributables(request) {
async function getDistributables() {
let all = {
releases: [],
download: '',
@@ -64,26 +64,40 @@ async function getDistributables(request) {
]
*/
// Alternate: 'https://nodejs.org/dist/index.json',
let baseUrl = `https://nodejs.org/download/release`;
let officialP = request({
url: `${baseUrl}/index.json`,
json: true,
}).then(function (resp) {
transform(baseUrl, resp.body);
return;
// Alternate: 'https://nodejs.org/dist/index.json',
let baseUrl = `https://nodejs.org/download/release`;
// Fetch official builds
let officialP = fetch(`${baseUrl}/index.json`, {
method: 'GET',
headers: { Accept: 'application/json' },
}).then((response) => {
if (!response.ok) {
throw new Error(`Failed to fetch official builds: HTTP ${response.status} - ${response.statusText}`);
}
return response.json();
})
.then((data) => {
transform(baseUrl, data);
});
// Fetch unofficial builds
let unofficialBaseUrl = `https://unofficial-builds.nodejs.org/download/release`;
let unofficialP = request({
url: `${unofficialBaseUrl}/index.json`,
json: true,
let unofficialP = fetch(`${unofficialBaseUrl}/index.json`, {
method: 'GET',
headers: { Accept: 'application/json' },
})
.then(function (resp) {
transform(unofficialBaseUrl, resp.body);
return;
.then((response) => {
if (!response.ok) {
throw new Error(`Failed to fetch unofficial builds: HTTP ${response.status} - ${response.statusText}`);
}
return response.json();
})
.catch(function (err) {
.then((data) => {
transform(unofficialBaseUrl, data);
})
.catch((err) => {
console.error('failed to fetch unofficial-builds');
console.error(err);
});
+20 -7
View File
@@ -1,11 +1,21 @@
'use strict';
function getDistributables(request) {
return request({
url: 'https://releases.hashicorp.com/terraform/index.json',
json: true,
}).then(function (resp) {
let releases = resp.body;
async function getDistributables() {
try {
// Fetch the Terraform releases JSON
const response = await fetch('https://releases.hashicorp.com/terraform/index.json', {
method: 'GET',
headers: { Accept: 'application/json' },
});
// Validate the HTTP response
if (!response.ok) {
throw new Error(`Failed to fetch releases: HTTP ${response.status} - ${response.statusText}`);
}
// Parse the JSON response
const releases = await response.json();
let all = {
releases: [],
download: '', // Full URI provided in response body
@@ -34,7 +44,10 @@ function getDistributables(request) {
});
return all;
});
} catch (err) {
console.error('Error fetching Terraform releases:', err.message);
return { releases: [], download: '' };
}
}
module.exports = getDistributables;
+23 -8
View File
@@ -3,12 +3,22 @@
var NON_BUILDS = ['bootstrap', 'src'];
var ODDITIES = NON_BUILDS.concat(['armv6kz-linux']);
module.exports = function (request) {
return request({
url: 'https://ziglang.org/download/index.json',
json: true,
}).then(function (resp) {
let versions = resp.body;
module.exports = async function () {
try {
// Fetch the Zig language download index JSON
const response = await fetch('https://ziglang.org/download/index.json', {
method: 'GET',
headers: { Accept: 'application/json' },
});
// Validate HTTP response
if (!response.ok) {
throw new Error(`Failed to fetch releases: HTTP ${response.status} - ${response.statusText}`);
}
// Parse the JSON response
const versions = await response.json();
let releases = [];
let refs = Object.keys(versions);
@@ -77,8 +87,13 @@ module.exports = function (request) {
return {
releases: releases,
};
});
};
}catch (err) {
console.error('Error fetching Zig releases:', err.message);
return {
releases: [],
};
};
}
if (module === require.main) {
module.exports(require('@root/request')).then(function (all) {