diff --git a/functions/share/create.ts b/functions/share/create.ts index 09d9d7a7c..ebc0306ac 100644 --- a/functions/share/create.ts +++ b/functions/share/create.ts @@ -86,7 +86,7 @@ export const onRequestPost: PagesFunction = async (context) => { JSON.stringify({ 'Status': 500, 'Message': e instanceof Error ? e.message : e, - 'ShortUrl': null, + 'Key': null, }), { 'status': 500, diff --git a/package.json b/package.json index 4a69989fb..fab47a057 100644 --- a/package.json +++ b/package.json @@ -59,7 +59,6 @@ "@mui/icons-material": "^6.1.5", "@mui/material": "^6.1.5", "@reduxjs/toolkit": "^2.3.0", - "axios": "^1.7.7", "comlink": "^4.4.1", "i18next": "^23.16.4", "js-yaml": "^4.1.0", @@ -97,6 +96,7 @@ "@typescript-eslint/eslint-plugin": "^8.12.2", "@typescript-eslint/parser": "^8.12.2", "@vitejs/plugin-react": "^4.3.3", + "axios": "^1.7.7", "babel-plugin-i18next-extract": "^0.10.0", "concurrently": "^9.0.1", "eslint": "^8.57.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1f3b73b5a..d5c146eba 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,9 +41,6 @@ importers: '@reduxjs/toolkit': specifier: ^2.3.0 version: 2.3.0(react-redux@9.1.2(@types/react@18.3.12)(react@18.3.1)(redux@5.0.1))(react@18.3.1) - axios: - specifier: ^1.7.7 - version: 1.7.7 comlink: specifier: ^4.4.1 version: 4.4.1 @@ -150,6 +147,9 @@ importers: '@vitejs/plugin-react': specifier: ^4.3.3 version: 4.3.3(vite@5.4.10(@types/node@22.8.4)) + axios: + specifier: ^1.7.7 + version: 1.7.7 babel-plugin-i18next-extract: specifier: ^0.10.0 version: 0.10.0 diff --git a/src/components/sections/results/BuildShareModal/ModalContent.jsx b/src/components/sections/results/BuildShareModal/ModalContent.jsx index d038b202c..0e187e6d0 100644 --- a/src/components/sections/results/BuildShareModal/ModalContent.jsx +++ b/src/components/sections/results/BuildShareModal/ModalContent.jsx @@ -2,7 +2,6 @@ import { Error, Icon, Item, Progress } from '@discretize/gw2-ui-new'; import { firstUppercase } from '@discretize/react-discretize-components'; import DoneIcon from '@mui/icons-material/Done'; import { Box, Button, ButtonGroup, MenuItem, Select, Typography } from '@mui/material'; -import axios from 'axios'; import React from 'react'; import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; @@ -59,9 +58,9 @@ export default function ModalContent({ character, buttons }) { }; React.useEffect(() => { - axios - .get(`https://api.guildwars2.com/v2/professions/${firstUppercase(profession)}`) - .then((res) => setState({ error: undefined, skills: res.data.skills })) + fetch(`https://api.guildwars2.com/v2/professions/${firstUppercase(profession)}`) + .then((response) => response.json()) + .then((res) => setState({ error: undefined, skills: res.skills })) .catch((e) => { console.error(e); setState({ error: e.message }); diff --git a/src/components/url-state/URLStateImport.tsx b/src/components/url-state/URLStateImport.tsx index 751a3b175..bc53322c5 100644 --- a/src/components/url-state/URLStateImport.tsx +++ b/src/components/url-state/URLStateImport.tsx @@ -1,4 +1,3 @@ -import axios from 'axios'; import React from 'react'; import { importFormState } from '../../state/async/formStateThunks'; import { useAppDispatch } from '../../state/redux-hooks'; @@ -63,10 +62,10 @@ const URLStateImport = ({ clearUrlOnSuccess }: URLStateImportProps) => { // found shortened link, resolve the data. // cf-function can be found in /functions/share/load.ts const key = shortenerKey.slice(0, -2); - axios - .get(`share/load?${PARAMS.SHORTENER_KEY}=${key}`, { responseType: 'arraybuffer' }) + fetch(`share/load?${PARAMS.SHORTENER_KEY}=${key}`) + .then((response) => response.arrayBuffer()) .then((response) => { - const binaryData = new Uint8Array(response.data); + const binaryData = new Uint8Array(response); console.log(binaryData); dispatch(importFormState({ binaryData, onSuccess: onLoadSuccess, onError: onLoadError })); diff --git a/src/state/async/formStateThunks.ts b/src/state/async/formStateThunks.ts index 7e16abd68..13fadad4a 100644 --- a/src/state/async/formStateThunks.ts +++ b/src/state/async/formStateThunks.ts @@ -1,4 +1,3 @@ -import axios from 'axios'; import type { TFunction } from 'i18next'; import JsonUrl from 'json-url'; import pako from 'pako'; @@ -90,14 +89,15 @@ const getShortUrl = async (exportData: unknown) => { const binaryData = pako.deflate(JSON.stringify(exportData)); console.timeEnd('Compressed binary data in:'); - const response = await axios.post(`share/create`, binaryData).catch(console.error); - if (response?.data?.Status !== 200) { - console.log( - `URL shortener returned status ${response?.data?.Status}! Falling back to long URL.`, - ); + const response = await fetch(`share/create`, { method: 'POST', body: binaryData }) + .then((response) => response.json<{ Status: number; Message: string; Key: string | null }>()) + .catch(console.error); + + if (!response || response?.Status !== 200) { + console.log(`URL shortener returned status ${response?.Status}! Falling back to long URL.`); throw new Error('failure'); } - const { Key } = response.data; + const { Key } = response; const urlObject = new URL(window.location.href); urlObject.searchParams.set(PARAMS.SHORTENER_KEY, `${Key}v1`);