Skip to content

Commit

Permalink
fix(dcellar-web-ui): share file and offchainauth expired
Browse files Browse the repository at this point in the history
  • Loading branch information
devinxl committed Jul 31, 2023
1 parent 5c04a11 commit be5eefa
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 16 deletions.
14 changes: 9 additions & 5 deletions apps/dcellar-web-ui/src/facade/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ErrorMsgMap } from "@/context/WalletConnectContext/error/error";
import { ErrorMsgMap } from '@/context/WalletConnectContext/error/error';

export type ErrorMsg = string;

Expand Down Expand Up @@ -56,9 +56,14 @@ export const createTxFault = (e: any): ErrorResponse => {
console.error('CreateTxFault', e);
// todo refactor
if (
code === -1 &&
(e as any).statusCode === 500 &&
['Get create object approval error.', 'Get create bucket approval error.'].includes(message)
(code === -1 &&
(e as any).statusCode === 500 &&
[
'Get create object approval error.',
'Get create bucket approval error.',
'user public key is expired',
].includes(message)) ||
((e as any).statusCode === 400 && ['user public key is expired'].includes(message))
) {
return [null, E_OFF_CHAIN_AUTH];
}
Expand Down Expand Up @@ -96,4 +101,3 @@ export const commonFault = (e: any): ErrorResponse => {
}
return [null, E_UNKNOWN_ERROR];
};

Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ export const CreateBucket = ({ isOpen, onClose, refetch }: Props) => {
isLoading: false,
};
if (e?.message) {
if (e.message.includes('user public key is expired')) {
onClose();
setOpenAuthModal();
return;
}
if (e.message.includes('Bucket already exists') || e.message.includes('repeated bucket')) {
result['name'] = {
available: false,
Expand Down
25 changes: 14 additions & 11 deletions apps/dcellar-web-ui/src/modules/share/SharedFile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { setupBucketQuota } from '@/store/slices/bucket';
import { useOffChainAuth } from '@/hooks/useOffChainAuth';
import { getSpUrlByBucketName, getVirtualGroupFamily } from '@/facade/virtual-group';
import { SpItem } from '@/store/slices/sp';
import { VisibilityType } from '../file/type';

interface SharedFileProps {
fileName: string;
Expand All @@ -36,8 +37,7 @@ export const SharedFile = memo<SharedFileProps>(function SharedFile({
loginAccount,
}) {
const dispatch = useAppDispatch();
const { oneSp, spInfo, allSps } = useAppSelector((root) => root.sp);
const { bucketInfo } = useAppSelector((root) => root.bucket);
const { allSps } = useAppSelector((root) => root.sp);
const [action, setAction] = useState<ActionType>('');
const [statusModalIcon, setStatusModalIcon] = useState<string>('');
const [statusModalTitle, setStatusModalTitle] = useState('');
Expand Down Expand Up @@ -85,15 +85,18 @@ export const SharedFile = memo<SharedFileProps>(function SharedFile({
if (!primarySp) return onError(E_SP_NOT_FOUND);
const operator = primarySp.operatorAddress;
const { seedString } = await dispatch(getSpOffChainData(loginAccount, operator));
const [_, accessError] = await getCanObjectAccess(
bucketName,
objectName,
primarySpEndpoint,
loginAccount,
seedString,
);
const errType = accessError as ShareErrorType;
if (errType) return onError(errType);
const isPrivate = objectInfo.visibility === VisibilityType.VISIBILITY_TYPE_PRIVATE;
if (isPrivate) {
const [_, accessError] = await getCanObjectAccess(
bucketName,
objectName,
primarySpEndpoint,
loginAccount,
seedString,
);
const errType = accessError as ShareErrorType;
if (errType) return onError(errType);
}
const params = {
primarySp,
objectInfo,
Expand Down
8 changes: 8 additions & 0 deletions apps/dcellar-web-ui/src/pages/share/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { useAppDispatch, useAppSelector } from '@/store';
import { getSpOffChainData } from '@/store/slices/persist';
import { getSpUrlByBucketName, getVirtualGroupFamily } from '@/facade/virtual-group';
import { SpItem } from '@/store/slices/sp';
import { headObject } from '@/facade/object';

const Container = styled.main`
min-height: calc(100vh - 48px);
Expand Down Expand Up @@ -53,6 +54,13 @@ const SharePage: NextPage<InferGetServerSidePropsType<typeof getServerSideProps>
seedString,
address: loginAccount,
}
if (!loginAccount) {
const objectInfo = await headObject(bucketName, objectName);
setObjectInfo(objectInfo);
setQuotaData({} as IQuotaProps);
return;
}

const [objectInfo, quotaData] = await getObjectInfoAndBucketQuota(params);
setObjectInfo(objectInfo);
setQuotaData(quotaData);
Expand Down

0 comments on commit be5eefa

Please sign in to comment.