Skip to content

Commit ea744fe

Browse files
Handle V2 API requests the same as V1.
1 parent 526d52e commit ea744fe

File tree

1 file changed

+8
-4
lines changed
  • extension/scripts/global/functions

1 file changed

+8
-4
lines changed

extension/scripts/global/functions/api.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ async function fetchData(location, options = {}) {
224224
if (result.error) {
225225
await handleError(result);
226226
} else {
227-
if (location === "torn" && !options.silent && SCRIPT_TYPE === "BACKGROUND") {
227+
if (isTornAPICall(location) && !options.silent && SCRIPT_TYPE === "BACKGROUND") {
228228
await getBadgeText()
229229
.then(async (value) => {
230230
if (value === "error") await setBadge("default");
@@ -255,7 +255,7 @@ async function fetchData(location, options = {}) {
255255
const isLocal = false;
256256
const code = CUSTOM_API_ERROR.CANCELLED;
257257

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

279-
if (location === "torn" && !options.silent && SCRIPT_TYPE === "BACKGROUND") {
279+
if (isTornAPICall(location) && !options.silent && SCRIPT_TYPE === "BACKGROUND") {
280280
await ttStorage.change({ api: { torn: { online: false, error } } });
281281
await setBadge("error");
282282
}
283283
reject({ error, isLocal, code });
284-
} else if (location === "torn") {
284+
} else if (isTornAPICall(location)) {
285285
let error, online;
286286

287287
if (result.error instanceof HTTPException) {
@@ -310,6 +310,10 @@ async function fetchData(location, options = {}) {
310310
});
311311
}
312312

313+
function isTornAPICall(location) {
314+
return ["torn", "tornv2"].includes(location);
315+
}
316+
313317
function checkAPIPermission(key) {
314318
return new Promise((resolve, reject) => {
315319
fetchData("torn", { section: "key", selections: ["info"], key, silent: true })

0 commit comments

Comments
 (0)