Skip to content

Commit

Permalink
fix(dcellar-web-ui): create folder error
Browse files Browse the repository at this point in the history
  • Loading branch information
devinxl committed Apr 9, 2024
1 parent db559be commit 73ed553
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 24 deletions.
2 changes: 1 addition & 1 deletion apps/dcellar-web-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"antd": "5.11.0",
"ahooks": "3.7.7",
"hash-wasm": "4.10.0",
"@bnb-chain/greenfield-js-sdk": "2.0.0-alpha.5",
"@bnb-chain/greenfield-js-sdk": "2.0.0-alpha.6",
"@bnb-chain/greenfield-cosmos-types": "0.4.0-alpha.31",
"@emotion/react": "^11.10.5",
"@emotion/styled": "^11.10.5",
Expand Down
8 changes: 8 additions & 0 deletions apps/dcellar-web-ui/src/facade/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ import { TempAccountEntity } from '@/store/slices/accounts';

export const resolve = <R>(r: R): [R, null] => [r, null];

export const resolveSpRequest = <R>(r: SpResponse<R>) => {
console.log('r', r);
if (r.code !== 0) {
return [null, r.message || UNKNOWN_ERROR];
}
return [r.body, null];
};

export type DeliverTxResponse = Awaited<ReturnType<TxResponse['broadcast']>>;

export const getObjectInfoAndBucketQuota = async ({
Expand Down
4 changes: 2 additions & 2 deletions apps/dcellar-web-ui/src/facade/object.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { GROUP_ID } from '@/constants/legacy';
import { quotaRemains } from '@/facade/bucket';
import { getObjectInfoAndBucketQuota, resolve } from '@/facade/common';
import { getObjectInfoAndBucketQuota, resolve, resolveSpRequest } from '@/facade/common';
import {
E_NOT_FOUND,
E_NO_QUOTA,
Expand Down Expand Up @@ -692,5 +692,5 @@ export const delegateCreateFolder = async (
) => {
const client = await getClient();

return client.object.delegateCreateFolder(request, auth).then(resolve, commonFault);
return client.object.delegateCreateFolder(request, auth).then(resolveSpRequest, commonFault);
};
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ export const CreateFolderOperation = memo<CreateFolderOperationProps>(function C
if (error1) {
setLoading(false);
dispatch(setSignatureAction({}));
return setFormErrors([error1 || UNKNOWN_ERROR]);
return setFormErrors([error1]);
} else {
onClose();
setLoading(false);
Expand Down
4 changes: 2 additions & 2 deletions apps/dcellar-web-ui/src/pages/api/bill_monthly/[[...slug]].ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ALLOWED_DOMAINS, BILLING_API_URL } from '@/base/env';
import { validateReferer } from '@/utils/req';
import { isRefererAllowed } from '@/utils/req';
import axios from 'axios';
import { NextApiRequest, NextApiResponse } from 'next';
import qs from 'query-string';

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (!validateReferer(req.headers.referer || '', ALLOWED_DOMAINS)) {
if (!isRefererAllowed(req.headers.referer || '', ALLOWED_DOMAINS)) {
res.status(403).json({ message: 'Forbidden' });
}
const { slug, ...query } = req.query;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ALLOWED_DOMAINS, BILLING_API_URL } from '@/base/env';
import { validateReferer } from '@/utils/req';
import { isRefererAllowed } from '@/utils/req';
import axios from 'axios';
import { NextApiRequest, NextApiResponse } from 'next';
import qs from 'query-string';

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (!validateReferer(req.headers.referer || '', ALLOWED_DOMAINS)) {
if (!isRefererAllowed(req.headers.referer || '', ALLOWED_DOMAINS)) {
res.status(403).json({ message: 'Forbidden' });
}
const { slug, ...query } = req.query;
Expand Down
4 changes: 2 additions & 2 deletions apps/dcellar-web-ui/src/pages/api/chart/[[...slug]].ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import axios from 'axios';
import qs from 'query-string';
import { NextApiRequest, NextApiResponse } from 'next';
import { ALLOWED_DOMAINS, EXPLORER_API_URL } from '@/base/env';
import { validateReferer } from '@/utils/req';
import { isRefererAllowed } from '@/utils/req';

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (!validateReferer(req.headers.referer || '', ALLOWED_DOMAINS)) {
if (!isRefererAllowed(req.headers.referer || '', ALLOWED_DOMAINS)) {
res.status(403).json({ message: 'Forbidden' });
}
const { slug, ...query } = req.query;
Expand Down
4 changes: 2 additions & 2 deletions apps/dcellar-web-ui/src/pages/api/policies/[[...slug]].ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ALLOWED_DOMAINS, EXPLORER_API_URL } from '@/base/env';
import { validateReferer } from '@/utils/req';
import { isRefererAllowed } from '@/utils/req';
import axios from 'axios';
import { NextApiRequest, NextApiResponse } from 'next';

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (!validateReferer(req.headers.referer || '', ALLOWED_DOMAINS)) {
if (!isRefererAllowed(req.headers.referer || '', ALLOWED_DOMAINS)) {
res.status(403).json({ message: 'Forbidden' });
}
const { slug } = req.query;
Expand Down
4 changes: 2 additions & 2 deletions apps/dcellar-web-ui/src/pages/api/total_cost/[[...slug]].ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ALLOWED_DOMAINS, BILLING_API_URL } from '@/base/env';
import { validateReferer } from '@/utils/req';
import { isRefererAllowed } from '@/utils/req';
import axios from 'axios';
import { NextApiRequest, NextApiResponse } from 'next';

const handler = async (req: NextApiRequest, res: NextApiResponse) => {
if (!validateReferer(req.headers.referer || '', ALLOWED_DOMAINS)) {
if (!isRefererAllowed(req.headers.referer || '', ALLOWED_DOMAINS)) {
res.status(403).json({ message: 'Forbidden' });
}
const { slug } = req.query;
Expand Down
16 changes: 10 additions & 6 deletions apps/dcellar-web-ui/src/utils/req.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
const localhostDomains = ['localhost', '127.0.0.1', '::1'];
const validLocalhostDomains: readonly string[] = ['localhost', '127.0.0.1', '::1'];

export function validateReferer(referrer: string, allowedDomains: string) {
if (!referrer) {
export function isRefererAllowed(referrerURL: string, allowedDomainList: string): boolean {
if (!referrerURL) {
return false;
}
const domain = new URL(referrer).hostname;
const domains = allowedDomains.split(',').concat(localhostDomains);

return domains.includes(domain);
const domain = new URL(referrerURL).hostname;
const domains = allowedDomainList
.split(',')
.map((domain) => domain.trim())
.concat(validLocalhostDomains);

return domains.some((allowedDomain) => domain.endsWith(allowedDomain));
}
8 changes: 4 additions & 4 deletions common/config/rush/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 73ed553

Please sign in to comment.