Skip to content

Commit

Permalink
Handle V2 API requests the same as V1.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeKleineKobini committed Jan 24, 2025
1 parent 526d52e commit ea744fe
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions extension/scripts/global/functions/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ async function fetchData(location, options = {}) {
if (result.error) {
await handleError(result);
} else {
if (location === "torn" && !options.silent && SCRIPT_TYPE === "BACKGROUND") {
if (isTornAPICall(location) && !options.silent && SCRIPT_TYPE === "BACKGROUND") {
await getBadgeText()
.then(async (value) => {
if (value === "error") await setBadge("default");
Expand Down Expand Up @@ -255,7 +255,7 @@ async function fetchData(location, options = {}) {
const isLocal = false;
const code = CUSTOM_API_ERROR.CANCELLED;

if (location === "torn" && !options.silent && SCRIPT_TYPE === "BACKGROUND") {
if (isTornAPICall(location) && !options.silent && SCRIPT_TYPE === "BACKGROUND") {
await ttStorage.change({ api: { torn: { online: false, error } } });
await setBadge("error");
}
Expand All @@ -276,12 +276,12 @@ async function fetchData(location, options = {}) {
}
}

if (location === "torn" && !options.silent && SCRIPT_TYPE === "BACKGROUND") {
if (isTornAPICall(location) && !options.silent && SCRIPT_TYPE === "BACKGROUND") {
await ttStorage.change({ api: { torn: { online: false, error } } });
await setBadge("error");
}
reject({ error, isLocal, code });
} else if (location === "torn") {
} else if (isTornAPICall(location)) {
let error, online;

if (result.error instanceof HTTPException) {
Expand Down Expand Up @@ -310,6 +310,10 @@ async function fetchData(location, options = {}) {
});
}

function isTornAPICall(location) {
return ["torn", "tornv2"].includes(location);
}

function checkAPIPermission(key) {
return new Promise((resolve, reject) => {
fetchData("torn", { section: "key", selections: ["info"], key, silent: true })
Expand Down

0 comments on commit ea744fe

Please sign in to comment.