From 68fd1fe5f0cde859d5eb0e0fe3988dab6a3c0dcd Mon Sep 17 00:00:00 2001 From: Mikhail Petrov Date: Tue, 10 Dec 2024 00:27:20 +0300 Subject: [PATCH] web: Add ability to set token expiration for shared objects, closed #175 Signed-off-by: Mikhail Petrov --- src/App.js | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/App.js b/src/App.js index 44affdd..934f151 100644 --- a/src/App.js +++ b/src/App.js @@ -34,6 +34,10 @@ function capitalizeFirstLetter(string) { return string.charAt(0).toUpperCase() + string.slice(1); } +function formatDateToHours(date) { + return Math.floor((new Date(`${date}T23:59:00`).getTime() - new Date().getTime()) / 1000 / 60 / 60) +} + export const App = () => { const location = useLocation(); const navigate = useNavigate(); @@ -51,6 +55,7 @@ export const App = () => { rest_gw: process.env.REACT_APP_RESTGW ? process.env.REACT_APP_RESTGW : 'https://rest.t5.fs.neo.org/v1', }); + const [objectLinkLifetime, setObjectLinkLifetime] = useState(new Date().toLocaleDateString("sv")); const [networkInfo, setNetworkInfo] = useState(null); const [depositQuantity, setDepositQuantity] = useState(0); const [withdrawQuantity, setWithdrawQuantity] = useState(0); @@ -344,7 +349,7 @@ export const App = () => { api('POST', '/auth', body, { "X-Bearer-Owner-Id": walletData.account.address, - "X-Bearer-Lifetime": params.objectId ? 24 : 2, + "X-Bearer-Lifetime": params.objectId ? formatDateToHours(objectLinkLifetime) : 2, "X-Bearer-For-All-Users": true, }).then((e) => { onSignMessage(e[0].token, type, operation, params); @@ -1581,18 +1586,27 @@ export const App = () => { /> Sharing object - {`You can share a link to this object, it will be available ${modal.text.type === 'private' ? 'for 1 day' : 'until EACL change'} to everyone without authorization`} + {`You can share a link to this object, it will be available to everyone without authorization until${modal.text.type === 'private' ? ':' : ' EACL change'}${!modal.text.token && modal.text.type === 'private' ? '' : ` ${new Date(objectLinkLifetime).toLocaleDateString()}`}`} {!modal.text.token && modal.text.type === 'private' ? ( -
- Sign token to share object - -
+ <> + + setObjectLinkLifetime(e.target.value)} + /> + +
+ Sign token to share object + +
+ ) : ( <>