mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-07-02 03:02:19 +08:00
feat: support for server-sent events (#5418)
* feat: qr code uploader * fix: axios * fix: test error
This commit is contained in:
parent
b4270c7377
commit
156d99c724
@ -62,6 +62,9 @@ export default defineConfig({
|
|||||||
edge: 79,
|
edge: 79,
|
||||||
safari: 12,
|
safari: 12,
|
||||||
},
|
},
|
||||||
|
jsMinifierOptions: {
|
||||||
|
target: ['chrome80', 'es2020'],
|
||||||
|
},
|
||||||
codeSplitting: {
|
codeSplitting: {
|
||||||
jsStrategy: 'depPerChunk'
|
jsStrategy: 'depPerChunk'
|
||||||
},
|
},
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
"ahooks": "^3.7.2",
|
"ahooks": "^3.7.2",
|
||||||
"antd": "5.12.8",
|
"antd": "5.12.8",
|
||||||
"antd-style": "3.4.5",
|
"antd-style": "3.4.5",
|
||||||
"axios": "^0.26.1",
|
"axios": "^1.7.0",
|
||||||
"bignumber.js": "^9.1.2",
|
"bignumber.js": "^9.1.2",
|
||||||
"classnames": "^2.3.1",
|
"classnames": "^2.3.1",
|
||||||
"cronstrue": "^2.11.0",
|
"cronstrue": "^2.11.0",
|
||||||
|
@ -8,8 +8,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { IResource } from '@nocobase/sdk';
|
import { IResource } from '@nocobase/sdk';
|
||||||
import React, { FC, ReactNode, createContext, useContext, useMemo } from 'react';
|
|
||||||
import { isArray } from 'lodash';
|
import { isArray } from 'lodash';
|
||||||
|
import React, { FC, ReactNode, createContext, useContext, useMemo } from 'react';
|
||||||
import { useAPIClient } from '../../api-client';
|
import { useAPIClient } from '../../api-client';
|
||||||
import { useCollectionManager } from '../collection';
|
import { useCollectionManager } from '../collection';
|
||||||
import { CollectionRecord } from '../collection-record';
|
import { CollectionRecord } from '../collection-record';
|
||||||
|
@ -20,6 +20,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import LightBox from 'react-image-lightbox';
|
import LightBox from 'react-image-lightbox';
|
||||||
import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app
|
import 'react-image-lightbox/style.css'; // This only needs to be imported once in your app
|
||||||
import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps';
|
import { withDynamicSchemaProps } from '../../../hoc/withDynamicSchemaProps';
|
||||||
|
import { useComponent } from '../../hooks';
|
||||||
import { useProps } from '../../hooks/useProps';
|
import { useProps } from '../../hooks/useProps';
|
||||||
import {
|
import {
|
||||||
FILE_SIZE_LIMIT_DEFAULT,
|
FILE_SIZE_LIMIT_DEFAULT,
|
||||||
@ -401,6 +402,8 @@ export function Uploader({ rules, ...props }: UploadProps) {
|
|||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const QRCodeUploader = useComponent('QRCodeUploader');
|
||||||
|
|
||||||
const { mimetype: accept, size } = rules ?? {};
|
const { mimetype: accept, size } = rules ?? {};
|
||||||
const sizeHint = useSizeHint(size);
|
const sizeHint = useSizeHint(size);
|
||||||
const selectable =
|
const selectable =
|
||||||
@ -441,6 +444,16 @@ export function Uploader({ rules, ...props }: UploadProps) {
|
|||||||
</AntdUpload>
|
</AntdUpload>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
|
{selectable && QRCodeUploader && (
|
||||||
|
<QRCodeUploader
|
||||||
|
value={value}
|
||||||
|
onChange={(value) => {
|
||||||
|
// TODO
|
||||||
|
console.log(value);
|
||||||
|
// onChange(value);
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,7 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './Upload';
|
|
||||||
export { attachmentFileTypes } from './shared';
|
export { attachmentFileTypes } from './shared';
|
||||||
|
export { useUploadStyles } from './style';
|
||||||
|
|
||||||
|
export * from './Upload';
|
||||||
|
@ -113,3 +113,5 @@ export const useStyles = genStyleHook('upload', (token) => {
|
|||||||
},
|
},
|
||||||
} as any;
|
} as any;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const useUploadStyles = useStyles;
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"license": "AGPL-3.0",
|
"license": "AGPL-3.0",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@umijs/utils": "3.5.20",
|
"@umijs/utils": "3.5.20",
|
||||||
"axios": "^0.26.1",
|
"axios": "^1.7.0",
|
||||||
"chalk": "^4.1.1",
|
"chalk": "^4.1.1",
|
||||||
"commander": "^9.2.0",
|
"commander": "^9.2.0",
|
||||||
"tar": "6.1.11"
|
"tar": "6.1.11"
|
||||||
|
@ -53,6 +53,15 @@ function getUmiConfig() {
|
|||||||
target: PROXY_TARGET_URL,
|
target: PROXY_TARGET_URL,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
pathRewrite: { [`^${API_BASE_PATH}`]: API_BASE_PATH },
|
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
|
// for local storage
|
||||||
...getLocalStorageProxy(),
|
...getLocalStorageProxy(),
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"types": "lib/index.d.ts",
|
"types": "lib/index.d.ts",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.26.1",
|
"axios": "^1.7.0",
|
||||||
"qs": "^6.10.1"
|
"qs": "^6.10.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
* 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';
|
import qs from 'qs';
|
||||||
|
|
||||||
export interface ActionParams {
|
export interface ActionParams {
|
||||||
@ -347,7 +347,7 @@ export class APIClient {
|
|||||||
return this.axios.request<T, R, D>(config);
|
return this.axios.request<T, R, D>(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
resource(name: string, of?: any, headers?: AxiosRequestHeaders, cancel?: boolean): IResource {
|
resource(name: string, of?: any, headers?: RawAxiosRequestHeaders, cancel?: boolean): IResource {
|
||||||
const target = {};
|
const target = {};
|
||||||
const handler = {
|
const handler = {
|
||||||
get: (_: any, actionName: string) => {
|
get: (_: any, actionName: string) => {
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
"@types/ini": "^1.3.31",
|
"@types/ini": "^1.3.31",
|
||||||
"@types/koa-send": "^4.1.3",
|
"@types/koa-send": "^4.1.3",
|
||||||
"@types/multer": "^1.4.5",
|
"@types/multer": "^1.4.5",
|
||||||
"axios": "^0.26.1",
|
"axios": "^1.7.0",
|
||||||
"chalk": "^4.1.1",
|
"chalk": "^4.1.1",
|
||||||
"commander": "^9.2.0",
|
"commander": "^9.2.0",
|
||||||
"cron": "^2.4.4",
|
"cron": "^2.4.4",
|
||||||
|
@ -15,7 +15,7 @@ import bodyParser from 'koa-bodyparser';
|
|||||||
import Database from '@nocobase/database';
|
import Database from '@nocobase/database';
|
||||||
import { MockServer } from '@nocobase/test';
|
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 { getApp, sleep } from '@nocobase/plugin-workflow-test';
|
||||||
|
|
||||||
import { RequestConfig } from '../MailerInstruction';
|
import { RequestConfig } from '../MailerInstruction';
|
||||||
@ -206,8 +206,8 @@ describe('workflow > instructions > request', () => {
|
|||||||
|
|
||||||
expect(job.result).toMatchObject({
|
expect(job.result).toMatchObject({
|
||||||
code: 'ECONNABORTED',
|
code: 'ECONNABORTED',
|
||||||
name: 'Error',
|
name: 'AxiosError',
|
||||||
status: null,
|
// status: null,
|
||||||
message: 'timeout of 250ms exceeded',
|
message: 'timeout of 250ms exceeded',
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -235,8 +235,8 @@ describe('workflow > instructions > request', () => {
|
|||||||
expect(job.status).toBe(JOB_STATUS.RESOLVED);
|
expect(job.status).toBe(JOB_STATUS.RESOLVED);
|
||||||
expect(job.result).toMatchObject({
|
expect(job.result).toMatchObject({
|
||||||
code: 'ECONNABORTED',
|
code: 'ECONNABORTED',
|
||||||
name: 'Error',
|
name: 'AxiosError',
|
||||||
status: null,
|
// status: null,
|
||||||
message: 'timeout of 250ms exceeded',
|
message: 'timeout of 250ms exceeded',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -319,7 +319,7 @@ describe('workflow > instructions > request', () => {
|
|||||||
expect(job.result).toMatchObject({
|
expect(job.result).toMatchObject({
|
||||||
code: 'ECONNRESET',
|
code: 'ECONNRESET',
|
||||||
name: 'Error',
|
name: 'Error',
|
||||||
status: null,
|
// status: null,
|
||||||
message: 'socket hang up',
|
message: 'socket hang up',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/workflow-request",
|
"homepage.zh-CN": "https://docs-cn.nocobase.com/handbook/workflow-request",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"antd": "5.x",
|
"antd": "5.x",
|
||||||
"axios": "^0.26.1",
|
"axios": "^1.7.0",
|
||||||
"react": "18.x",
|
"react": "18.x",
|
||||||
"react-i18next": "^11.15.1"
|
"react-i18next": "^11.15.1"
|
||||||
},
|
},
|
||||||
|
@ -8,15 +8,15 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Server } from 'http';
|
import { Server } from 'http';
|
||||||
import type { AddressInfo } from 'net';
|
|
||||||
import jwt from 'jsonwebtoken';
|
import jwt from 'jsonwebtoken';
|
||||||
import Koa from 'koa';
|
import Koa from 'koa';
|
||||||
import bodyParser from 'koa-bodyparser';
|
import bodyParser from 'koa-bodyparser';
|
||||||
|
import type { AddressInfo } from 'net';
|
||||||
|
|
||||||
import Database from '@nocobase/database';
|
import Database from '@nocobase/database';
|
||||||
import { MockServer } from '@nocobase/test';
|
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 { getApp, sleep } from '@nocobase/plugin-workflow-test';
|
||||||
|
|
||||||
import { RequestConfig } from '../RequestInstruction';
|
import { RequestConfig } from '../RequestInstruction';
|
||||||
@ -227,8 +227,8 @@ describe('workflow > instructions > request', () => {
|
|||||||
|
|
||||||
expect(job.result).toMatchObject({
|
expect(job.result).toMatchObject({
|
||||||
code: 'ECONNABORTED',
|
code: 'ECONNABORTED',
|
||||||
name: 'Error',
|
name: 'AxiosError',
|
||||||
status: null,
|
// status: null,
|
||||||
message: 'timeout of 250ms exceeded',
|
message: 'timeout of 250ms exceeded',
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -256,8 +256,8 @@ describe('workflow > instructions > request', () => {
|
|||||||
expect(job.status).toBe(JOB_STATUS.RESOLVED);
|
expect(job.status).toBe(JOB_STATUS.RESOLVED);
|
||||||
expect(job.result).toMatchObject({
|
expect(job.result).toMatchObject({
|
||||||
code: 'ECONNABORTED',
|
code: 'ECONNABORTED',
|
||||||
name: 'Error',
|
name: 'AxiosError',
|
||||||
status: null,
|
// status: null,
|
||||||
message: 'timeout of 250ms exceeded',
|
message: 'timeout of 250ms exceeded',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -340,7 +340,7 @@ describe('workflow > instructions > request', () => {
|
|||||||
expect(job.result).toMatchObject({
|
expect(job.result).toMatchObject({
|
||||||
code: 'ECONNRESET',
|
code: 'ECONNRESET',
|
||||||
name: 'Error',
|
name: 'Error',
|
||||||
status: null,
|
// status: null,
|
||||||
message: 'socket hang up',
|
message: 'socket hang up',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user