From cbf7f7478b45720333a9e34ae0a216b980d43ee8 Mon Sep 17 00:00:00 2001 From: sherry Date: Thu, 14 Sep 2023 17:26:09 +0800 Subject: [PATCH] feat: add S3 storage module --- src/components/Cards/CardConfig.js | 24 +---------------- src/components/Cards/S3CardConfig.js | 40 +++++++++++++++++++++++++--- src/components/Tables/S3ApiTable.js | 4 +-- 3 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/components/Cards/CardConfig.js b/src/components/Cards/CardConfig.js index 17898d2..a540d8d 100644 --- a/src/components/Cards/CardConfig.js +++ b/src/components/Cards/CardConfig.js @@ -1,16 +1,13 @@ -import React, { useState, useEffect, useRef, memo, useContext } from 'react'; +import React, { useState, useEffect, useRef, memo } from 'react'; import { Switch, Tooltip } from 'antd'; import { InfoCircleOutlined } from '@ant-design/icons'; import { Link } from 'react-router-dom'; import ButtonRoundRect from 'components/Buttons/ButtonRoundRect'; import Emitter from 'utils/eventBus'; -import { getUrl } from 'utils/BTFSUtil'; import { t } from 'utils/text.js'; -import { mainContext } from 'reducer'; import { getHostConfigData, resetHostConfigData, editHostConfig } from 'services/otherService.js'; function CardConfig({ color }) { - const { dispatch } = useContext(mainContext); const [configList, setConfigList] = useState([]); const [rpcAddress, setRpcAddress] = useState(''); const rpcAddressRef = useRef(null); @@ -66,17 +63,7 @@ function CardConfig({ color }) { const data = await getHostConfigData(); let configList = []; let rpcAddress = ''; - let s3ApiUrl = ''; - let addressConfig = null; - if (data && data.Experimental) { - const { S3CompatibleAPI, Addresses } = data; - console.log('S3CompatibleAPI', S3CompatibleAPI); - s3ApiUrl = S3CompatibleAPI?.Address; - addressConfig = Addresses; - if(addressConfig){ - addressConfig.Gateway = getUrl(addressConfig.Gateway, true); - } const { Experimental, ChainInfo } = data; if (Experimental) { configList = handleExperimentalData(Experimental); @@ -89,16 +76,7 @@ function CardConfig({ color }) { return configList; }); setRpcAddress(rpcAddress); - dispatch({ - type: 'SET_S3_API_URL', - s3ApiUrl: getUrl(s3ApiUrl), - }); - dispatch({ - type: 'SET_ADDRESS_CONFIG', - addressConfig: addressConfig, - }); - }; const handleExperimentalData = experimental => { if (!experimental) return []; diff --git a/src/components/Cards/S3CardConfig.js b/src/components/Cards/S3CardConfig.js index 5eba694..ebcc5e4 100644 --- a/src/components/Cards/S3CardConfig.js +++ b/src/components/Cards/S3CardConfig.js @@ -1,14 +1,48 @@ -import React, { memo, useContext } from 'react'; +import React, { memo, useEffect, useContext } from 'react'; import { mainContext } from 'reducer'; import { Tooltip } from 'antd'; import { InfoCircleOutlined } from '@ant-design/icons'; import { Link } from 'react-router-dom'; import ClipboardCopy from 'components/Utils/ClipboardCopy'; import { t } from 'utils/text.js'; +import { getHostConfigData, } from 'services/otherService.js'; +import { getUrl } from 'utils/BTFSUtil'; function S3CardConfig({ color }) { - const { state } = useContext(mainContext); + const { dispatch, state } = useContext(mainContext); const { s3ApiUrl } = state; + const nodeUrl = localStorage.getItem('NODE_URL') + + const fetchData = async () => { + const data = await getHostConfigData(); + let s3ApiUrl = ''; + let addressConfig = null; + + if (data && data.Experimental) { + const { S3CompatibleAPI, Addresses } = data; + s3ApiUrl = S3CompatibleAPI?.Address; + addressConfig = Addresses; + if (addressConfig) { + addressConfig.Gateway = getUrl(addressConfig.Gateway, true); + } + } + + dispatch({ + type: 'SET_S3_API_URL', + s3ApiUrl: getUrl(s3ApiUrl), + }); + dispatch({ + type: 'SET_ADDRESS_CONFIG', + addressConfig: addressConfig, + }); + }; + + + useEffect(() => { + fetchData(); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [nodeUrl]); + return (
@@ -41,7 +75,7 @@ function S3CardConfig({ color }) { - +
diff --git a/src/components/Tables/S3ApiTable.js b/src/components/Tables/S3ApiTable.js index 98ae147..1e71ed4 100644 --- a/src/components/Tables/S3ApiTable.js +++ b/src/components/Tables/S3ApiTable.js @@ -99,9 +99,9 @@ export default function S3ApiTable({ color }) { } const fetchData = async () => { - const data = await getS3AccessKeyList(); - console.log("getS3AccessKeyList", data); + let data = await getS3AccessKeyList(); if (data && data.length) { + data = data.filter((item)=>item.enable) setAccessKeyList(data); setAccessData(data[0]); fetchBucketList(data[0]);