Skip to content

Commit

Permalink
refactor: server update & bugfix (#230)
Browse files Browse the repository at this point in the history
feat: mime && connectdb
feat: 文件上传、删除、预览功能实现 (#206)
feat: middleware (#208)
* feat: middleware
* feat: dynamicly add query params func
* feat: common params
* update: go mod tidy
* feat: batchExec

complete file and import task (#213)

modify upload and download
mody: go mod
refine the code
update: make check
modify return values

Refactor (#219)

* update: server-v2
* updata: format

feat: context auth (#220)

update: export module (#222)

feat: export RegisterHandlers (#223)

update: gitignore (#224)

fix: fix service init crash (#225)

update: WithErrorMessage (#226)

fix import task (#227)

fix the type conveersion problem

fix: fix import & file model (#229)

Co-authored-by: Bruce <[email protected]>
  • Loading branch information
hetao92 and huaxiabuluo authored May 26, 2022
1 parent 0deae69 commit eb8e692
Show file tree
Hide file tree
Showing 90 changed files with 5,549 additions and 242 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ node_modules/
.DS_Store
.vscode
*.swp
*.swo
*.out
*.log
*.lock
*.map
.github/workflows/nodejs.yml


app/**/*.map
config/**/*.map
dist/
Expand All @@ -19,5 +23,9 @@ dist/
!app/**/*.js
tmp
server/data
assets/
server/assets/*
!server/assets/.gitkeep
server-v2/api/*/data
server-v2/api/*/assets/*
!server-v2/api/*/assets/.gitkeep
bin/
60 changes: 28 additions & 32 deletions app/config/service.ts
Original file line number Diff line number Diff line change
@@ -1,61 +1,57 @@
import { _delete, get, post, put } from '../utils/http';

let service = {
execNGQL: (params, config?) => {
return post('/api-nebula/db/exec')(params, config)
const service = {
execNGQL: (params, config?) => {
return post('/api-nebula/db/exec')(params, config);
},
batchExecNGQL: (params, config?) => {
return post('/api-nebula/db/batchExec')(params, config)
return post('/api-nebula/db/batchExec')(params, config);
},
connectDB: (params, config?) => {
return post('/api-nebula/db/connect')(params, config)
return post('/api-nebula/db/connect')(params, config);
},
disconnectDB: (params, config?) => {
return post('/api-nebula/db/disconnect')(params, config)
return post('/api-nebula/db/disconnect')(params, config);
},
// import
importData: (params, config?) => {
return post('/api/import-tasks/import')(params, config)
return post('/api/import-tasks')(params, config);
},
handleImportAction: (params, config?) => {
return post('/api/import-tasks/action')(params, config)
stopImportTask: (id: number) => {
return post(`/api/import-tasks/${id}/stop`)();
},
getLog: (params, config?) => {
return get('/api/import-tasks/logs')(params, config)
deleteImportTask: (id: number) => {
return post(`/api/import-tasks/${id}/stop`)();
},
getErrLog: (params, config?) => {
return get('/api/import-tasks/err-logs')(params, config)
getTaskList: (params?, config?) => {
return get('/api/import-tasks')(params, config);
},
finishImport: (params, config?) => {
return post('/api/import/finish')(params, config)
},
getUploadDir: () => {
return get('/api/import-tasks/working-dir')()
getTaskLogs: (params?, config?) => {
const { id, ...others } = params;
return get(`/api/import-tasks/${id}/task-log-names`)(others, config);
},
getTaskDir: () => {
return get('/api/import-tasks/task-dir')()
getLogDetail: (params, config?) => {
const { id, ...others } = params;
return get(`/api/import-tasks/${id}/logs`)(others, config);
},
deteleFile:params => {
getTaskConfig: (id: string | number) => `/api/import-tasks/${id}/download-config`,
getTaskLog: (id: string | number) => `/api/import-tasks/${id}/download-logs`,
// files
deteleFile: params => {
const { filename } = params;
return _delete(`/api/files/${filename}`)();
},
getFiles: () => {
return get('/api/files')()
return get('/api/files')();
},
uploadFiles: (params?, config?) => {
put('/api/files')(params, { ...config, headers: { 'Content-Type': 'multipart/form-data' } });
},
getTaskLogs: (params?, config?) => {
const { id, ...others } = params;
return get(`/api/import-tasks/${id}/task-log-names`)(others, config);
},
getTaskConfigUrl: (id: string | number) => `/api/import-tasks/config/${id}`,
getTaskLogUrl: (id: string | number) => `/api/import-tasks/${id}/log`,
getTaskErrLogUrl: (id: string | number) => `/api/import-tasks/${id}/err-logs`,
}
};

export const updateService = (partService: any) => {
Object.assign(service, partService)
}
Object.assign(service, partService);
};

export default service;

12 changes: 6 additions & 6 deletions app/interfaces/import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ export interface ITaskStats {
numReadFailed: number;
}
export interface ITaskItem {
taskID: number;
nebulaAddress: string;
id: number;
address: string;
space: string;
name: string;
createdTime: number;
updatedTime: number;
createTime: number;
updateTime: number;
user: string;
taskStatus: ITaskStatus;
taskMessage: string;
status: ITaskStatus;
message: string;
stats: ITaskStats;
}

Expand Down
32 changes: 12 additions & 20 deletions app/pages/Import/FileUpload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,57 +2,49 @@ import React, { useEffect, useState } from 'react';
import { observer } from 'mobx-react-lite';
import { useStore } from '@app/stores';
import { trackPageView } from '@app/utils/stat';
import FileList from './FileList';
import { debounce } from 'lodash';
import { message } from 'antd';
import intl from 'react-intl-universal';
import { StudioFile } from '@app/interfaces/import';
interface IProps {
needFileDir: boolean
}
import FileList from './FileList';

const FileUpload = (props: IProps) => {
const FileUpload = () => {
const { files } = useStore();
const { fileList, uploadDir, deleteFile, getFiles, uploadFile, getUploadDir } = files;
const { fileList, deleteFile, getFiles, uploadFile } = files;
const [loading, setLoading] = useState(false);
const { needFileDir = true } = props;
const transformFile = async (_file: StudioFile, fileList: StudioFile[]) => {
fileList.forEach(file => {
if(needFileDir) {
file.path = `${uploadDir}/${file.name}`;
}
file.path = `${file.name}`;
file.withHeader = false;
})

await handleUpdate(fileList)
return false
});
await handleUpdate(fileList);
return false;
};

const handleUpdate = async (fileList: StudioFile[]) => {
setLoading(true);
await uploadFile(fileList).then(_ => {
setTimeout(() => {
getFileList();
message.success(intl.get('import.uploadSuccessfully'))
}, 2000)
message.success(intl.get('import.uploadSuccessfully'));
}, 2000);
}).catch(_err => {
setLoading(false);
});
};

const handleDelete = (index: number) => {
const file = fileList[index].name;
deleteFile(file)
}
deleteFile(file);
};

const getFileList = async () => {
!loading && setLoading(true);
await getFiles();
setLoading(false);
}
};
useEffect(() => {
getFileList();
needFileDir && getUploadDir();
trackPageView('/import/files');
}, []);
return (
Expand Down
14 changes: 9 additions & 5 deletions app/pages/Import/TaskCreate/FileSelect/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Form, Popover, Select } from 'antd';
import React, { useEffect, useState } from 'react';
import React, { useState } from 'react';
import intl from 'react-intl-universal';
import { observer } from 'mobx-react-lite';
import { useStore } from '@app/stores';
Expand Down Expand Up @@ -42,9 +42,13 @@ const FileSelect = (props: IProps) => {
}
setVisible(false);
};
useEffect(() => {
getFiles();
}, []);

const handleGetFiles = () => {
if(fileList.length === 0) {
getFiles();
}
};

return (
<Popover
destroyTooltipOnHide={true}
Expand All @@ -54,7 +58,7 @@ const FileSelect = (props: IProps) => {
onVisibleChange={visible => setVisible(visible)}
content={<Form className={styles.fileSelectForm} onFinish={onFinish} layout="inline">
<FormItem name="name" rules={[{ required: true }]}>
<Select className={styles.fileSelect} showSearch={true} dropdownMatchSelectWidth={false}>
<Select className={styles.fileSelect} showSearch={true} onDropdownVisibleChange={handleGetFiles} dropdownMatchSelectWidth={false}>
{fileList.map((file: any) => (
<Option value={file.name} key={file.name}>
{file.name}
Expand Down
2 changes: 1 addition & 1 deletion app/pages/Import/TaskCreate/PasswordInputModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const PasswordInputModal = (props: IProps) => {
const handleCancel = () => {
setPassword('');
onCancel();
}
};
return (
<Modal
title={intl.get('import.enterPassword')}
Expand Down
30 changes: 15 additions & 15 deletions app/pages/Import/TaskCreate/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,16 @@ const formItemLayout = {

interface IProps {
needPwdConfirm?: boolean;
mode?: string
}
const TaskCreate = (props: IProps) => {
const { dataImport, schema } = useStore();
const { getTaskDir, basicConfig, verticesConfig, edgesConfig, updateBasicConfig, importTask } = dataImport;
const { dataImport, schema, files } = useStore();
const { basicConfig, verticesConfig, edgesConfig, updateBasicConfig, importTask } = dataImport;
const { spaces, getSpaces, updateSpaceInfo, currentSpace } = schema;
const { getFiles } = files;
const { batchSize } = basicConfig;
const [modalVisible, setVisible] = useState(false);
const history = useHistory();
const { needPwdConfirm = true, mode = 'local' } = props;
const { needPwdConfirm = true } = props;
const routes = [
{
path: '/import/tasks',
Expand Down Expand Up @@ -107,33 +107,33 @@ const TaskCreate = (props: IProps) => {
}
};

const clearConfig = () => {
dataImport.update({
basicConfig: { taskName: '' },
const clearConfig = (type?: string) => {
const params = {
verticesConfig: [],
edgesConfig: []
});
} as any;
if(type === 'all') {
params.basicConfig = { taskName: '' };
}
dataImport.update(params);
};
const handleSpaceChange = (space: string) => {
clearConfig();
updateSpaceInfo(space);
};

const initTaskDir = async () => {
const dir = await getTaskDir();
if(dir) {
const count = dir.split('/').pop();
updateBasicConfig('taskName', `task-${count}`);
}
updateBasicConfig('taskName', `task-${Date.now()}`);
};
useEffect(() => {
mode === 'local' && initTaskDir();
initTaskDir();
getSpaces();
getFiles();
if(currentSpace) {
updateSpaceInfo(currentSpace);
}
trackPageView('/import/create');
return () => clearConfig();
return () => clearConfig('all');
}, []);
return (
<div className={styles.importCreate}>
Expand Down
20 changes: 7 additions & 13 deletions app/pages/Import/TaskList/TaskItem/LogModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@ interface ILogDimension {
status: ITaskStatus;
}

interface ILog {
name: string;
}
interface IProps {
logDimension: ILogDimension;
visible: boolean;
Expand All @@ -25,15 +22,15 @@ interface IProps {
}
const LogModal = (props: IProps) => {
const { visible, onCancel, showLogDownload, logDimension: { space, id, status } } = props;
const { dataImport: { getLogs, downloadTaskLog, getImportLogDetail, getErrLogDetail } } = useStore();
const { dataImport: { getLogs, downloadTaskLog, getLogDetail } } = useStore();
const logRef = useRef<HTMLDivElement>(null);
const timer = useRef<any>(null);
const offset = useRef(0);
const _status = useRef(status);
const [logs, setLogs] = useState<ILog[]>([]);
const [currentLog, setCurrentLog] = useState<ILog | null>(null);
const [logs, setLogs] = useState<string[]>([]);
const [currentLog, setCurrentLog] = useState<string | null>(null);
const handleTabChange = (key: string) => {
setCurrentLog(logs.filter(item => item.name === key)[0]);
setCurrentLog(logs.filter(item => item === key)[0]);
};

const getAllLogs = async () => {
Expand All @@ -46,22 +43,19 @@ const LogModal = (props: IProps) => {

const handleLogDownload = () => {
if(currentLog) {
const type = currentLog!.name === 'import.log' ? 'import' : 'err';
downloadTaskLog({
id,
type,
name: currentLog.name
name: currentLog
});
}
};

const readLog = async () => {
const getLogDetail = currentLog!.name === 'import.log' ? getImportLogDetail : getErrLogDetail;
const res = await getLogDetail({
offset: offset.current,
id,
limit: 500,
name: currentLog!.name
file: currentLog
});
handleLogData(res);
};
Expand Down Expand Up @@ -125,7 +119,7 @@ const LogModal = (props: IProps) => {
>
<Tabs className={styles.logTab} tabBarGutter={0} tabPosition="left" onChange={handleTabChange}>
{logs.map(log => (
<TabPane tab={`${log.name}`} key={log.name} />
<TabPane tab={log} key={log} />
))}
</Tabs>
<div className={styles.logContainer} ref={logRef}/>
Expand Down
Loading

0 comments on commit eb8e692

Please sign in to comment.