From affd47193c9f103cf1afcf65da17d52d8b433c95 Mon Sep 17 00:00:00 2001 From: AceDataCloud Date: Mon, 25 Sep 2023 20:54:31 +0800 Subject: [PATCH] fix --- certs/.gitignore | 2 -- docker-compose.yaml | 8 ++--- nginx.conf | 8 ----- package.json | 7 ++-- src/App.vue | 22 +----------- src/components/common/Sidebar.vue | 3 ++ src/layouts/Main.vue | 33 +++++++++++++++++ src/pages/chat/Conversation.vue | 3 ++ src/pages/chat/Index.vue | 0 src/router/chat.ts | 18 ++++++++++ src/router/constants.ts | 3 ++ src/router/index.ts | 19 ++-------- src/store/index.ts | 60 +------------------------------ vite.config.ts | 47 ++---------------------- 14 files changed, 73 insertions(+), 160 deletions(-) delete mode 100644 certs/.gitignore create mode 100644 src/components/common/Sidebar.vue create mode 100644 src/layouts/Main.vue create mode 100644 src/pages/chat/Conversation.vue create mode 100644 src/pages/chat/Index.vue create mode 100644 src/router/chat.ts diff --git a/certs/.gitignore b/certs/.gitignore deleted file mode 100644 index c96a04f0..00000000 --- a/certs/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml index 48d82572..8b35a5b2 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,8 +1,8 @@ version: '3' services: - zhishuyun-chat-frontend: - container_name: 'zhishuyun-chat-frontend' + zhishuyun-ai-frontend: + container_name: 'zhishuyun-ai-frontend' build: ./ - image: 'ghcr.io/zhishuyun/chat-frontend:${BUILD_NUMBER}' + image: 'ghcr.io/zhishuyun/ai-frontend:${BUILD_NUMBER}' ports: - - '8086:80' + - '8000:80' diff --git a/nginx.conf b/nginx.conf index ceb3ba29..63d5daf2 100644 --- a/nginx.conf +++ b/nginx.conf @@ -3,14 +3,6 @@ server { server_name localhost; proxy_http_version 1.1; - location /api/v1/me { - proxy_pass http://auth-backend:8000; - } - - location /api/v1/token { - proxy_pass http://auth-backend:8000; - } - location /api/v1/ { proxy_pass http://data-backend:8000; } diff --git a/package.json b/package.json index d5c6d7df..640122f8 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,5 @@ { - "name": "zhishuyun-data", + "name": "zhishuyun-ai", "version": "0.1.0", "scripts": { "start": "cross-env NODE_ENV=$npm_config_env vite --host", @@ -9,10 +9,7 @@ "build": "vite build", "serve": "vite preview", "lint": "npx eslint src --fix --ext .ts,.tsx,.vue,.js,.jsx", - "prettier": "npx prettier --write .", - "init:https": "npm run init:ca && npm run init:cert", - "init:ca": "npx mkcert create-ca --validity 36500 --key certs/chat.local.zhishuyun.com.ca.key --cert certs/chat.local.zhishuyun.com.ca.crt", - "init:cert": "npx mkcert create-cert --ca-key certs/chat.local.zhishuyun.com.ca.key --ca-cert certs/chat.local.zhishuyun.com.ca.crt --validity 36500 --key certs/chat.local.zhishuyun.com.cert.key --cert certs/chat.local.zhishuyun.com.cert.crt --domains chat.local.zhishuyun.com" + "prettier": "npx prettier --write ." }, "dependencies": { "@codemirror/lang-java": "^6.0.1", diff --git a/src/App.vue b/src/App.vue index 1f0bfd69..e85489d6 100644 --- a/src/App.vue +++ b/src/App.vue @@ -8,7 +8,6 @@ import { defineComponent } from 'vue'; import { ElConfigProvider } from 'element-plus'; import zhCn from 'element-plus/dist/locale/zh-cn.mjs'; -import { authOperator } from './operators/auth/operator'; export default defineComponent({ components: { @@ -19,25 +18,6 @@ export default defineComponent({ locale: zhCn }; }, - async mounted() { - // if refresh token is already set, try to refresh it and get user info - const currentRefreshToken = this.$store.getters.refreshToken; - const currentAccessToken = this.$store.getters.accessToken; - if (!currentAccessToken) { - console.log('user not login'); - } - if (currentRefreshToken) { - const { - data: { access: accessToken, refresh: refreshToken } - } = await authOperator.refreshToken({ - refresh: currentRefreshToken - }); - await this.$store.dispatch('setAccessToken', accessToken); - await this.$store.dispatch('setRefreshToken', refreshToken); - await this.$store.dispatch('getMe'); - } else { - console.error('refresh token does not exist'); - } - } + async mounted() {} }); diff --git a/src/components/common/Sidebar.vue b/src/components/common/Sidebar.vue new file mode 100644 index 00000000..9785253b --- /dev/null +++ b/src/components/common/Sidebar.vue @@ -0,0 +1,3 @@ + diff --git a/src/layouts/Main.vue b/src/layouts/Main.vue new file mode 100644 index 00000000..cb3d2f06 --- /dev/null +++ b/src/layouts/Main.vue @@ -0,0 +1,33 @@ + + + + + diff --git a/src/pages/chat/Conversation.vue b/src/pages/chat/Conversation.vue new file mode 100644 index 00000000..18acd737 --- /dev/null +++ b/src/pages/chat/Conversation.vue @@ -0,0 +1,3 @@ + diff --git a/src/pages/chat/Index.vue b/src/pages/chat/Index.vue new file mode 100644 index 00000000..e69de29b diff --git a/src/router/chat.ts b/src/router/chat.ts new file mode 100644 index 00000000..a480209d --- /dev/null +++ b/src/router/chat.ts @@ -0,0 +1,18 @@ +import { ROUTE_AUTH_CALLBACK, ROUTE_AUTH_LOGIN, ROUTE_CHAT_CONVERSATION, ROUTE_CHAT_INDEX } from './constants'; + +export default { + path: '/chat', + component: () => import('@/layouts/Main.vue'), + children: [ + { + path: '', + name: ROUTE_CHAT_INDEX, + component: () => import('@/pages/chat/Index.vue') + }, + { + path: 'conversation/:id', + name: ROUTE_CHAT_CONVERSATION, + component: () => import('@/pages/chat/Conversation.vue') + } + ] +}; diff --git a/src/router/constants.ts b/src/router/constants.ts index 659c99f6..6dbf799d 100644 --- a/src/router/constants.ts +++ b/src/router/constants.ts @@ -3,5 +3,8 @@ export const ROUTE_INDEX = 'index'; export const ROUTE_AUTH_LOGIN = 'auth-login'; export const ROUTE_AUTH_CALLBACK = 'auth-callback'; +export const ROUTE_CHAT_INDEX = 'chat-index'; +export const ROUTE_CHAT_CONVERSATION = 'chat-conversation'; + export const ROUTE_CONVERSATION_NEW = 'conversation-new'; export const ROUTE_CONVERSATION_DETAIL = 'conversation-detail'; diff --git a/src/router/index.ts b/src/router/index.ts index dccaeaa1..1672357f 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router'; import auth from './auth'; import conversation from './conversation'; import store from '@/store'; +import chat from './chat'; import { ROUTE_AUTH_LOGIN, ROUTE_CONVERSATION_NEW, ROUTE_INDEX } from './constants'; const routes = [ @@ -12,8 +13,7 @@ const routes = [ name: ROUTE_CONVERSATION_NEW } }, - auth, - conversation + chat ]; const router = createRouter({ @@ -21,21 +21,6 @@ const router = createRouter({ routes }); -router.beforeEach((to, from, next) => { - if (to.matched.some((record) => record.meta.auth)) { - if (!store.getters.authenticated) { - next({ - name: ROUTE_AUTH_LOGIN, - query: { redirect: to.fullPath } - }); - } else { - next(); - } - } else { - next(); - } -}); - export default router; export * from './constants'; diff --git a/src/store/index.ts b/src/store/index.ts index b1a63b82..3265cbc7 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,9 +1,7 @@ import { createStore, ActionContext } from 'vuex'; import createPersistedState from 'vuex-persistedstate'; -import { userOperator, IUser } from '@/operators'; import { removeCookies } from '@/utils/cookie'; -import { IConversation } from '@/operators/conversation/models'; -import { DEFAULT_API, ENDPOINT } from '@/constants'; +import { ENDPOINT } from '@/constants'; export interface ISetting { stream?: boolean; @@ -12,10 +10,6 @@ export interface ISetting { export interface IState { accessToken: string | undefined; - refreshToken: string | undefined; - user: IUser | undefined; - activeApiId: string | undefined; - conversations: IConversation[]; setting: ISetting; } @@ -23,10 +17,6 @@ const store = createStore({ state(): IState { return { accessToken: undefined, - refreshToken: undefined, - user: undefined, - activeApiId: DEFAULT_API.id, - conversations: [], setting: { endpoint: ENDPOINT, stream: false @@ -37,59 +27,23 @@ const store = createStore({ setAccessToken(state: IState, payload: string): void { state.accessToken = payload; }, - setRefreshToken(state: IState, payload: string): void { - state.refreshToken = payload; - }, - setUser(state: IState, payload: IUser): void { - state.user = payload; - }, setSetting(state: IState, payload: ISetting): void { state.setting = { ...state.setting, ...payload }; - }, - setConversations(state: IState, payload: IConversation[]): void { - state.conversations = payload; - }, - setActiveApiId(state: IState, payload: string): void { - state.activeApiId = payload; } }, actions: { resetAuth({ commit }) { - commit('setRefreshToken', undefined); commit('setAccessToken', undefined); - commit('setUser', undefined); removeCookies(); }, - setRefreshToken({ commit }: ActionContext, payload: string) { - commit('setRefreshToken', payload); - }, setAccessToken({ commit }: ActionContext, payload: string) { commit('setAccessToken', payload); }, - setUser({ commit }: ActionContext, payload: IUser) { - commit('setUser', payload); - }, setSetting({ commit }: ActionContext, payload: ISetting) { commit('setSetting', payload); - }, - setActiveApiId({ commit }: ActionContext, payload: string) { - commit('setActiveApiId', payload); - }, - setConversations({ commit }: ActionContext, payload: IConversation[]) { - commit('setConversations', payload); - }, - getMe({ commit }: ActionContext) { - userOperator - .getMe() - .then(({ data: data }) => { - commit('setUser', data); - }) - .catch(() => { - console.error('failed to get user info'); - }); } }, getters: { @@ -99,20 +53,8 @@ const store = createStore({ accessToken(state): string | undefined { return state.accessToken; }, - activeApiId(state): string | undefined { - return state.activeApiId; - }, - refreshToken(state): string | undefined { - return state.refreshToken; - }, - user(state): IUser | undefined { - return state.user; - }, setting(state): ISetting | undefined { return state.setting; - }, - conversations(state): IConversation[] { - return state.conversations || []; } }, plugins: [createPersistedState()] diff --git a/vite.config.ts b/vite.config.ts index 5981c0f7..b2ba23de 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -3,55 +3,14 @@ import vue from '@vitejs/plugin-vue'; import replace from '@rollup/plugin-replace'; import { string } from 'rollup-plugin-string'; import * as path from 'path'; -import * as fs from 'fs'; - -const getAuthEndpoint = () => { - switch (process.env.NODE_ENV) { - case 'local': - return 'https://auth.test.zhishuyun.com'; - case 'test': - return 'https://auth.test.zhishuyun.com'; - case 'production': - default: - return 'https://auth.zhishuyun.com'; - } -}; - -const getDataEndpoint = () => { - switch (process.env.NODE_ENV) { - case 'local': - return 'http://127.0.0.1:8007'; - case 'test': - return 'https://data.test.zhishuyun.com'; - case 'production': - default: - return 'https://data.zhishuyun.com'; - } -}; export default defineConfig({ server: { - host: 'chat.local.zhishuyun.com', - port: 443, - https: { - key: fs.readFileSync('certs/chat.local.zhishuyun.com.cert.key'), - cert: fs.readFileSync('certs/chat.local.zhishuyun.com.cert.crt') - }, + host: 'localhost', + port: 8080, proxy: { - '/api/v1/me': { - target: getAuthEndpoint(), - changeOrigin: true - }, - '/api/v1/token': { - target: getAuthEndpoint(), - changeOrigin: true - }, '/api': { - target: getDataEndpoint(), - changeOrigin: true - }, - '/static': { - target: getDataEndpoint(), + target: 'https://data.zhishuyun.com', changeOrigin: true } }