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'
|
version: '3'
|
||||||
services:
|
services:
|
||||||
zhishuyun-chat-frontend:
|
zhishuyun-ai-frontend:
|
||||||
container_name: 'zhishuyun-chat-frontend'
|
container_name: 'zhishuyun-ai-frontend'
|
||||||
build: ./
|
build: ./
|
||||||
image: 'ghcr.io/zhishuyun/chat-frontend:${BUILD_NUMBER}'
|
image: 'ghcr.io/zhishuyun/ai-frontend:${BUILD_NUMBER}'
|
||||||
ports:
|
ports:
|
||||||
- '8086:80'
|
- '8000:80'
|
||||||
@@ -3,14 +3,6 @@ server {
|
|||||||
server_name localhost;
|
server_name localhost;
|
||||||
proxy_http_version 1.1;
|
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/ {
|
location /api/v1/ {
|
||||||
proxy_pass http://data-backend:8000;
|
proxy_pass http://data-backend:8000;
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-5
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "zhishuyun-data",
|
"name": "zhishuyun-ai",
|
||||||
"version": "0.1.0",
|
"version": "0.1.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "cross-env NODE_ENV=$npm_config_env vite --host",
|
"start": "cross-env NODE_ENV=$npm_config_env vite --host",
|
||||||
@@ -9,10 +9,7 @@
|
|||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"serve": "vite preview",
|
"serve": "vite preview",
|
||||||
"lint": "npx eslint src --fix --ext .ts,.tsx,.vue,.js,.jsx",
|
"lint": "npx eslint src --fix --ext .ts,.tsx,.vue,.js,.jsx",
|
||||||
"prettier": "npx prettier --write .",
|
"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"
|
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@codemirror/lang-java": "^6.0.1",
|
"@codemirror/lang-java": "^6.0.1",
|
||||||
|
|||||||
+1
-21
@@ -8,7 +8,6 @@
|
|||||||
import { defineComponent } from 'vue';
|
import { defineComponent } from 'vue';
|
||||||
import { ElConfigProvider } from 'element-plus';
|
import { ElConfigProvider } from 'element-plus';
|
||||||
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';
|
import zhCn from 'element-plus/dist/locale/zh-cn.mjs';
|
||||||
import { authOperator } from './operators/auth/operator';
|
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: {
|
components: {
|
||||||
@@ -19,25 +18,6 @@ export default defineComponent({
|
|||||||
locale: zhCn
|
locale: zhCn
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
async mounted() {
|
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');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
</script>
|
</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_LOGIN = 'auth-login';
|
||||||
export const ROUTE_AUTH_CALLBACK = 'auth-callback';
|
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_NEW = 'conversation-new';
|
||||||
export const ROUTE_CONVERSATION_DETAIL = 'conversation-detail';
|
export const ROUTE_CONVERSATION_DETAIL = 'conversation-detail';
|
||||||
+2
-17
@@ -2,6 +2,7 @@ import { createRouter, createWebHistory } from 'vue-router';
|
|||||||
import auth from './auth';
|
import auth from './auth';
|
||||||
import conversation from './conversation';
|
import conversation from './conversation';
|
||||||
import store from '@/store';
|
import store from '@/store';
|
||||||
|
import chat from './chat';
|
||||||
import { ROUTE_AUTH_LOGIN, ROUTE_CONVERSATION_NEW, ROUTE_INDEX } from './constants';
|
import { ROUTE_AUTH_LOGIN, ROUTE_CONVERSATION_NEW, ROUTE_INDEX } from './constants';
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
@@ -12,8 +13,7 @@ const routes = [
|
|||||||
name: ROUTE_CONVERSATION_NEW
|
name: ROUTE_CONVERSATION_NEW
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
auth,
|
chat
|
||||||
conversation
|
|
||||||
];
|
];
|
||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
@@ -21,21 +21,6 @@ const router = createRouter({
|
|||||||
routes
|
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 default router;
|
||||||
|
|
||||||
export * from './constants';
|
export * from './constants';
|
||||||
+1
-59
@@ -1,9 +1,7 @@
|
|||||||
import { createStore, ActionContext } from 'vuex';
|
import { createStore, ActionContext } from 'vuex';
|
||||||
import createPersistedState from 'vuex-persistedstate';
|
import createPersistedState from 'vuex-persistedstate';
|
||||||
import { userOperator, IUser } from '@/operators';
|
|
||||||
import { removeCookies } from '@/utils/cookie';
|
import { removeCookies } from '@/utils/cookie';
|
||||||
import { IConversation } from '@/operators/conversation/models';
|
import { ENDPOINT } from '@/constants';
|
||||||
import { DEFAULT_API, ENDPOINT } from '@/constants';
|
|
||||||
|
|
||||||
export interface ISetting {
|
export interface ISetting {
|
||||||
stream?: boolean;
|
stream?: boolean;
|
||||||
@@ -12,10 +10,6 @@ export interface ISetting {
|
|||||||
|
|
||||||
export interface IState {
|
export interface IState {
|
||||||
accessToken: string | undefined;
|
accessToken: string | undefined;
|
||||||
refreshToken: string | undefined;
|
|
||||||
user: IUser | undefined;
|
|
||||||
activeApiId: string | undefined;
|
|
||||||
conversations: IConversation[];
|
|
||||||
setting: ISetting;
|
setting: ISetting;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,10 +17,6 @@ const store = createStore({
|
|||||||
state(): IState {
|
state(): IState {
|
||||||
return {
|
return {
|
||||||
accessToken: undefined,
|
accessToken: undefined,
|
||||||
refreshToken: undefined,
|
|
||||||
user: undefined,
|
|
||||||
activeApiId: DEFAULT_API.id,
|
|
||||||
conversations: [],
|
|
||||||
setting: {
|
setting: {
|
||||||
endpoint: ENDPOINT,
|
endpoint: ENDPOINT,
|
||||||
stream: false
|
stream: false
|
||||||
@@ -37,59 +27,23 @@ const store = createStore({
|
|||||||
setAccessToken(state: IState, payload: string): void {
|
setAccessToken(state: IState, payload: string): void {
|
||||||
state.accessToken = payload;
|
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 {
|
setSetting(state: IState, payload: ISetting): void {
|
||||||
state.setting = {
|
state.setting = {
|
||||||
...state.setting,
|
...state.setting,
|
||||||
...payload
|
...payload
|
||||||
};
|
};
|
||||||
},
|
|
||||||
setConversations(state: IState, payload: IConversation[]): void {
|
|
||||||
state.conversations = payload;
|
|
||||||
},
|
|
||||||
setActiveApiId(state: IState, payload: string): void {
|
|
||||||
state.activeApiId = payload;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
resetAuth({ commit }) {
|
resetAuth({ commit }) {
|
||||||
commit('setRefreshToken', undefined);
|
|
||||||
commit('setAccessToken', undefined);
|
commit('setAccessToken', undefined);
|
||||||
commit('setUser', undefined);
|
|
||||||
removeCookies();
|
removeCookies();
|
||||||
},
|
},
|
||||||
setRefreshToken({ commit }: ActionContext<IState, IState>, payload: string) {
|
|
||||||
commit('setRefreshToken', payload);
|
|
||||||
},
|
|
||||||
setAccessToken({ commit }: ActionContext<IState, IState>, payload: string) {
|
setAccessToken({ commit }: ActionContext<IState, IState>, payload: string) {
|
||||||
commit('setAccessToken', payload);
|
commit('setAccessToken', payload);
|
||||||
},
|
},
|
||||||
setUser({ commit }: ActionContext<IState, IState>, payload: IUser) {
|
|
||||||
commit('setUser', payload);
|
|
||||||
},
|
|
||||||
setSetting({ commit }: ActionContext<IState, IState>, payload: ISetting) {
|
setSetting({ commit }: ActionContext<IState, IState>, payload: ISetting) {
|
||||||
commit('setSetting', payload);
|
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: {
|
getters: {
|
||||||
@@ -99,20 +53,8 @@ const store = createStore({
|
|||||||
accessToken(state): string | undefined {
|
accessToken(state): string | undefined {
|
||||||
return state.accessToken;
|
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 {
|
setting(state): ISetting | undefined {
|
||||||
return state.setting;
|
return state.setting;
|
||||||
},
|
|
||||||
conversations(state): IConversation[] {
|
|
||||||
return state.conversations || [];
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
plugins: [createPersistedState()]
|
plugins: [createPersistedState()]
|
||||||
|
|||||||
+3
-44
@@ -3,55 +3,14 @@ import vue from '@vitejs/plugin-vue';
|
|||||||
import replace from '@rollup/plugin-replace';
|
import replace from '@rollup/plugin-replace';
|
||||||
import { string } from 'rollup-plugin-string';
|
import { string } from 'rollup-plugin-string';
|
||||||
import * as path from 'path';
|
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({
|
export default defineConfig({
|
||||||
server: {
|
server: {
|
||||||
host: 'chat.local.zhishuyun.com',
|
host: 'localhost',
|
||||||
port: 443,
|
port: 8080,
|
||||||
https: {
|
|
||||||
key: fs.readFileSync('certs/chat.local.zhishuyun.com.cert.key'),
|
|
||||||
cert: fs.readFileSync('certs/chat.local.zhishuyun.com.cert.crt')
|
|
||||||
},
|
|
||||||
proxy: {
|
proxy: {
|
||||||
'/api/v1/me': {
|
|
||||||
target: getAuthEndpoint(),
|
|
||||||
changeOrigin: true
|
|
||||||
},
|
|
||||||
'/api/v1/token': {
|
|
||||||
target: getAuthEndpoint(),
|
|
||||||
changeOrigin: true
|
|
||||||
},
|
|
||||||
'/api': {
|
'/api': {
|
||||||
target: getDataEndpoint(),
|
target: 'https://data.zhishuyun.com',
|
||||||
changeOrigin: true
|
|
||||||
},
|
|
||||||
'/static': {
|
|
||||||
target: getDataEndpoint(),
|
|
||||||
changeOrigin: true
|
changeOrigin: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user