diff --git a/common/utilities.ts b/common/utilities.ts index 8138404..85d0504 100644 --- a/common/utilities.ts +++ b/common/utilities.ts @@ -172,6 +172,32 @@ export const getAuthAddress = async (headers) => { } } +export const getUserStorageThreshold = async (headers) => { + try { + const token = Cookies.get(headers, C.auth); + const url = `${C.api.host}/user/utilization`; + const response = await fetch(url, { + headers: { + Authorization: `Bearer ${token}`, + }, + }); + + const json = await response.json(); + + if (!json) { + return null; + } + + if (json.error) { + return null; + } + + return json; + } catch (e) { + return null; + } +} + export const getViewerFromHeader = async (headers) => { try { const token = Cookies.get(headers, C.auth); diff --git a/pages/home.tsx b/pages/home.tsx index 904f9ed..b287b15 100644 --- a/pages/home.tsx +++ b/pages/home.tsx @@ -15,6 +15,7 @@ import PageHeader from '@components/PageHeader'; import { H2, P } from '@components/Typography'; import FilesTable from '@root/components/FilesTable'; +import AlertPanel from '@components/AlertPanel'; const INCREMENT = 1000; @@ -56,6 +57,7 @@ function HomePage(props: any) { const [state, setState] = React.useState({ files: null, stats: null, + threshold: null, offset: 0, limit: INCREMENT, }); @@ -64,9 +66,10 @@ function HomePage(props: any) { const run = async () => { const files = await R.get(`/content/contents?offset=${state.offset}&limit=${state.limit}`, props.api); const stats = await R.get('/user/stats', props.api); + const threshold = await R.get('/user/utilization', props.api); if (files && !files.error) { - setState({ ...state, files, stats }); + setState({ ...state, files, stats, threshold }); } }; @@ -107,6 +110,26 @@ function HomePage(props: any) { )} + { state.stats && state.threshold ? ( +
+ { state.stats.totalSize >= state.threshold.soft_limit_bytes && state.stats.totalSize < state.threshold.hard_limit_bytes ? ( + + You are currently at { U.formatNumber((state.stats.totalSize / state.threshold.hard_limit_bytes) * 100) }% of + storage utilization. Once your hard limit threshold is reached + ({ U.bytesToSize(state.threshold.hard_limit_bytes) }), you will no longer be able to upload files. Please get + in touch with the Estuary Team if you require additional storage. + + ) : null } + { state.stats.totalSize >= state.threshold.hard_limit_bytes ? ( + + You have reached your hard limit threshold { U.bytesToSize(state.threshold.hard_limit_bytes) }. Please get in touch + with the Estuary Team if you require additional storage. You can find us in the Filecoin slack under the + #ecosystem-dev channel. + + ) : null } +
+ ) : null } + {state.stats ? (
diff --git a/pages/settings.tsx b/pages/settings.tsx index 9390e27..4291af6 100644 --- a/pages/settings.tsx +++ b/pages/settings.tsx @@ -20,6 +20,7 @@ import Modal from '@components/Modal'; export async function getServerSideProps(context) { const viewer = await U.getViewerFromHeader(context.req.headers); + const threshold = await U.getUserStorageThreshold(context.req.headers) const wallet = await U.getAuthAddress(context.req.headers); const host = context.req.headers.host; const protocol = host.split(':')[0] === 'localhost' ? 'http' : 'https'; @@ -34,6 +35,7 @@ export async function getServerSideProps(context) { } viewer.wallet = wallet; + viewer.threshold = threshold; return { props: { host, protocol, viewer, api: process.env.NEXT_PUBLIC_ESTUARY_API, hostname: `https://${context.req.headers.host}` }, @@ -298,6 +300,14 @@ function SettingsPage(props: any) { + +

User soft limit threshold (%)

+ + +

User hard limit threshold

+ +