From 26a288c3de7a8e0cefb0e05875acd291cd76295a Mon Sep 17 00:00:00 2001 From: goodmice Date: Thu, 2 Jun 2022 14:45:28 +0500 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B4=D0=BE=D0=BF=20=D0=BF=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B5=D1=80=D0=BA=D0=B0=20=D0=BD=D0=B0=20=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B0=20=D0=B4=D0=BB=D1=8F=20dev=20=D0=B1=D0=B8=D0=BB?= =?UTF-8?q?=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/UploadForm.tsx | 8 +++++--- src/components/factory.ts | 5 +++-- src/services/signalr/index.ts | 6 ++++-- src/utils/index.ts | 2 ++ src/utils/permissions.ts | 3 ++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/components/UploadForm.tsx b/src/components/UploadForm.tsx index 12bfef4..f85992d 100644 --- a/src/components/UploadForm.tsx +++ b/src/components/UploadForm.tsx @@ -1,8 +1,10 @@ import { memo, useCallback, useEffect, useMemo, useState } from 'react' -import { Upload, Button } from 'antd' -import { UploadOutlined } from '@ant-design/icons' import { UploadFile } from 'antd/lib/upload/interface' +import { UploadOutlined } from '@ant-design/icons' import { RcFile } from 'antd/lib/upload' +import { Upload, Button } from 'antd' + +import { isDev } from '@utils' import { notify, upload } from './factory' import { ErrorFetch } from './ErrorFetch' @@ -53,7 +55,7 @@ export const UploadForm = memo(({ url, disabled, style, formDat onUploadSuccess?.() } } catch(error) { - if(process.env.NODE_ENV === 'development') + if(isDev()) console.error(error) onUploadError?.(error) } finally { diff --git a/src/components/factory.ts b/src/components/factory.ts index 635b2c2..3083ac4 100755 --- a/src/components/factory.ts +++ b/src/components/factory.ts @@ -1,8 +1,9 @@ import { notification } from 'antd' import { Dispatch, ReactNode, SetStateAction } from 'react' -import { ApiError, FileInfoDto } from '@api' +import { isDev } from '@utils' import { getUserToken } from '@utils/storage' +import { ApiError, FileInfoDto } from '@api' const notificationTypeDictionary = new Map([ ['error' , { notifyInstance: notification.error , caption: 'Ошибка' }], @@ -45,7 +46,7 @@ export const invokeWebApiWrapperAsync = async ( try{ await funcAsync() } catch (ex) { - if(process.env.NODE_ENV === 'development') + if(isDev()) console.error(ex) if (ex instanceof ApiError && ex.status === 403) { if (actionName) diff --git a/src/services/signalr/index.ts b/src/services/signalr/index.ts index b55982a..5afede2 100755 --- a/src/services/signalr/index.ts +++ b/src/services/signalr/index.ts @@ -1,6 +1,8 @@ -import { getUserToken } from '@asb/utils/storage' import { HubConnection, HubConnectionBuilder, HubConnectionState } from '@microsoft/signalr' +import { getUserToken } from '@utils/storage' +import { isDev } from '@utils' + // SignalR js api: //https://docs.microsoft.com/ru-ru/javascript/api/@aspnet/signalr/?view=signalr-js-latest @@ -12,7 +14,7 @@ const ConnectionOptions = { type ConnectionsDict = Record //var baseUrl = `http://192.168.1.70:5000` -const baseUrl = process.env.NODE_ENV === 'development' ? require('../../../package.json').proxy : '' +const baseUrl = isDev() ? require('../../../package.json').proxy : '' const Connections: ConnectionsDict = { 'hubs/telemetry': new HubConnectionBuilder() diff --git a/src/utils/index.ts b/src/utils/index.ts index 51732bc..4ef3299 100755 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -62,3 +62,5 @@ export const range = (end: number, start: number = 0) => Array.from({ length: en * @returns Общий тип с полным `T` и несовпадающими полями из `R` */ export type OmitExtends = T & Omit + +export const isDev = () => process.env.NODE_ENV === 'development' diff --git a/src/utils/permissions.ts b/src/utils/permissions.ts index 43444b6..dd7ad6e 100755 --- a/src/utils/permissions.ts +++ b/src/utils/permissions.ts @@ -1,3 +1,4 @@ +import { isDev } from '.' import { getUserLogin, getUserPermissions, getUserRoles } from './storage' export type Role = string @@ -17,7 +18,7 @@ export const getPermissions = (...values: PermissionRequest[]) => { const [service, type] = key.toLowerCase().split('.') if (!isRequestType(type)) return permissions[service] = permissions[service] ?? {} - permissions[service][type] = getUserLogin() === 'dev' || hasPermission(key) + permissions[service][type] = hasPermission(key) || (isDev() && getUserLogin() === 'dev') }) return permissions }