Skip to content

Commit

Permalink
connected to sqlite3 in dev mode but can not bundle yet
Browse files Browse the repository at this point in the history
  • Loading branch information
hxhxhx88 committed Feb 28, 2024
1 parent ddbeb86 commit 73ad3fe
Show file tree
Hide file tree
Showing 22 changed files with 971 additions and 168 deletions.
11 changes: 7 additions & 4 deletions app/action/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func createServer() (backend.Server, func(), error) {
var opts []backend.Option

// storage
db, err := sqlite3.New(filepath.Join(databaseDir(), "db.sqlite3"))
db, err := sqlite3.New(databasePath())
if err != nil {
return nil, nil, err
}
Expand Down Expand Up @@ -217,6 +217,10 @@ func databaseDir() string {
return filepath.Join(StorageOption.Workspace, "database")
}

func databasePath() string {
return filepath.Join(databaseDir(), "db.sqlite3")
}

func mustStartYJSServer() int {
// create a temporary file
bin, err := os.CreateTemp("", "nutsh-yjs-*")
Expand All @@ -232,15 +236,14 @@ func mustStartYJSServer() int {

// prepare arguments
internalPort := mustFindFreePort()
dir := filepath.Join(StorageOption.Workspace, "yjs")

// execute the binary in a new process
cmd := exec.Command(bin.Name())
cmd.Env = []string{
fmt.Sprintf("PORT=%d", internalPort),
fmt.Sprintf("DATA_DIR=%s", dir),
fmt.Sprintf("DATABASE_PATH=%s", databasePath()),
}
zap.L().Info("start yjs-server server", zap.Int("port", internalPort), zap.String("dir", dir))
zap.L().Info("start yjs-server server", zap.Int("port", internalPort))

cmd.Stderr = os.Stderr
cmd.Stdout = os.Stdout
Expand Down
4 changes: 4 additions & 0 deletions app/frontend/craco.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
// eslint-disable-next-line node/no-unpublished-require
const CopyWebpackPlugin = require('copy-webpack-plugin');
const path = require('path');

module.exports = {
webpack: {
alias: {
'@@frontend': path.resolve(__dirname, 'src/'),
},
configure: config => {
config.plugins.push(
new CopyWebpackPlugin({
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/common/annotation.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Annotation, Component, Entity, EntityId, SliceIndex, Vertex} from 'type/annotation';
import type {Annotation, Component, Entity, EntityId, SliceIndex, Vertex} from '@@frontend/type/annotation';
import {deepClone} from './util';

export function addAnnotationComponent(
Expand Down
7 changes: 7 additions & 0 deletions app/frontend/src/common/mouse.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function relativeMousePosition<T extends HTMLElement>(event: React.MouseEvent<T>, ele: T) {
const rect = ele.getBoundingClientRect();
return {
x: event.clientX - rect.left,
y: event.clientY - rect.top,
};
}
8 changes: 0 additions & 8 deletions app/frontend/src/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,3 @@ export function deepClone<T>(obj: T): T {
export function deepEqual<T>(a: T, b: T): boolean {
return deepCompare(a, b);
}

export function relativeMousePosition<T extends HTMLElement>(event: React.MouseEvent<T>, ele: T) {
const rect = ele.getBoundingClientRect();
return {
x: event.clientX - rect.left,
y: event.clientY - rect.top,
};
}
11 changes: 5 additions & 6 deletions app/frontend/src/common/yjs/convert.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
import {emptyAnnotation} from 'state/annotate/render';
import {
import * as Y from 'yjs';
import type {
Annotation,
Component,
ComponentId,
EntityId,
PolychainComponent,
RectangleComponent,
SliceIndex,
} from 'type/annotation';
import * as Y from 'yjs';
} from '@@frontend/type/annotation';
import {addAnnotationComponent, setEntityCategory} from '@@frontend/common/annotation';
import {yjsComponentMap, Component as YjsComponent} from './docs/component';
import {yjsRectangleAnchorsMap} from './docs/rectangle';
import {yjsPolychainVerticesMap} from './docs/polychain';
import {yjsMaskMap} from './docs/mask';
import {encodeEntityCategoryMapKey, decodeEntityCategoryMapKey, yjsEntityCategoriesMap} from './docs/entity';
import {addAnnotationComponent, setEntityCategory} from 'common/annotation';

export function readAnnotationFromYjs(doc: Y.Doc): Annotation {
const anno = emptyAnnotation();
const anno: Annotation = {entities: {}};

// components
const comps = yjsComponentMap(doc);
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/common/yjs/docs/component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {EntityId, SliceIndex} from 'type/annotation';
import type {EntityId, SliceIndex} from '@@frontend/type/annotation';
import * as Y from 'yjs';

export type ComponentBase = {
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/common/yjs/docs/entity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {EntityId, SliceIndex} from 'type/annotation';
import type {EntityId, SliceIndex} from '@@frontend/type/annotation';
import * as Y from 'yjs';

export type CategoryList = string[];
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/common/yjs/docs/mask.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Y from 'yjs';
import {MaskComponent} from 'type/annotation';
import type {MaskComponent} from '@@frontend/type/annotation';

export type Mask = MaskComponent;

Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/common/yjs/docs/polychain.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Y from 'yjs';
import {Vertex} from 'type/annotation';
import type {Vertex} from '@@frontend/type/annotation';

export type PolychainVertices = Y.Array<Vertex>;

Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/common/yjs/docs/rectangle.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Y from 'yjs';
import {RectangleComponent} from 'type/annotation';
import type {RectangleComponent} from '@@frontend/type/annotation';

export type RectangleAnchors = Pick<RectangleComponent, 'topLeft' | 'bottomRight'>;

Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/component/panel/layer/mask/Hover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ComponentProximity} from 'state/annotate/render/mouse';
import {useStore as useBrushCanvasStore} from 'component/segmentation/BrushCanvas';
import {useStore as useRenderStore} from 'state/annotate/render';
import {useStore as useUIStore} from 'state/annotate/ui';
import {relativeMousePosition} from 'common/util';
import {relativeMousePosition} from 'common/mouse';
import {coordinatesCanvasToImage} from 'common/geometry';

type Props = HTMLAttributes<HTMLDivElement> & {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {Spin, Tag} from 'antd';
import intl from 'react-intl-universal';
import {Tensor} from 'onnxruntime-web';
import shallow from 'zustand/shallow';
import {relativeMousePosition} from 'common/util';
import {relativeMousePosition} from 'common/mouse';
import {coordinatesCanvasToImage, coordinatesImageToCanvas, limitGrid} from 'common/geometry';
import {drawRect} from 'common/draw';
import {SurroundStyle} from 'common/constant';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {throttle} from 'lodash';
import {Tensor} from 'onnxruntime-web';

import {FocusOpacity} from 'common/constant';
import {relativeMousePosition} from 'common/util';
import {relativeMousePosition} from 'common/mouse';
import {coordinatesCanvasToImage, coordinatesImageToCanvas, distance} from 'common/geometry';
import {SizedContainer} from 'component/SizedContainer';
import {Coordinates} from 'type/annotation';
Expand Down
2 changes: 1 addition & 1 deletion app/frontend/src/component/segmentation/BrushCanvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {coordinatesCanvasToImage, coordinatesImageToCanvas, distance} from 'comm
import {FocusOpacity} from 'common/constant';
import {convertRGBA2Hex} from 'common/color';
import {Coordinates} from 'type/annotation';
import {relativeMousePosition} from 'common/util';
import {relativeMousePosition} from 'common/mouse';
import {updateImageRendering, useCanvasContext} from '../panel/layer/mask/common';
import {ViewportTransform} from 'state/annotate/render/viewport';
import {Alert, Button, Popover, Slider, Space, Tag, Tooltip, Typography, theme} from 'antd';
Expand Down
17 changes: 7 additions & 10 deletions app/frontend/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@
"extends": "./node_modules/gts/tsconfig-google.json",
"compilerOptions": {
"target": "es2015",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
Expand All @@ -19,13 +15,14 @@
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"jsx": "react-jsx",
"jsxImportSource": "@emotion/react",

// To enable importing by absolute path
"baseUrl": "src"
"baseUrl": "src",
"paths": {
"@@frontend/*": ["*"]
}
},
"include": [
"src"
]
"include": ["src"]
}
3 changes: 3 additions & 0 deletions app/yjs-server/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"printWidth": 120
}
Loading

0 comments on commit 73ad3fe

Please sign in to comment.