Skip to content

Commit

Permalink
Merge branch 'cloud/202312' into dev-4.2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
HSunboy committed Jan 17, 2024
2 parents 0ffd801 + d2108f2 commit 07a8c81
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 22 deletions.
14 changes: 5 additions & 9 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,22 @@ import { setLocale } from '@umijs/max';
import { initMetaStore } from './common/metaStore';
import DndHTML5Provider from './component/DndHTML5Provider';
import registerPlugins from './plugins/register';
import { haveOCP, isClient } from './util/env';
import { isClient } from './util/env';
import logger from './util/logger';
import { getRoute } from './util/tracert/userRoutes';
import { initIntl } from './util/intl';
import * as Sentry from "@sentry/react";
import { initSentry } from './util/sentry';
if (isClient()) {
import('@sentry/electron').then((_Sentry) => {
_Sentry.init({
dsn: 'https://[email protected]/3',
});
});
} else if (haveOCP()) {
Sentry.init({
dsn: "https://[email protected]/6"
});
} else {
initSentry()
}





// TODO: 非云上场景不应该 export qiankun
export const qiankun = {
// 应用加载之前
Expand All @@ -65,6 +60,7 @@ export const qiankun = {
};

export async function render(oldRender: () => void) {

await initIntl();
registerPlugins();
await initMetaStore();
Expand Down
2 changes: 2 additions & 0 deletions src/component/ErrorBoundary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import { formatMessage } from '@/util/intl';
import { getSentry } from '@/util/sentry';
import { Button, Result } from 'antd';
import React from 'react';
export default class ErrorBoundary extends React.Component {
Expand All @@ -39,6 +40,7 @@ export default class ErrorBoundary extends React.Component {
public componentDidCatch(error: any, errorInfo) {
// You can also log the error to an error reporting service
console.log('error', error?.stack, errorInfo);
getSentry()?.captureException(error);
this.setState({
hasError: true,
errorComponent: errorInfo?.componentStack,
Expand Down
2 changes: 1 addition & 1 deletion src/component/OSSDragger/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ODCDragger: React.FC<IProps> = function (props) {
delete props.action;
// @ts-ignore
props.customRequest = async ({ file, onSuccess, onError, onProgress }) => {
const fileName = await uploadFileToOSS(file, props.uploadFileOpenAPIName, null);
const fileName = await uploadFileToOSS(file, props.uploadFileOpenAPIName, null, onProgress);
setTimeout(() => {
onSuccess(
{
Expand Down
2 changes: 1 addition & 1 deletion src/component/OSSDragger2/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ const ODCDragger: React.FC<IProps> = React.memo((props) => {

try {
if (setting.isUploadCloudStore) {
const fileName = await uploadFileToOSS(task.file, task.uploadFileOpenAPIName, sessionId);
const fileName = await uploadFileToOSS(task.file, task.uploadFileOpenAPIName, sessionId, task.onProgress);
task.onSuccess(
{
data: fileName,
Expand Down
21 changes: 15 additions & 6 deletions src/page/Gateway/newCloudConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import {
createConnection,
getConnectionDetail,
getConnectionList,
testExsitConnection,
updateConnectionFromConnection,
Expand Down Expand Up @@ -222,12 +223,20 @@ export const action = async (config: INewCloudConnection) => {
if (!pass) {
return 'Connect Failed';
}
if (isExist) {
await updateConnectionFromConnection({
...targetConnection,
passwordSaved: true,
password: password,
});
if (isExist && isPasswordError) {
/**
* replace password
*/
const connectionDetail = await getConnectionDetail(targetConnection?.id);
if (connectionDetail) {
await updateConnectionFromConnection({
...connectionDetail,
passwordSaved: true,
password: password,
});
} else {
return 'Update Connection Failed';
}
}
gotoSQLWorkspace(
null,
Expand Down
47 changes: 42 additions & 5 deletions src/util/aliyun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@

import { generateDatabaseSid } from '@/common/network/pathUtil';
import request from './request';
import logger from './logger';

// 上传文件到 OSS
// @see https://help.aliyun.com/document_detail/64047.html
export async function uploadFileToOSS(file, uploadFileOpenAPIName, sessionId) {
export async function uploadFileToOSS(file, uploadFileOpenAPIName, sessionId, onProgress?: (e: any) => void) {
// 1. 获取文档上传坐标
const uploadMeta = await request.post('/api/v2/cloud/resource/generateTempCredential', {
data: {
Expand All @@ -40,6 +41,7 @@ export async function uploadFileToOSS(file, uploadFileOpenAPIName, sessionId) {
} = uploadMeta.data;
// 3. 上传文件
const S3 = await import('aws-sdk/clients/s3').then((module) => module.default);
let beginTime, uploadTime, pullTime;
const s3 = new S3({
credentials: {
secretAccessKey: accessKeySecret,
Expand All @@ -53,7 +55,8 @@ export async function uploadFileToOSS(file, uploadFileOpenAPIName, sessionId) {
},
});
const isSuccess = await new Promise((resolve) => {
s3.putObject(
beginTime = Date.now();
const req = s3.putObject(
{
Bucket: bucketName,
Body: file,
Expand All @@ -68,24 +71,58 @@ export async function uploadFileToOSS(file, uploadFileOpenAPIName, sessionId) {
}
},
);
// 获取进度
req.on('httpUploadProgress', (e) => {
const newP = {...e, percent: 0};
if (e.total > 0) {
/**
* 后续还需要后端去pull资源,空出10%当作pull时间
*/
newP.percent = (e.loaded / e.total) * 100 * 0.9;
}
onProgress?.(newP)
})
});
uploadTime = Date.now();
if (!isSuccess) {
return null;
}
if (!uploadFileOpenAPIName) {
return filePath;
}
// 3. 报告记录
const resUpload = await request.post('/api/v2/aliyun/specific/' + uploadFileOpenAPIName, {
const resUpload = await request.post('/api/v2/aliyun/specific/asyncUpload', {
data: {
bucketName,
objectName: filePath,
region,
sid: generateDatabaseSid(null, sessionId),
type: uploadFileOpenAPIName
},
});
const fileName = resUpload.data;
return fileName;
const uploadId = resUpload.data;
if (!uploadId) {
return null;
}
async function getResult() {
const result = await request.get("/api/v2/aliyun/specific/getUploadResult/" + uploadId);
if (result?.isError) {
pullTime = Date.now();
logger.info('upload:', (uploadTime - beginTime)/1000, 'pull:', (pullTime - uploadTime)/1000)
return null;
} else if (result?.data) {
pullTime = Date.now();
logger.info('upload:', (uploadTime - beginTime)/1000, 'pull:', (pullTime - uploadTime)/1000)
return result?.data;
} else {
return await new Promise((resolve) => {
setTimeout(() => {
resolve(true)
}, 3000);
}).then(() => getResult())
}
}
return await getResult();
}

// 下载传输任务文件
Expand Down
15 changes: 15 additions & 0 deletions src/util/sentry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { haveOCP } from "./env";
import * as Sentry from "@sentry/react";
export function getSentry() {
if (haveOCP()) {
return Sentry;
}
}

export function initSentry() {
getSentry()?.init({
dsn: "https://[email protected]/6",
debug: true,
transport: Sentry.makeXHRTransport
});
}

0 comments on commit 07a8c81

Please sign in to comment.