From 156d99c7247651a46eb4b093068a20b4321f865e Mon Sep 17 00:00:00 2001 From: chenos Date: Tue, 15 Oct 2024 16:16:58 +0800 Subject: [PATCH] feat: support for server-sent events (#5418) * feat: qr code uploader * fix: axios * fix: test error --- packages/core/app/client/.umirc.ts | 3 +++ packages/core/client/package.json | 2 +- .../data-block/DataBlockResourceProvider.tsx | 2 +- .../src/schema-component/antd/upload/Upload.tsx | 13 +++++++++++++ .../src/schema-component/antd/upload/index.ts | 4 +++- .../src/schema-component/antd/upload/style.ts | 2 ++ packages/core/create-nocobase-app/package.json | 2 +- packages/core/devtools/umiConfig.js | 9 +++++++++ packages/core/sdk/package.json | 2 +- packages/core/sdk/src/APIClient.ts | 4 ++-- packages/core/server/package.json | 2 +- .../src/server/__tests__/instruction.test.ts | 12 ++++++------ .../@nocobase/plugin-workflow-request/package.json | 2 +- .../src/server/__tests__/instruction.test.ts | 14 +++++++------- 14 files changed, 51 insertions(+), 22 deletions(-) diff --git a/packages/core/app/client/.umirc.ts b/packages/core/app/client/.umirc.ts index e07063548..084f591a9 100644 --- a/packages/core/app/client/.umirc.ts +++ b/packages/core/app/client/.umirc.ts @@ -62,6 +62,9 @@ export default defineConfig({ edge: 79, safari: 12, }, + jsMinifierOptions: { + target: ['chrome80', 'es2020'], + }, codeSplitting: { jsStrategy: 'depPerChunk' }, diff --git a/packages/core/client/package.json b/packages/core/client/package.json index 82f58fc9c..145f37233 100644 --- a/packages/core/client/package.json +++ b/packages/core/client/package.json @@ -33,7 +33,7 @@ "ahooks": "^3.7.2", "antd": "5.12.8", "antd-style": "3.4.5", - "axios": "^0.26.1", + "axios": "^1.7.0", "bignumber.js": "^9.1.2", "classnames": "^2.3.1", "cronstrue": "^2.11.0", diff --git a/packages/core/client/src/data-source/data-block/DataBlockResourceProvider.tsx b/packages/core/client/src/data-source/data-block/DataBlockResourceProvider.tsx index 9bb4d8df0..2f1588c47 100644 --- a/packages/core/client/src/data-source/data-block/DataBlockResourceProvider.tsx +++ b/packages/core/client/src/data-source/data-block/DataBlockResourceProvider.tsx @@ -8,8 +8,8 @@ */ import { IResource } from '@nocobase/sdk'; -import React, { FC, ReactNode, createContext, useContext, useMemo } from 'react'; import { isArray } from 'lodash'; +import React, { FC, ReactNode, createContext, useContext, useMemo } from 'react'; import { useAPIClient } from '../../api-client'; import { useCollectionManager } from '../collection'; import { CollectionRecord } from '../collection-record'; diff --git a/packages/core/client/src/schema-component/antd/upload/Upload.tsx b/packages/core/client/src/schema-component/antd/upload/Upload.tsx index b6efb3836..44f989fa6 100644 --- a/packages/core/client/src/schema-component/antd/upload/Upload.tsx +++ b/packages/core/client/src/schema-component/antd/upload/Upload.tsx @@ -20,6 +20,7 @@ import { useTranslation } from 'react-i18next'; import LightBox from 'react-image-lightbox'; import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps'; +import { useComponent } from '../../hooks'; import { useProps } from '../../hooks/useProps'; import { FILE_SIZE_LIMIT_DEFAULT, @@ -401,6 +402,8 @@ export function Uploader({ rules, ...props }: UploadProps) { }); }, []); + const QRCodeUploader = useComponent('QRCodeUploader'); + const { mimetype: accept, size } = rules ?? {}; const sizeHint = useSizeHint(size); const selectable = @@ -441,6 +444,16 @@ export function Uploader({ rules, ...props }: UploadProps) { + {selectable && QRCodeUploader && ( + { + // TODO + console.log(value); + // onChange(value); + }} + /> + )} ); } diff --git a/packages/core/client/src/schema-component/antd/upload/index.ts b/packages/core/client/src/schema-component/antd/upload/index.ts index ea7cfbdec..cd0ff5dd7 100644 --- a/packages/core/client/src/schema-component/antd/upload/index.ts +++ b/packages/core/client/src/schema-component/antd/upload/index.ts @@ -7,5 +7,7 @@ * For more information, please refer to: https://www.nocobase.com/agreement. */ -export * from './Upload'; export { attachmentFileTypes } from './shared'; +export { useUploadStyles } from './style'; + +export * from './Upload'; diff --git a/packages/core/client/src/schema-component/antd/upload/style.ts b/packages/core/client/src/schema-component/antd/upload/style.ts index 7180109f4..d413dfcc6 100644 --- a/packages/core/client/src/schema-component/antd/upload/style.ts +++ b/packages/core/client/src/schema-component/antd/upload/style.ts @@ -113,3 +113,5 @@ export const useStyles = genStyleHook('upload', (token) => { }, } as any; }); + +export const useUploadStyles = useStyles; diff --git a/packages/core/create-nocobase-app/package.json b/packages/core/create-nocobase-app/package.json index d03857854..b26236b5f 100755 --- a/packages/core/create-nocobase-app/package.json +++ b/packages/core/create-nocobase-app/package.json @@ -5,7 +5,7 @@ "license": "AGPL-3.0", "dependencies": { "@umijs/utils": "3.5.20", - "axios": "^0.26.1", + "axios": "^1.7.0", "chalk": "^4.1.1", "commander": "^9.2.0", "tar": "6.1.11" diff --git a/packages/core/devtools/umiConfig.js b/packages/core/devtools/umiConfig.js index ff56d142f..bdccac8e8 100644 --- a/packages/core/devtools/umiConfig.js +++ b/packages/core/devtools/umiConfig.js @@ -53,6 +53,15 @@ function getUmiConfig() { target: PROXY_TARGET_URL, changeOrigin: true, pathRewrite: { [`^${API_BASE_PATH}`]: API_BASE_PATH }, + onProxyRes(proxyRes, req, res) { + if (req.headers.accept === 'text/event-stream') { + res.writeHead(res.statusCode, { + 'Content-Type': 'text/event-stream', + 'Cache-Control': 'no-transform', + Connection: 'keep-alive', + }); + } + }, }, // for local storage ...getLocalStorageProxy(), diff --git a/packages/core/sdk/package.json b/packages/core/sdk/package.json index e88a5c0f8..12b15d8ff 100644 --- a/packages/core/sdk/package.json +++ b/packages/core/sdk/package.json @@ -5,7 +5,7 @@ "main": "lib/index.js", "types": "lib/index.d.ts", "dependencies": { - "axios": "^0.26.1", + "axios": "^1.7.0", "qs": "^6.10.1" }, "devDependencies": { diff --git a/packages/core/sdk/src/APIClient.ts b/packages/core/sdk/src/APIClient.ts index 1b0bbcc0e..e89877078 100644 --- a/packages/core/sdk/src/APIClient.ts +++ b/packages/core/sdk/src/APIClient.ts @@ -7,7 +7,7 @@ * For more information, please refer to: https://www.nocobase.com/agreement. */ -import axios, { AxiosInstance, AxiosRequestConfig, AxiosRequestHeaders, AxiosResponse } from 'axios'; +import axios, { AxiosInstance, AxiosRequestConfig, AxiosResponse, RawAxiosRequestHeaders } from 'axios'; import qs from 'qs'; export interface ActionParams { @@ -347,7 +347,7 @@ export class APIClient { return this.axios.request(config); } - resource(name: string, of?: any, headers?: AxiosRequestHeaders, cancel?: boolean): IResource { + resource(name: string, of?: any, headers?: RawAxiosRequestHeaders, cancel?: boolean): IResource { const target = {}; const handler = { get: (_: any, actionName: string) => { diff --git a/packages/core/server/package.json b/packages/core/server/package.json index 97e5c3519..081d0a202 100644 --- a/packages/core/server/package.json +++ b/packages/core/server/package.json @@ -26,7 +26,7 @@ "@types/ini": "^1.3.31", "@types/koa-send": "^4.1.3", "@types/multer": "^1.4.5", - "axios": "^0.26.1", + "axios": "^1.7.0", "chalk": "^4.1.1", "commander": "^9.2.0", "cron": "^2.4.4", diff --git a/packages/plugins/@nocobase/plugin-workflow-mailer/src/server/__tests__/instruction.test.ts b/packages/plugins/@nocobase/plugin-workflow-mailer/src/server/__tests__/instruction.test.ts index e5c8b883e..7d8e36dd9 100644 --- a/packages/plugins/@nocobase/plugin-workflow-mailer/src/server/__tests__/instruction.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-mailer/src/server/__tests__/instruction.test.ts @@ -15,7 +15,7 @@ import bodyParser from 'koa-bodyparser'; import Database from '@nocobase/database'; import { MockServer } from '@nocobase/test'; -import PluginWorkflow, { Processor, EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow'; +import PluginWorkflow, { EXECUTION_STATUS, JOB_STATUS, Processor } from '@nocobase/plugin-workflow'; import { getApp, sleep } from '@nocobase/plugin-workflow-test'; import { RequestConfig } from '../MailerInstruction'; @@ -206,8 +206,8 @@ describe('workflow > instructions > request', () => { expect(job.result).toMatchObject({ code: 'ECONNABORTED', - name: 'Error', - status: null, + name: 'AxiosError', + // status: null, message: 'timeout of 250ms exceeded', }); @@ -235,8 +235,8 @@ describe('workflow > instructions > request', () => { expect(job.status).toBe(JOB_STATUS.RESOLVED); expect(job.result).toMatchObject({ code: 'ECONNABORTED', - name: 'Error', - status: null, + name: 'AxiosError', + // status: null, message: 'timeout of 250ms exceeded', }); }); @@ -319,7 +319,7 @@ describe('workflow > instructions > request', () => { expect(job.result).toMatchObject({ code: 'ECONNRESET', name: 'Error', - status: null, + // status: null, message: 'socket hang up', }); }); diff --git a/packages/plugins/@nocobase/plugin-workflow-request/package.json b/packages/plugins/@nocobase/plugin-workflow-request/package.json index f864fb063..b809d0b37 100644 --- a/packages/plugins/@nocobase/plugin-workflow-request/package.json +++ b/packages/plugins/@nocobase/plugin-workflow-request/package.json @@ -11,7 +11,7 @@ "homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/workflow-request", "devDependencies": { "antd": "5.x", - "axios": "^0.26.1", + "axios": "^1.7.0", "react": "18.x", "react-i18next": "^11.15.1" }, diff --git a/packages/plugins/@nocobase/plugin-workflow-request/src/server/__tests__/instruction.test.ts b/packages/plugins/@nocobase/plugin-workflow-request/src/server/__tests__/instruction.test.ts index 4a8540f71..2cc00be40 100644 --- a/packages/plugins/@nocobase/plugin-workflow-request/src/server/__tests__/instruction.test.ts +++ b/packages/plugins/@nocobase/plugin-workflow-request/src/server/__tests__/instruction.test.ts @@ -8,15 +8,15 @@ */ import { Server } from 'http'; -import type { AddressInfo } from 'net'; import jwt from 'jsonwebtoken'; import Koa from 'koa'; import bodyParser from 'koa-bodyparser'; +import type { AddressInfo } from 'net'; import Database from '@nocobase/database'; import { MockServer } from '@nocobase/test'; -import PluginWorkflow, { Processor, EXECUTION_STATUS, JOB_STATUS } from '@nocobase/plugin-workflow'; +import PluginWorkflow, { EXECUTION_STATUS, JOB_STATUS, Processor } from '@nocobase/plugin-workflow'; import { getApp, sleep } from '@nocobase/plugin-workflow-test'; import { RequestConfig } from '../RequestInstruction'; @@ -227,8 +227,8 @@ describe('workflow > instructions > request', () => { expect(job.result).toMatchObject({ code: 'ECONNABORTED', - name: 'Error', - status: null, + name: 'AxiosError', + // status: null, message: 'timeout of 250ms exceeded', }); @@ -256,8 +256,8 @@ describe('workflow > instructions > request', () => { expect(job.status).toBe(JOB_STATUS.RESOLVED); expect(job.result).toMatchObject({ code: 'ECONNABORTED', - name: 'Error', - status: null, + name: 'AxiosError', + // status: null, message: 'timeout of 250ms exceeded', }); }); @@ -340,7 +340,7 @@ describe('workflow > instructions > request', () => { expect(job.result).toMatchObject({ code: 'ECONNRESET', name: 'Error', - status: null, + // status: null, message: 'socket hang up', }); });