integrate api
This commit is contained in:
1 parent
ddd3910e7d
commit
7880b1d5d0
10 files changed
+293
-34
No files matched your search
+26
-21
@@ -2,45 +2,47 @@ import { createStore, ActionContext } from 'vuex';
|
||||
import createPersistedState from 'vuex-persistedstate';
|
||||
import { removeCookies } from '@/utils/cookie';
|
||||
import { ENDPOINT } from '@/constants';
|
||||
|
||||
export interface ISetting {
|
||||
stream?: boolean;
|
||||
endpoint?: string;
|
||||
}
|
||||
|
||||
export interface IState {
|
||||
accessToken: string | undefined;
|
||||
setting: ISetting;
|
||||
}
|
||||
import { IApplication } from '@/operators';
|
||||
import { ISetting, IState, IToken } from './models';
|
||||
|
||||
const store = createStore({
|
||||
state(): IState {
|
||||
return {
|
||||
accessToken: undefined,
|
||||
token: {
|
||||
access: undefined,
|
||||
refresh: undefined
|
||||
},
|
||||
setting: {
|
||||
endpoint: ENDPOINT,
|
||||
stream: false
|
||||
}
|
||||
},
|
||||
applications: []
|
||||
};
|
||||
},
|
||||
mutations: {
|
||||
setAccessToken(state: IState, payload: string): void {
|
||||
state.accessToken = payload;
|
||||
setToken(state: IState, payload: IToken): void {
|
||||
state.token = {
|
||||
...state.token,
|
||||
...payload
|
||||
};
|
||||
},
|
||||
setSetting(state: IState, payload: ISetting): void {
|
||||
state.setting = {
|
||||
...state.setting,
|
||||
...payload
|
||||
};
|
||||
},
|
||||
setApplications(state: IState, payload: IApplication[]): void {
|
||||
state.applications = payload;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
resetAuth({ commit }) {
|
||||
commit('setAccessToken', undefined);
|
||||
resetToken({ commit }) {
|
||||
commit('setToken', {});
|
||||
removeCookies();
|
||||
},
|
||||
setAccessToken({ commit }: ActionContext<IState, IState>, payload: string) {
|
||||
commit('setAccessToken', payload);
|
||||
setToken({ commit }: ActionContext<IState, IState>, payload: IToken) {
|
||||
commit('setToken', payload);
|
||||
},
|
||||
setSetting({ commit }: ActionContext<IState, IState>, payload: ISetting) {
|
||||
commit('setSetting', payload);
|
||||
@@ -48,13 +50,16 @@ const store = createStore({
|
||||
},
|
||||
getters: {
|
||||
authenticated(state): boolean {
|
||||
return !!state.accessToken;
|
||||
return !!state.token.access;
|
||||
},
|
||||
accessToken(state): string | undefined {
|
||||
return state.accessToken;
|
||||
token(state): IToken {
|
||||
return state.token;
|
||||
},
|
||||
setting(state): ISetting | undefined {
|
||||
return state.setting;
|
||||
},
|
||||
applications(state): IApplication[] | undefined {
|
||||
return state.applications;
|
||||
}
|
||||
},
|
||||
plugins: [createPersistedState()]
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
export interface IToken {
|
||||
access?: string;
|
||||
refresh?: string;
|
||||
}
|
||||
|
||||
export interface ISetting {
|
||||
stream?: boolean;
|
||||
endpoint?: string;
|
||||
}
|
||||
|
||||
export enum IApplicationType {
|
||||
API = 'Api',
|
||||
PROXY = 'Proxy'
|
||||
}
|
||||
|
||||
export enum ICredentialType {
|
||||
TOKEN = 'Token',
|
||||
IDENTITY = 'Identity'
|
||||
}
|
||||
|
||||
export interface ICredential {
|
||||
type: ICredentialType;
|
||||
name?: string;
|
||||
token?: string;
|
||||
username?: string;
|
||||
password?: string;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface IApplication {
|
||||
id?: string;
|
||||
type?: IApplicationType;
|
||||
api_id?: string;
|
||||
proxy_id?: string;
|
||||
api_key?: string;
|
||||
user_id?: string;
|
||||
remaining_amount?: number;
|
||||
used_amount?: number;
|
||||
credential?: ICredential;
|
||||
created_at?: string;
|
||||
updated_at?: string;
|
||||
}
|
||||
|
||||
export interface IState {
|
||||
token: IToken;
|
||||
setting: ISetting;
|
||||
applications: IApplication[];
|
||||
}
|
||||
Reference in new issue
Block a user