fix
This commit is contained in:
1 parent
d206c7df38
commit
affd47193c
14 files changed
+73
-160
No files matched your search
@@ -1,2 +0,0 @@
|
||||
*
|
||||
!.gitignore
|
||||
+4
-4
@@ -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'
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+2
-5
@@ -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",
|
||||
|
||||
+1
-21
@@ -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() {}
|
||||
});
|
||||
</script>
|
||||
@@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<div>si</div>
|
||||
</template>
|
||||
@@ -0,0 +1,33 @@
|
||||
<template>
|
||||
<div class="wrapper">
|
||||
<div class="sidebar"></div>
|
||||
<div class="main">
|
||||
<router-view />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElContainer, ElMain } from 'element-plus';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'LayoutMain',
|
||||
components: {}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.wrapper {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.sidebar {
|
||||
width: 50px;
|
||||
}
|
||||
.main {
|
||||
flex: 1;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,3 @@
|
||||
<template>
|
||||
<div>hi</div>
|
||||
</template>
|
||||
Whitespace-only changes.
@@ -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')
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -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';
|
||||
+2
-17
@@ -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';
|
||||
+1
-59
@@ -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<IState, IState>, payload: string) {
|
||||
commit('setRefreshToken', payload);
|
||||
},
|
||||
setAccessToken({ commit }: ActionContext<IState, IState>, payload: string) {
|
||||
commit('setAccessToken', payload);
|
||||
},
|
||||
setUser({ commit }: ActionContext<IState, IState>, payload: IUser) {
|
||||
commit('setUser', payload);
|
||||
},
|
||||
setSetting({ commit }: ActionContext<IState, IState>, payload: ISetting) {
|
||||
commit('setSetting', payload);
|
||||
},
|
||||
setActiveApiId({ commit }: ActionContext<IState, IState>, payload: string) {
|
||||
commit('setActiveApiId', payload);
|
||||
},
|
||||
setConversations({ commit }: ActionContext<IState, IState>, payload: IConversation[]) {
|
||||
commit('setConversations', payload);
|
||||
},
|
||||
getMe({ commit }: ActionContext<IState, IState>) {
|
||||
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()]
|
||||
|
||||
+3
-44
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user