refactor: use bee-js for health endpoint (#38)
* refactor: use bee-js for health endpoint * refactor: fix API URLs which could be undefined
This commit is contained in:
@@ -6,7 +6,7 @@ import type { NodeAddresses, ChequebookAddressResponse, ChequebookBalanceRespons
|
|||||||
import { beeDebugApi, beeApi } from '../services/bee';
|
import { beeDebugApi, beeApi } from '../services/bee';
|
||||||
|
|
||||||
export const useApiHealth = () => {
|
export const useApiHealth = () => {
|
||||||
const [health, setHealth] = useState('')
|
const [health, setHealth] = useState<boolean>(false)
|
||||||
const [isLoadingHealth, setLoading] = useState<boolean>(false)
|
const [isLoadingHealth, setLoading] = useState<boolean>(false)
|
||||||
const [error, setError] = useState<Error | null>(null)
|
const [error, setError] = useState<Error | null>(null)
|
||||||
|
|
||||||
@@ -14,7 +14,7 @@ export const useApiHealth = () => {
|
|||||||
setLoading(true)
|
setLoading(true)
|
||||||
beeApi.status.health()
|
beeApi.status.health()
|
||||||
.then(res => {
|
.then(res => {
|
||||||
setHealth(res.data)
|
setHealth(res)
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
setError(error)
|
setError(error)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import {DropzoneArea} from 'material-ui-dropzone'
|
|||||||
import ClipboardCopy from '../../components/ClipboardCopy';
|
import ClipboardCopy from '../../components/ClipboardCopy';
|
||||||
|
|
||||||
import TroubleshootConnectionCard from '../../components/TroubleshootConnectionCard';
|
import TroubleshootConnectionCard from '../../components/TroubleshootConnectionCard';
|
||||||
|
import { Data, FileData } from '@ethersphere/bee-js';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme: Theme) =>
|
const useStyles = makeStyles((theme: Theme) =>
|
||||||
createStyles({
|
createStyles({
|
||||||
@@ -36,7 +37,7 @@ export default function Files(props: any) {
|
|||||||
|
|
||||||
const [inputMode, setInputMode] = useState<'browse' | 'upload'>('browse');
|
const [inputMode, setInputMode] = useState<'browse' | 'upload'>('browse');
|
||||||
const [searchInput, setSearchInput] = useState('');
|
const [searchInput, setSearchInput] = useState('');
|
||||||
const [searchResult, setSearchResult] = useState('');
|
const [searchResult, setSearchResult] = useState<FileData<Data> | null>(null);
|
||||||
const [loadingSearch, setLoadingSearch] = useState(false);
|
const [loadingSearch, setLoadingSearch] = useState(false);
|
||||||
|
|
||||||
const [files, setFiles] = useState<File[]>([]);
|
const [files, setFiles] = useState<File[]>([]);
|
||||||
@@ -47,7 +48,8 @@ export default function Files(props: any) {
|
|||||||
setLoadingSearch(true)
|
setLoadingSearch(true)
|
||||||
beeApi.files.downloadFile(searchInput)
|
beeApi.files.downloadFile(searchInput)
|
||||||
.then(res => {
|
.then(res => {
|
||||||
setSearchResult(new TextDecoder("utf-8").decode(res.data))
|
setSearchResult(res)
|
||||||
|
|
||||||
const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
|
const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
|
||||||
const link = document.createElement('a');
|
const link = document.createElement('a');
|
||||||
link.href = downloadUrl;
|
link.href = downloadUrl;
|
||||||
|
|||||||
+9
-33
@@ -1,39 +1,21 @@
|
|||||||
import axios, { AxiosInstance } from 'axios';
|
import axios, { AxiosInstance } from 'axios';
|
||||||
import { Bee } from "@ethersphere/bee-js";
|
import { Bee, Reference } from "@ethersphere/bee-js";
|
||||||
|
|
||||||
const beeJSClient = () => {
|
const beeJSClient = () => {
|
||||||
let apiHost
|
let apiHost = process.env.REACT_APP_BEE_HOST || 'http://localhost:1633'
|
||||||
|
|
||||||
if (sessionStorage.getItem('api_host')) {
|
if (sessionStorage.getItem('api_host')) {
|
||||||
apiHost = String(sessionStorage.getItem('api_host') || '')
|
apiHost = String(sessionStorage.getItem('api_host'))
|
||||||
} else {
|
|
||||||
apiHost = process.env.REACT_APP_BEE_HOST
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Bee(`${apiHost}`)
|
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
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const beeDebugApiClient = (): AxiosInstance => {
|
const beeDebugApiClient = (): AxiosInstance => {
|
||||||
let debugApiHost
|
let debugApiHost = process.env.REACT_APP_BEE_DEBUG_HOST || 'http://localhost:1635'
|
||||||
|
|
||||||
if (sessionStorage.getItem('debug_api_host')) {
|
if (sessionStorage.getItem('debug_api_host')) {
|
||||||
debugApiHost = String(sessionStorage.getItem('debug_api_host') || '')
|
debugApiHost = String(sessionStorage.getItem('debug_api_host'))
|
||||||
} else {
|
|
||||||
debugApiHost = process.env.REACT_APP_BEE_DEBUG_HOST
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return axios.create({
|
return axios.create({
|
||||||
@@ -44,22 +26,16 @@ const beeDebugApiClient = (): AxiosInstance => {
|
|||||||
export const beeApi = {
|
export const beeApi = {
|
||||||
status: {
|
status: {
|
||||||
health() {
|
health() {
|
||||||
return beeApiClient().get('/')
|
return beeJSClient().isConnected()
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
files: {
|
files: {
|
||||||
uploadFile(file: any) {
|
uploadFile(file: File) {
|
||||||
return beeJSClient().uploadFile(file)
|
return beeJSClient().uploadFile(file)
|
||||||
},
|
},
|
||||||
uploadData(file: any) {
|
downloadFile(hash: string | Reference) {
|
||||||
return beeJSClient().uploadData(file)
|
|
||||||
},
|
|
||||||
downloadFile(hash: string) {
|
|
||||||
return beeJSClient().downloadFile(hash)
|
return beeJSClient().downloadFile(hash)
|
||||||
},
|
},
|
||||||
downloadData(hash: string) {
|
|
||||||
return beeJSClient().downloadData(hash)
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user