Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix issues #400

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/config/locale/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@
"fileNotExist": "{name} file does not exist!",
"importYaml": "Import the YAML file",
"templateMatchError": "The {type} in the configuration does not match the current login account/host",
"uploadSuccessfully": "Upload files successfully."
"uploadSuccessfully": "Upload files successfully.",
"fileSizeLimit": "The file is too large and exceeds the upload limit({size}), please modify the MaxBytes in the startup configuration file and restart the service"
},
"schema": {
"spaceList": "Graph Space List",
Expand Down Expand Up @@ -315,7 +316,7 @@
"selectSpace": "Select Space",
"noCurrentSketch": "No schema sketch selected",
"noCurrentSketchTips": "Please select a schema sketch first",
"sketchInvalid": "The schema sketch is invalid, please check",
"sketchInvalid": "Please complete the current Schema information",
"saveSuccess": "Save successfully",
"saveReminder": "The current sketch has been modified but not saved, whether to continue to switch sketches?",
"saveTip": "The current sketch has been modified but not saved, please save first.",
Expand Down
5 changes: 3 additions & 2 deletions app/config/locale/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@
"fileNotExist": "文件 {name} 不存在",
"importYaml": "导入 YAML 文件",
"templateMatchError": "配置中的{type}与当前登录账号/地址不匹配",
"uploadSuccessfully": "上传文件成功"
"uploadSuccessfully": "上传文件成功",
"fileSizeLimit": "文件过大,超过上传限制({size}),请修改启动配置文件中的 MaxBytes 并重启服务"
},
"schema": {
"spaceList": "图空间列表",
Expand Down Expand Up @@ -315,7 +316,7 @@
"selectSpace": "选择图空间",
"noCurrentSketch": "当前没有选中草图",
"noCurrentSketchTips": "请在左侧列表中选择草图",
"sketchInvalid": "当前草图数据格式错误,请检查",
"sketchInvalid": "请完善当前 Schema 信息。",
"saveSuccess": "保存成功",
"saveReminder": "当前草图有修改未保存,是否继续切换草图?",
"saveTip": "当前草图有修改未保存, 请先保存。",
Expand Down
2 changes: 1 addition & 1 deletion app/config/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const service = {
return get('/api/files')();
},
uploadFiles: (params?, config?) => {
put('/api/files')(params, { ...config, headers: { 'Content-Type': 'multipart/form-data' } });
return put('/api/files')(params, { ...config, headers: { 'Content-Type': 'multipart/form-data' } });
},
initSketch: (params, config?) => {
return post(`/api/sketches/sketch`)(params, config);
Expand Down
5 changes: 5 additions & 0 deletions app/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,8 @@ declare module '*.bmp';
declare module '*.tiff';
declare module '*.less';

interface Window {
gConfig: {
maxBytes: number
};
}
9 changes: 9 additions & 0 deletions app/index.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<% var initProps=htmlWebpackPlugin.options.pageInitialProps %>

<!DOCTYPE html>
<html lang="EN_US">

Expand All @@ -8,6 +10,13 @@
<title>NebulaGraph Studio</title>
<script async defer src="https://buttons.github.io/buttons.js"></script>
<!-- Global Event Tracking -->
<script>
<% if (initProps.dev) { %>
window.gConfig = { maxBytes: <%= JSON.stringify(initProps.maxBytes) %> }
<% } else { %>
window.gConfig = { maxBytes: { {.maxBytes } } }
<% } %>
</script>
<style>
@-webkit-keyframes square-spin {
25% {
Expand Down
1 change: 1 addition & 0 deletions app/pages/Import/FileUpload/FileList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const FileList = (props: IProps) => {
{
title: intl.get('import.fileName'),
dataIndex: 'name',
width: '50%'
},
{
title: intl.get('import.withHeader'),
Expand Down
20 changes: 14 additions & 6 deletions app/pages/Import/FileUpload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@ import { debounce } from 'lodash';
import { message } from 'antd';
import { StudioFile } from '@app/interfaces/import';
import { useI18n } from '@vesoft-inc/i18n';
import { getFileSize } from '@app/utils/file';
import FileList from './FileList';

const FileUpload = () => {
const { files } = useStore();
const { files, global } = useStore();
const { intl } = useI18n();
const { fileList, deleteFile, getFiles, uploadFile } = files;
const [loading, setLoading] = useState(false);
const transformFile = async (_file: StudioFile, fileList: StudioFile[]) => {
const size = fileList.reduce((acc, cur) => acc + cur.size, 0);
if(size > global.gConfig.maxBytes) {
message.error(intl.get('import.fileSizeLimit', { size: getFileSize(global.gConfig.maxBytes) }));
return false;
}
fileList.forEach(file => {
file.path = `${file.name}`;
file.withHeader = false;
Expand All @@ -22,13 +28,15 @@ const FileUpload = () => {
return false;
};

const handleUpdate = async (fileList: StudioFile[]) => {
const handleUpdate = (fileList: StudioFile[]) => {
setLoading(true);
await uploadFile(fileList).then(_ => {
setTimeout(() => {
getFileList();
uploadFile(fileList).then(res => {
if(res.code === 0) {
message.success(intl.get('import.uploadSuccessfully'));
}, 2000);
getFileList();
} else {
setLoading(false);
}
}).catch(_err => {
setLoading(false);
});
Expand Down
3 changes: 2 additions & 1 deletion app/pages/SketchModeling/Plugins/SketchShapes/Path.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ const Path: LineRender = {
startControlPoint,
endControlPoint
};
} else if (l <= 0) {
} else if (l <= 0 && from.nodeId === to.nodeId) {
// from.nodeId === to.nodeId Avoid two circles completely coincident
const selfLoopRadius = 30;
const startSpace = 8;
const endSpace = 8;
Expand Down
2 changes: 1 addition & 1 deletion app/pages/SketchModeling/SchemaConfig/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const SchemaConfig: React.FC = () => {
}
});
data.lines.forEach((item) => {
if(item.uuid === sketchModel.active?.uuid || !name) {
if(item.uuid === sketchModel.active?.uuid || !item.name) {
return;
}
if(item.name === name) {
Expand Down
1 change: 1 addition & 0 deletions app/stores/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getRootStore, resetStore } from '.';

const { intl } = getI18n();
export class GlobalStore {
gConfig = window.gConfig;
history: BrowserHistory;
_username = cookies.get('nu');
_host = cookies.get('nh');
Expand Down
2 changes: 1 addition & 1 deletion app/stores/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ export class SchemaStore {

getNodeTagMap = async (ids: string[]) => {
const vidMap = {};
const tagSet = new Set();
const tagSet = new Set(this.tagList.map(i => i.name));
if(!this.spaceVidType) {
await this.updateVidType();
}
Expand Down
9 changes: 9 additions & 0 deletions config/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const fs = require('fs');
const path = require('path');
const yaml = require('js-yaml');

exports.getAppConfig = () => {
const file = fs.readFileSync(path.resolve(__dirname, '../server/api/studio/etc/studio-api.yaml'), 'utf8');
const appConfig = yaml.load(file);
return appConfig;
};
10 changes: 10 additions & 0 deletions config/webpack.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ const AntdDayjsWebpackPlugin = require('antd-dayjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const Package = require('../package.json');
const { getAppConfig } = require('./config');
const { getEnv } = require('./env');

const appConfig = getAppConfig();

const isDevEnv = () => getEnv() === 'development';

const commonConfig = {
entry: {
Expand Down Expand Up @@ -119,6 +125,10 @@ const commonConfig = {
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
},
pageInitialProps: {
dev: isDevEnv(),
maxBytes: appConfig.MaxBytes
}
}),
new AntdDayjsWebpackPlugin(),
new CopyPlugin({
Expand Down
3 changes: 3 additions & 0 deletions server/api/studio/internal/service/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func (f *fileService) FileUpload() error {
return ecode.WithErrorMessage(ecode.ErrInternalServer, err, "upload failed")
}
for _, file := range files {
if file.Size == 0 {
continue
}
charSet, err := checkCharset(file)
if err != nil {
logx.Infof("upload file error, check charset fail:%v", err)
Expand Down
41 changes: 41 additions & 0 deletions server/api/studio/pkg/middleware/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package utils

import (
"html/template"
"io/fs"
"net/http"
"path/filepath"

"github.com/vesoft-inc/go-pkg/middleware"
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/svc"
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/ecode"
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/utils"
)

func AssetsMiddlewareWithCtx(svcCtx *svc.ServiceContext, embedAssets fs.FS) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
if filepath.Ext(r.URL.Path) == "" {
tpl, err := template.ParseFS(embedAssets, "assets/index.html")
withErrorMessage := utils.ErrMsgWithLogger(r.Context())
if err != nil {
svcCtx.ResponseHandler.Handle(w, r, nil, withErrorMessage(ecode.ErrInternalServer, err))
return
}

w.Header().Set("Content-Type", "text/html")
w.WriteHeader(http.StatusOK)
tpl.Execute(w, map[string]any{"maxBytes": svcCtx.Config.MaxBytes})
return
}

handler := middleware.NewAssetsHandler(middleware.AssetsConfig{
Root: "assets",
Filesystem: http.FS(embedAssets),
SPA: true,
})
// if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") && !strings.Contains(r.Header.Get("Accept"), "image/") {
// w.Header().Set("Content-Encoding", "gzip")
// }
handler.ServeHTTP(w, r)
})
}
7 changes: 2 additions & 5 deletions server/api/studio/studio.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/vesoft-inc/nebula-studio/server/api/studio/internal/svc"
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/auth"
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/logging"
studioMiddleware "github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/middleware"
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/server"
"github.com/vesoft-inc/nebula-studio/server/api/studio/pkg/utils"
"github.com/zeromicro/go-zero/core/conf"
Expand Down Expand Up @@ -45,11 +46,7 @@ func main() {
server.InitDB(c.File.SqliteDbFilePath)

svcCtx := svc.NewServiceContext(c)
server := rest.MustNewServer(c.RestConf, rest.WithNotFoundHandler(middleware.NewAssetsHandler(middleware.AssetsConfig{
Root: "assets",
Filesystem: http.FS(embedAssets),
SPA: true,
})))
server := rest.MustNewServer(c.RestConf, rest.WithNotFoundHandler(studioMiddleware.AssetsMiddlewareWithCtx(svcCtx, embedAssets)))

defer server.Stop()
waitForCalled := proc.AddWrapUpListener(func() {
Expand Down