Skip to content

Commit

Permalink
fix: update got options and remove custom wago error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Stanzilla committed Jan 16, 2025
1 parent 11f1533 commit 8a91f62
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 24 deletions.
3 changes: 1 addition & 2 deletions src/components/LandingPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -427,9 +427,8 @@ export default defineComponent({
headers: {
"Identifier": this.accountHash,
"api-key": this.config.wagoApiKey || "",
"User-Agent": `WeakAuras Companion ${__APP_VERSION__})`,
"User-Agent": `WeakAuras Companion ${__APP_VERSION__}`,
},
crossdomain: true,
timeout: {
request: 30000,
},
Expand Down
22 changes: 9 additions & 13 deletions src/libs/compare-sv-with-wago.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import type {
Version,
} from "@/stores/config";
import type { Response } from "got";
import got from "got";
import got, { Options } from "got";
import luaparse from "luaparse";

import hash from "./hash";
Expand Down Expand Up @@ -47,12 +47,12 @@ export async function compareSVwithWago(

let fetching = fetchingState;

const getAccountHash = () => {
const getAccountHash = (): string => {
if (versionSelected) {
const { account } = versionSelected;
return hash.hashFnv32a(account, true);
return hash.hashFnv32a(account, true).toString();
}
return null;
return "";
};

const setFirstAddonInstalledSelected = (
Expand All @@ -74,14 +74,13 @@ export async function compareSVwithWago(
schedule.id = setTimeout(refreshWago, timeout);
};

const getGotOptions = () => ({
const gotOptions = new Options({
http2: true,
headers: {
"Identifier": getAccountHash(),
"api-key": config.wagoApiKey || "",
"User-Agent": `WeakAuras Companion ${__APP_VERSION__})`,
"User-Agent": `WeakAuras Companion ${__APP_VERSION__}`,
},
crossdomain: true,
timeout: {
request: 30000,
},
Expand Down Expand Up @@ -247,7 +246,7 @@ export async function compareSVwithWago(
promisesWagoCallsComplete.push(
got
.post<WagoApiResponse>(config.wagoAPI, {
...getGotOptions,
...gotOptions,
responseType: "json",
json: {
ids: fetchAuras,
Expand Down Expand Up @@ -288,7 +287,7 @@ export async function compareSVwithWago(
got(
`https://data.wago.io/api/raw/encoded?id=${wagoData._id}`,
{
...getGotOptions,
...gotOptions,
responseType: "text",
},
),
Expand Down Expand Up @@ -356,10 +355,7 @@ export async function compareSVwithWago(
fetching = false;
fetchingUpdateCallback(fetching);

const delay =
error.code === "ERR_NON_2XX_3XX_RESPONSE" // Server said nope
? 1000 * 10 // 10 seconds
: MINUTES_30;
const delay = MINUTES_30;
scheduleRefreshWago(delay);
return;
}
Expand Down
17 changes: 8 additions & 9 deletions src/libs/wago-push-handler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { StashStore } from "@/stores/auras";
import type { ConfigState, Version } from "@/stores/config";
import type { Response } from "got";
import got from "got";
import got, { Options } from "got";

import hash from "./hash";

Expand All @@ -19,22 +19,21 @@ export async function wagoPushHandler(
) {
const existingAuraIndex = stash.auras.findIndex((aura) => aura.slug === slug);

const getAccountHash = () => {
const getAccountHash = (): string => {
if (versionSelected) {
const { account } = versionSelected;
return hash.hashFnv32a(account, true);
return hash.hashFnv32a(account, true).toString();
}
return null;
return "";
};

const getGotOptions = () => ({
const gotOptions = new Options({
http2: true,
headers: {
"Identifier": getAccountHash(),
"api-key": config.wagoApiKey || "",
"User-Agent": `WeakAuras Companion ${__APP_VERSION__})`,
"User-Agent": `WeakAuras Companion ${__APP_VERSION__}`,
},
crossdomain: true,
timeout: {
request: 30000,
},
Expand All @@ -45,7 +44,7 @@ export async function wagoPushHandler(
const response: Response<WagoApiResponse> = await got(
`https://data.wago.io/api/check/?ids=${slug}`,
{
...getGotOptions,
...gotOptions,
responseType: "json",
},
);
Expand Down Expand Up @@ -73,7 +72,7 @@ export async function wagoPushHandler(
const response2 = await got(
`https://data.wago.io/api/raw/encoded?id=${wagoData._id}`,
{
...getGotOptions,
...gotOptions,
responseType: "text",
},
);
Expand Down

0 comments on commit 8a91f62

Please sign in to comment.