diff --git a/src/routes/getBrandingStats.ts b/src/routes/getBrandingStats.ts index b6a9daf..0046f91 100644 --- a/src/routes/getBrandingStats.ts +++ b/src/routes/getBrandingStats.ts @@ -4,7 +4,7 @@ import { db } from "../databases/databases"; import { Request, Response } from "express"; import axios from "axios"; import { Logger } from "../utils/logger"; -import { getCWSUsers } from "../utils/getCWSUsers"; +import { getCWSUsers, getChromeUsers } from "../utils/getCWSUsers"; // A cache of the number of chrome web store users let chromeUsersCache = 0; @@ -79,27 +79,4 @@ function updateExtensionUsers() { getChromeUsers(chromeExtensionUrl) .then(res => chromeUsersCache = res) ); -} - -/* istanbul ignore next */ -function getChromeUsers(chromeExtensionUrl: string): Promise { - return axios.get(chromeExtensionUrl) - .then(res => { - const body = res.data; - // 2021-01-05 - // [...]= 0) { - const closingQuoteIndex = body.indexOf('"', userDownloadsStartIndex + matchingStringLen); - const userDownloadsStr = body.substr(userDownloadsStartIndex + matchingStringLen, closingQuoteIndex - userDownloadsStartIndex).replace(",", "").replace(".", ""); - return parseInt(userDownloadsStr); - } - }) - .catch(/* istanbul ignore next */ () => { - Logger.debug(`Failing to connect to ${chromeExtensionUrl}`); - return 0; - }); } \ No newline at end of file diff --git a/src/routes/getTotalStats.ts b/src/routes/getTotalStats.ts index 2eab75e..08817b7 100644 --- a/src/routes/getTotalStats.ts +++ b/src/routes/getTotalStats.ts @@ -3,7 +3,7 @@ import { config } from "../config"; import { Request, Response } from "express"; import axios from "axios"; import { Logger } from "../utils/logger"; -import { getCWSUsers } from "../utils/getCWSUsers"; +import { getCWSUsers, getChromeUsers } from "../utils/getCWSUsers"; // A cache of the number of chrome web store users let chromeUsersCache = 0; @@ -97,29 +97,4 @@ function updateExtensionUsers() { getChromeUsers(chromeExtensionUrl) .then(res => chromeUsersCache = res) ); -} - -/* istanbul ignore next */ -function getChromeUsers(chromeExtensionUrl: string): Promise { - return axios.get(chromeExtensionUrl) - .then(res => { - const body = res.data; - // 2021-01-05 - // [...]= 0) { - const closingQuoteIndex = body.indexOf('"', userDownloadsStartIndex + matchingStringLen); - const userDownloadsStr = body.substr(userDownloadsStartIndex + matchingStringLen, closingQuoteIndex - userDownloadsStartIndex).replace(",", "").replace(".", ""); - return parseInt(userDownloadsStr); - } else { - lastUserCountCheck = 0; - } - }) - .catch(/* istanbul ignore next */ () => { - Logger.debug(`Failing to connect to ${chromeExtensionUrl}`); - return 0; - }); } \ No newline at end of file diff --git a/src/utils/getCWSUsers.ts b/src/utils/getCWSUsers.ts index 35aeaf0..9ebebb3 100644 --- a/src/utils/getCWSUsers.ts +++ b/src/utils/getCWSUsers.ts @@ -2,6 +2,7 @@ import axios from "axios"; import { Logger } from "../utils/logger"; export const getCWSUsers = (extID: string): Promise => + axios.post(`https://chrome.google.com/webstore/ajax/detail?pv=20210820&id=${extID}`) .then(res => res.data.split("\n")[2]) .then(data => JSON.parse(data)) @@ -10,4 +11,22 @@ export const getCWSUsers = (extID: string): Promise => .catch((err) => { Logger.error(`Error getting chrome users - ${err}`); return 0; - }); \ No newline at end of file + }); + +/* istanbul ignore next */ +export function getChromeUsers(chromeExtensionUrl: string): Promise { + return axios.get(chromeExtensionUrl) + .then(res => { + const body = res.data; + // 2024-02-09 + // >20,000 users< + const match = body.match(/>([\d,]+) users { + Logger.debug(`Failing to connect to ${chromeExtensionUrl}`); + return 0; + }); +} \ No newline at end of file