Simplify vip info fetching

This commit is contained in:
Ajay Ramachandran
2021-10-13 23:25:46 -04:00
parent ff5fa4c724
commit 9b9174ab9a

View File

@@ -756,12 +756,12 @@ async function sponsorsLookup(id: string, keepOldSubmissions = true) {
sponsorLookupRetries++; sponsorLookupRetries++;
} }
getVipSegmentsWarnings(id); lookupVipInformation(id);
} }
function getVipSegmentsWarnings(id: string): void { function lookupVipInformation(id: string): void {
// Look up locked status if the user is a vip updateVipInfo();
isVipLookup();
const isVip = Config.config.isVip; const isVip = Config.config.isVip;
if (isVip) { if (isVip) {
lockedCategoriesLookup(id); lockedCategoriesLookup(id);
@@ -769,51 +769,50 @@ function getVipSegmentsWarnings(id: string): void {
} }
} }
async function isVipLookup() { async function updateVipInfo() {
const currentTime = Date.now(); const currentTime = Date.now();
const lastUpdate = Config.config.lastIsVipUpdate; const lastUpdate = Config.config.lastIsVipUpdate;
if (currentTime - lastUpdate > 1000*60*60*24) { //max every 24 hours 1000*60*60*24 if (currentTime - lastUpdate > 1000 * 60 * 60 * 72) { // 72 hours
Config.config.lastIsVipUpdate = currentTime; Config.config.lastIsVipUpdate = currentTime;
utils.sendRequestToServer("GET", "/api/isUserVIP?userID=" + Config.config.userID,
(response) => { utils.sendRequestToServer("GET", "/api/isUserVIP?userID=" + Config.config.userID, (response) => {
if (response.status === 200) { if (response.status === 200) {
if (JSON.parse(response.responseText).vip === true) { let isVip = false;
Config.config.isVip = true; try {
} const vipResponse = JSON.parse(response.responseText)?.vip;
else Config.config.isVip = false; if (typeof(vipResponse) === "boolean") {
isVip = vipResponse;
}
} catch (e) { } //eslint-disable-line no-empty
Config.config.isVip = isVip;
} }
} });
)
} }
} }
async function lockedSegmentsLookup() { async function lockedSegmentsLookup() {
let url = "" utils.asyncRequestToServer("GET", "/api/segmentInfo", { UUIDs: sponsorTimes?.map((segment) => segment.UUID) })
for (let i = 0; i < sponsorTimes.length; i++) { .then((response) => {
if (i !== 0) url += ","; if (response.status === 200) {
url += `"` + sponsorTimes[i].UUID + `"`; for (let i = 0; i < sponsorTimes.length && i < 10; i++) { // Because the api only return 10 segments maximum
} try {
utils.sendRequestToServer("GET", "/api/segmentInfo?UUIDs=[" + url + "]",
(response) => {
if (response.status === 200) {
for (let i = 0; i < sponsorTimes.length && i < 10; i++) { //because the api only return 10 segments maximum
sponsorTimes[i].locked = (JSON.parse(response.responseText)[i].locked === 1) ? true : false; sponsorTimes[i].locked = (JSON.parse(response.responseText)[i].locked === 1) ? true : false;
} } catch (e) { } //eslint-disable-line no-empty
} }
} }
) });
} }
async function lockedCategoriesLookup(id: string) { async function lockedCategoriesLookup(id: string) {
utils.sendRequestToServer("GET", "/api/lockCategories?videoID=" + id, utils.asyncRequestToServer("GET", "/api/lockCategories?videoID=" + id)
(response) => { .then((response) => {
if (response.status === 200 && response.ok) { if (response.status === 200 && response.ok) {
for (const category of JSON.parse(response.responseText).categories) { for (const category of JSON.parse(response.responseText).categories) {
lockedCategories.push(category); lockedCategories.push(category);
}
} }
} }
) });
} }
function retryFetch(): void { function retryFetch(): void {