Skip to content

Commit

Permalink
fix(dcellar-web-ui): fix remaining quota error
Browse files Browse the repository at this point in the history
  • Loading branch information
devinxl committed Dec 26, 2024
1 parent 2d53b8e commit 579b3cd
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/dcellar-web-ui/src/facade/bucket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@ export const getObjectPolicies = async (
// todo using temp data
export const getFolderPolicies = async (bucketId: string) => {
const { data } = await axios.get<{ result: any[] }>(`/api/policies/${bucketId}`);
if (!data.result) return [];

return data.result
.filter((i) => !i.Removed)
.map((d) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/dcellar-web-ui/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function middleware(request: NextRequest) {
img-src 'self' blob: data: https: https://www.google-analytics.com https://www.googletagmanager.com;
font-src 'self' https://fonts.gstatic.com;
connect-src *;
object-src 'none';
object-src 'self' data;
base-uri 'self';
form-action 'self';
frame-ancestors 'none';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { Checkbox, Flex, ModalBody, ModalFooter, ModalHeader, Text } from '@node
import { memo, useEffect, useState } from 'react';
import { OBJECT_ERROR_TYPES, ObjectErrorType } from '../ObjectError';
import { setSignatureAction } from '@/store/slices/global';
import { getRemainingQuota } from '@/modules/object/utils/getRemainingQuota';

const renderProp = (key: string, value: string) => {
return (
Expand Down Expand Up @@ -68,8 +69,9 @@ export const DownloadObjectOperation = memo<DownloadObjectOperationProps>(functi
dispatch(setSignatureAction(errorData));
};

const remainingQuota = +quotaData?.readQuota + +quotaData?.freeQuota - +quotaData?.consumedQuota;
const transformedRemainingQuota = remainingQuota ? formatBytes(remainingQuota, true) : '--';
const remainingQuota = getRemainingQuota(quotaData);

const transformedRemainingQuota = remainingQuota ? formatBytes(remainingQuota) : '--';

const onAction = async () => {
setLoading(true);
Expand Down
11 changes: 11 additions & 0 deletions apps/dcellar-web-ui/src/modules/object/utils/getRemainingQuota.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { IQuotaProps } from '@bnb-chain/greenfield-js-sdk';

export const getRemainingQuota = (quotaData: IQuotaProps) => {
if (!quotaData) return 0;
const { readQuota, freeQuota, consumedQuota, monthlyFreeQuota, monthlyQuotaConsumedSize } =
quotaData;
const remainingQuota =
freeQuota + readQuota + monthlyFreeQuota - consumedQuota - monthlyQuotaConsumedSize;

return remainingQuota;
};
1 change: 1 addition & 0 deletions apps/dcellar-web-ui/src/utils/string.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export const formatQuota = (quota: IQuotaProps, removeSpace = true) => {
oneTimeFreeConsumedSize: freeConsumedSize,
oneTimeFreeRemain: freeQuota,
};
console.log('value', value.remain);

const f = (v: number, _removeSpace = removeSpace) => {
if (!quota) return '--';
Expand Down

0 comments on commit 579b3cd

Please sign in to comment.