Skip to content
This repository has been archived by the owner on Jul 18, 2023. It is now read-only.

fix: fetch versions until a recommended is found. #692

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 40 additions & 33 deletions wsEvents/getAppVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const { getAppVersion: getAppVersion_ } = require('../utils/getAppVersion.js');
const { downloadApp: downloadApp_ } = require('../utils/downloadApp.js');
const getDeviceArch = require('../utils/getDeviceArch.js');

const APKMIRROR_UPLOAD_BASE = 'https://www.apkmirror.com/uploads/?appcategory=';

/**
* @param {string} ver
Expand Down Expand Up @@ -123,10 +122,6 @@ async function downloadApp(ws, message) {
* @param {import('ws').WebSocket} ws
*/
module.exports = async function getAppVersion(ws, message) {
let versionsList = await getPage(
`${APKMIRROR_UPLOAD_BASE}${global.jarNames.selectedApp.link.split('/')[3]}`
);

if (global.jarNames.isRooted) {
if (process.platform !== 'android') {
if (!(global.jarNames.devices && global.jarNames.devices[0])) {
Expand Down Expand Up @@ -186,39 +181,51 @@ module.exports = async function getAppVersion(ws, message) {
}
}


const link = global.jarNames.selectedApp.link;
// prettier-ignore
const regex = new RegExp(`(?<=${link}${link.split('/')[3]}-)(.*)(?=-release/)`);
let nextPage = 1

/** @type {{ version: string; recommended: boolean; beta: boolean }[]} */
const versionList = [];
const $ = load(versionsList);
const link = global.jarNames.selectedApp.link;
const regex = new RegExp(
`(?<=${link}${link.split('/')[3]}-)(.*)(?=-release/)`
);

for (const version of $(
'#primary h5.appRowTitle.wrapText.marginZero.block-on-mobile'
).get()) {
const versionTitle = version.attribs.title.toLowerCase();
const versionName = version.children[0].next.attribs.href
.match(regex)[0]
.replace(/-/g, '.');
while (nextPage && !versionList.some(v => v.recommended)) {
// prettier-ignore
const html = await getPage(
`https://www.apkmirror.com/uploads/page/${nextPage}/?appcategory=` +
global.jarNames.selectedApp.link.split('/')[3]
);
const $ = load(html);

// prettier-ignore
for (const version of $('#primary h5.appRowTitle.wrapText.marginZero.block-on-mobile').get()) {
const versionTitle = version.attribs.title.toLowerCase();
const versionName = version.children[0].next.attribs.href
.match(regex)[0]
.replace(/-/g, '.');

if (
(global.jarNames.selectedApp.packageName === 'com.twitter.android' &&
!versionTitle.includes('release')) ||
versionTitle.includes('(Wear OS)') ||
versionTitle.includes('-car_release')
)
continue;

versionList.push({
version: versionName,
recommended:
global.versions !== 'NOREC'
? global.versions.includes(versionName)
: 'NOREC',
beta: versionTitle.includes('beta')
});
}

if (
(global.jarNames.selectedApp.packageName === 'com.twitter.android' &&
!versionTitle.includes('release')) ||
versionTitle.includes('(Wear OS)') ||
versionTitle.includes('-car_release')
)
continue;

versionList.push({
version: versionName,
recommended:
global.versions !== 'NOREC'
? global.versions.includes(versionName)
: 'NOREC',
beta: versionTitle.includes('beta')
});
nextPage = parseInt($(".nextpostslink")?.attr("href")?.match(/page\/(\d+)/)?.[1] ?? 0, 10)
}

if (versionList.every((el) => /^[0-9.]*$/g.test(el.version))) {
versionList.sort((a, b) =>
semver.lt(sanitizeVersion(a.version), sanitizeVersion(b.version)) ? 1 : -1
Expand Down