diff --git a/src/hooks/apiHooks.tsx b/src/hooks/apiHooks.tsx index 45432f6..b77d508 100644 --- a/src/hooks/apiHooks.tsx +++ b/src/hooks/apiHooks.tsx @@ -6,7 +6,7 @@ import type { NodeAddresses, ChequebookAddressResponse, ChequebookBalanceRespons import { beeDebugApi, beeApi } from '../services/bee'; export const useApiHealth = () => { - const [health, setHealth] = useState('') + const [health, setHealth] = useState(false) const [isLoadingHealth, setLoading] = useState(false) const [error, setError] = useState(null) @@ -14,7 +14,7 @@ export const useApiHealth = () => { setLoading(true) beeApi.status.health() .then(res => { - setHealth(res.data) + setHealth(res) }) .catch(error => { setError(error) diff --git a/src/pages/files/index.tsx b/src/pages/files/index.tsx index 6b487de..7286b69 100644 --- a/src/pages/files/index.tsx +++ b/src/pages/files/index.tsx @@ -8,6 +8,7 @@ import {DropzoneArea} from 'material-ui-dropzone' import ClipboardCopy from '../../components/ClipboardCopy'; import TroubleshootConnectionCard from '../../components/TroubleshootConnectionCard'; +import { Data, FileData } from '@ethersphere/bee-js'; const useStyles = makeStyles((theme: Theme) => createStyles({ @@ -36,7 +37,7 @@ export default function Files(props: any) { const [inputMode, setInputMode] = useState<'browse' | 'upload'>('browse'); const [searchInput, setSearchInput] = useState(''); - const [searchResult, setSearchResult] = useState(''); + const [searchResult, setSearchResult] = useState | null>(null); const [loadingSearch, setLoadingSearch] = useState(false); const [files, setFiles] = useState([]); @@ -47,7 +48,8 @@ export default function Files(props: any) { setLoadingSearch(true) beeApi.files.downloadFile(searchInput) .then(res => { - setSearchResult(new TextDecoder("utf-8").decode(res.data)) + setSearchResult(res) + const downloadUrl = window.URL.createObjectURL(new Blob([res.data])); const link = document.createElement('a'); link.href = downloadUrl; diff --git a/src/services/bee.tsx b/src/services/bee.tsx index 6249e37..4bc7156 100644 --- a/src/services/bee.tsx +++ b/src/services/bee.tsx @@ -1,39 +1,21 @@ import axios, { AxiosInstance } from 'axios'; -import { Bee } from "@ethersphere/bee-js"; +import { Bee, Reference } from "@ethersphere/bee-js"; const beeJSClient = () => { - let apiHost + let apiHost = process.env.REACT_APP_BEE_HOST || 'http://localhost:1633' if (sessionStorage.getItem('api_host')) { - apiHost = String(sessionStorage.getItem('api_host') || '') - } else { - apiHost = process.env.REACT_APP_BEE_HOST + apiHost = String(sessionStorage.getItem('api_host')) } - return new Bee(`${apiHost}`) -} - -const beeApiClient = (): AxiosInstance => { - let apiHost - - if (sessionStorage.getItem('api_host')) { - apiHost = String(sessionStorage.getItem('api_host') || '') - } else { - apiHost = process.env.REACT_APP_BEE_HOST - } - - return axios.create({ - baseURL: apiHost - }) + return new Bee(apiHost) } const beeDebugApiClient = (): AxiosInstance => { - let debugApiHost + let debugApiHost = process.env.REACT_APP_BEE_DEBUG_HOST || 'http://localhost:1635' if (sessionStorage.getItem('debug_api_host')) { - debugApiHost = String(sessionStorage.getItem('debug_api_host') || '') - } else { - debugApiHost = process.env.REACT_APP_BEE_DEBUG_HOST + debugApiHost = String(sessionStorage.getItem('debug_api_host')) } return axios.create({ @@ -44,22 +26,16 @@ const beeDebugApiClient = (): AxiosInstance => { export const beeApi = { status: { health() { - return beeApiClient().get('/') + return beeJSClient().isConnected() } }, files: { - uploadFile(file: any) { + uploadFile(file: File) { return beeJSClient().uploadFile(file) }, - uploadData(file: any) { - return beeJSClient().uploadData(file) - }, - downloadFile(hash: string) { + downloadFile(hash: string | Reference) { return beeJSClient().downloadFile(hash) }, - downloadData(hash: string) { - return beeJSClient().downloadData(hash) - }, }, }