Fix auth and experience issue (#87)
Co-authored-by: Germey <germey@acedata.cloud>
This commit is contained in:
1 parent
c7c755fcd6
commit
558eadb63c
24 files changed
+235
-427
No files matched your search
+15
-14
@@ -1,7 +1,6 @@
|
||||
import { applicationOperator, chatOperator, serviceOperator } from '@/operators';
|
||||
import { IRootState } from '../common/models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IChatState } from './models';
|
||||
import { IApplication, IChatConversation, IChatModel, ICredential, IService, Status } from '@/models';
|
||||
import { CHAT_SERVICE_ID } from '@/constants';
|
||||
@@ -15,27 +14,27 @@ export const setModel = async ({ commit }: any, payload: IChatModel): Promise<vo
|
||||
};
|
||||
|
||||
export const setApplication = async ({ commit }: any, payload: IApplication): Promise<void> => {
|
||||
log(setApplication, 'set application', payload);
|
||||
console.debug('set application', payload);
|
||||
commit('setApplication', payload);
|
||||
};
|
||||
|
||||
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
|
||||
log(setService, 'set service', payload);
|
||||
console.debug('set service', payload);
|
||||
commit('setService', payload);
|
||||
};
|
||||
|
||||
export const setConversations = async ({ commit }: any, payload: IChatConversation[]): Promise<void> => {
|
||||
log(setConversations, 'set conversations', payload);
|
||||
console.debug('set conversations', payload);
|
||||
commit('setConversations', payload);
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
log(setCredential, 'set credential', payload);
|
||||
console.debug('set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
export const setConversation = async ({ commit, state }: any, payload: IChatConversation): Promise<void> => {
|
||||
log(setConversation, 'set conversation', payload);
|
||||
console.debug('set conversation', payload);
|
||||
const conversations = state.conversations || [];
|
||||
const index = conversations?.findIndex((conversation: IChatConversation) => conversation.id === payload.id);
|
||||
if (index > -1) {
|
||||
@@ -44,12 +43,12 @@ export const setConversation = async ({ commit, state }: any, payload: IChatConv
|
||||
conversations?.unshift(payload);
|
||||
}
|
||||
commit('setConversations', conversations);
|
||||
log(setConversation, 'set conversation success', conversations);
|
||||
console.debug('set conversation success', conversations);
|
||||
};
|
||||
|
||||
export const getService = async ({ commit, state }: ActionContext<IChatState, IRootState>): Promise<IService> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getService, 'start to get service for chat');
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get service for chat');
|
||||
state.status.getService = Status.Request;
|
||||
serviceOperator
|
||||
.get(CHAT_SERVICE_ID)
|
||||
@@ -70,8 +69,8 @@ export const getApplication = async ({
|
||||
state,
|
||||
rootState
|
||||
}: ActionContext<IChatState, IRootState>): Promise<IApplication> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getApplication, 'start to get application for chat');
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get application for chat');
|
||||
state.status.getApplication = Status.Request;
|
||||
applicationOperator
|
||||
.getAll({
|
||||
@@ -79,6 +78,7 @@ export const getApplication = async ({
|
||||
service_id: CHAT_SERVICE_ID
|
||||
})
|
||||
.then((response) => {
|
||||
console.debug('get application success', response?.data);
|
||||
state.status.getApplication = Status.Success;
|
||||
commit('setApplication', response.data.items[0]);
|
||||
const credential = response.data.items?.[0]?.credentials?.find(
|
||||
@@ -86,6 +86,7 @@ export const getApplication = async ({
|
||||
);
|
||||
commit('setCredential', credential);
|
||||
resolve(response.data.items[0]);
|
||||
console.debug('save application success', response.data.items[0]);
|
||||
})
|
||||
.catch((error) => {
|
||||
state.status.getApplication = Status.Error;
|
||||
@@ -98,10 +99,10 @@ export const getConversations = async ({
|
||||
commit,
|
||||
state
|
||||
}: ActionContext<IChatState, IRootState>): Promise<IChatConversation[]> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
state.status.getConversations = Status.Request;
|
||||
const credential = state.credential;
|
||||
log(getConversations, 'credential', credential);
|
||||
console.debug('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
state.status.getConversations = Status.Error;
|
||||
@@ -117,7 +118,7 @@ export const getConversations = async ({
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
log(getConversations, 'get conversations success', response.data?.items?.length);
|
||||
console.debug('get conversations success', response.data?.items?.length);
|
||||
commit('setConversations', response.data.items);
|
||||
const conversations = response.data.items;
|
||||
resolve(conversations);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { IRootState } from '../common/models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IChatdocState } from './models';
|
||||
import {
|
||||
IApplication,
|
||||
@@ -20,12 +19,12 @@ export const setApplication = async ({ commit }: any, payload: IApplication): Pr
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
log(setCredential, 'set credential', payload);
|
||||
console.debug('set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
|
||||
log(setService, 'set service', payload);
|
||||
console.debug('set service', payload);
|
||||
commit('setService', payload);
|
||||
};
|
||||
|
||||
@@ -69,7 +68,7 @@ export const getRepositories = async ({
|
||||
commit,
|
||||
state
|
||||
}: ActionContext<IChatdocState, IRootState>): Promise<IChatdocRepository[]> => {
|
||||
log(getRepositories, 'start to get repositories');
|
||||
console.debug('start to get repositories');
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
@@ -82,7 +81,7 @@ export const getRepositories = async ({
|
||||
token
|
||||
})
|
||||
).data.items;
|
||||
log(getRepositories, 'get repositories success', repositories);
|
||||
console.debug('get repositories success', repositories);
|
||||
commit('setRepositories', repositories);
|
||||
return repositories;
|
||||
};
|
||||
@@ -93,7 +92,7 @@ export const deleteRepository = async (
|
||||
id: string;
|
||||
}
|
||||
): Promise<IChatdocRepository> => {
|
||||
log(deleteRepository, 'start to delete repository');
|
||||
console.debug('start to delete repository');
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
@@ -105,7 +104,7 @@ export const deleteRepository = async (
|
||||
token
|
||||
})
|
||||
).data;
|
||||
log(deleteRepository, 'delete repository success', repository);
|
||||
console.debug('delete repository success', repository);
|
||||
return repository;
|
||||
};
|
||||
|
||||
@@ -115,7 +114,7 @@ export const deleteDocument = async (
|
||||
id: string;
|
||||
}
|
||||
): Promise<IChatdocDocument> => {
|
||||
log(deleteDocument, 'start to delete document');
|
||||
console.debug('start to delete document');
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
@@ -127,13 +126,13 @@ export const deleteDocument = async (
|
||||
token
|
||||
})
|
||||
).data;
|
||||
log(deleteRepository, 'delete document success', document);
|
||||
console.debug('delete document success', document);
|
||||
return document;
|
||||
};
|
||||
|
||||
export const getService = async ({ commit, state }: ActionContext<IChatdocState, IRootState>): Promise<IService> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getService, 'start to get service for chatdoc');
|
||||
console.debug('start to get service for chatdoc');
|
||||
state.status.getService = Status.Request;
|
||||
serviceOperator
|
||||
.get(CHATDOC_SERVICE_ID)
|
||||
@@ -156,7 +155,7 @@ export const createRepository = async (
|
||||
description?: string;
|
||||
}
|
||||
): Promise<IChatdocRepository> => {
|
||||
log(createRepository, 'start to create repository');
|
||||
console.debug('start to create repository');
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
@@ -168,7 +167,7 @@ export const createRepository = async (
|
||||
token
|
||||
})
|
||||
).data;
|
||||
log(createRepository, 'create repository success', repository);
|
||||
console.debug('create repository success', repository);
|
||||
return repository;
|
||||
};
|
||||
|
||||
@@ -180,7 +179,7 @@ export const createDocument = async (
|
||||
fileName: string;
|
||||
}
|
||||
): Promise<IChatdocDocument> => {
|
||||
log(createDocument, 'start to create document');
|
||||
console.debug('start to create document');
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
@@ -192,7 +191,7 @@ export const createDocument = async (
|
||||
token
|
||||
})
|
||||
).data;
|
||||
log(createDocument, 'create document success', document);
|
||||
console.debug('create document success', document);
|
||||
return document;
|
||||
};
|
||||
|
||||
@@ -204,7 +203,7 @@ export const setConversation = async (
|
||||
repositoryId: string;
|
||||
}
|
||||
): Promise<void> => {
|
||||
log(setConversation, 'set conversation', payload);
|
||||
console.debug('set conversation', payload);
|
||||
const repository: IChatdocRepository | undefined = state.repositories.find(
|
||||
(repository: IChatdocRepository) => repository.id === payload.repositoryId
|
||||
);
|
||||
@@ -216,14 +215,14 @@ export const setConversation = async (
|
||||
if (index > -1) {
|
||||
conversations[index].messages = payload.messages;
|
||||
}
|
||||
log(setConversation, 'set conversation success', conversations);
|
||||
console.debug('set conversation success', conversations);
|
||||
};
|
||||
|
||||
export const getDocuments = async (
|
||||
{ commit, state }: ActionContext<IChatdocState, IRootState>,
|
||||
payload: { repositoryId: string }
|
||||
): Promise<IChatdocDocument[]> => {
|
||||
log(getRepositories, 'start to get documents');
|
||||
console.debug('start to get documents');
|
||||
const credential = state.credential;
|
||||
console.log('credential for getDocuments', credential);
|
||||
const token = credential?.token;
|
||||
@@ -239,7 +238,7 @@ export const getDocuments = async (
|
||||
token
|
||||
})
|
||||
).data.items;
|
||||
log(getRepositories, 'get documents success', documents);
|
||||
console.debug('get documents success', documents);
|
||||
commit('setRepository', {
|
||||
id: payload.repositoryId,
|
||||
documents: documents
|
||||
@@ -251,7 +250,7 @@ export const getConversations = async (
|
||||
{ commit, state }: ActionContext<IChatdocState, IRootState>,
|
||||
payload: { repositoryId: string }
|
||||
): Promise<IChatdocConversation[]> => {
|
||||
log(getConversations, 'start to get conversations');
|
||||
console.debug('start to get conversations');
|
||||
const credential = state.credential;
|
||||
console.log('credential for getConversations', credential);
|
||||
const token = credential?.token;
|
||||
@@ -267,7 +266,7 @@ export const getConversations = async (
|
||||
token
|
||||
})
|
||||
).data.items;
|
||||
log(getConversations, 'get conversations success', conversations);
|
||||
console.debug('get conversations success', conversations);
|
||||
commit('setRepository', {
|
||||
id: payload.repositoryId,
|
||||
conversations: conversations
|
||||
@@ -279,7 +278,7 @@ export const getRepository = async (
|
||||
{ commit, state }: ActionContext<IChatdocState, IRootState>,
|
||||
payload: { id: string }
|
||||
): Promise<IChatdocRepository> => {
|
||||
log(getRepository, 'start to get repository');
|
||||
console.debug('start to get repository');
|
||||
const credential = state.credential;
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
@@ -291,7 +290,7 @@ export const getRepository = async (
|
||||
token
|
||||
})
|
||||
).data;
|
||||
log(getRepository, 'get repository success', repository);
|
||||
console.debug('get repository success', repository);
|
||||
commit('setRepository', repository);
|
||||
return repository;
|
||||
};
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { IApplication, IChatdocRepository, ICredential, IService } from '@/models';
|
||||
import { IChatdocState } from './models';
|
||||
import { log } from '@/utils';
|
||||
|
||||
export const resetAll = (state: IChatdocState): void => {
|
||||
state.application = undefined;
|
||||
@@ -41,20 +40,20 @@ export const setCredential = (state: IChatdocState, payload: ICredential): void
|
||||
};
|
||||
|
||||
export const setRepository = (state: IChatdocState, payload: IChatdocRepository): void => {
|
||||
log(setRepository, 'mutation', payload);
|
||||
console.debug('mutation', payload);
|
||||
// find the repository and set it
|
||||
const repository = payload;
|
||||
const repositories = state.repositories;
|
||||
if (!repositories) {
|
||||
log(setRepository, 'no repositories');
|
||||
console.debug('no repositories');
|
||||
return;
|
||||
}
|
||||
const index = repositories.findIndex((item: IChatdocRepository) => item.id === repository.id);
|
||||
if (index === -1) {
|
||||
log(setRepository, 'no repository found');
|
||||
console.debug('no repository found');
|
||||
return;
|
||||
}
|
||||
log(setRepository, 'set repository for index', index, repository);
|
||||
console.debug('set repository for index', index, repository);
|
||||
repositories[index] = {
|
||||
...repositories[index],
|
||||
...repository
|
||||
|
||||
+25
-23
@@ -1,7 +1,6 @@
|
||||
import { ActionContext } from 'vuex';
|
||||
import { IRootState } from '../common/models';
|
||||
import { userOperator, oauthOperator, siteOperator, exchangeOperator } from '@/operators';
|
||||
import { log } from '@/utils/log';
|
||||
import { IToken, IUser } from '@/models';
|
||||
import { getSiteOrigin } from '@/utils/site';
|
||||
import { login as authLogin } from '@/utils';
|
||||
@@ -40,33 +39,36 @@ export const setExchange = ({ commit }: ActionContext<IRootState, IRootState>, p
|
||||
};
|
||||
|
||||
export const getUser = async ({ commit }: ActionContext<IRootState, IRootState>): Promise<IUser> => {
|
||||
log(getUser, 'start to get user');
|
||||
console.debug('start to get user');
|
||||
try {
|
||||
commit('resetUser');
|
||||
const { data: user } = await userOperator.getMe();
|
||||
commit('setUser', user);
|
||||
log(getUser, 'get user success', user);
|
||||
console.debug('get user success', user);
|
||||
return user;
|
||||
} catch (error) {
|
||||
log(getUser, 'get user failed', error);
|
||||
console.error('get user failed', error);
|
||||
}
|
||||
};
|
||||
|
||||
export const getToken = async ({ commit }: ActionContext<IRootState, IRootState>, code: string): Promise<IToken> => {
|
||||
log(getToken, 'start to get token using code', code);
|
||||
console.debug('start to get token using code', code);
|
||||
try {
|
||||
commit('resetToken');
|
||||
const { data } = await oauthOperator.token({
|
||||
code
|
||||
});
|
||||
console.debug('get token success', data);
|
||||
const token = {
|
||||
access: data.access_token,
|
||||
refresh: data.refresh_token,
|
||||
expiration: data.expires_in
|
||||
};
|
||||
commit('setToken', token);
|
||||
log(getToken, 'get token success', data);
|
||||
console.debug('get token success', data);
|
||||
return token;
|
||||
} catch (error) {
|
||||
log(getToken, 'get token failed', error);
|
||||
console.error('get token failed', error);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -78,34 +80,34 @@ export const getExchangeRate = async (
|
||||
return;
|
||||
}
|
||||
const key = `${payload.source}-${payload.target}`;
|
||||
if (!state.exchange || !state.exchange[key]) {
|
||||
try {
|
||||
const { data } = await exchangeOperator.rate(payload);
|
||||
commit('setExchange', {
|
||||
[key]: data.rate
|
||||
});
|
||||
return state.exchange![key];
|
||||
} catch (e) {
|
||||
log(getExchangeRate, 'get exchange rate failed');
|
||||
}
|
||||
console.debug('start to get exchange rate', key);
|
||||
try {
|
||||
const { data } = await exchangeOperator.rate(payload);
|
||||
console.debug('get exchange rate success', data);
|
||||
commit('setExchange', {
|
||||
[key]: data.rate
|
||||
});
|
||||
return state.exchange![key];
|
||||
} catch (e) {
|
||||
console.error('get exchange rate failed');
|
||||
}
|
||||
};
|
||||
|
||||
export const initializeSite = async ({ state, commit, dispatch }: ActionContext<IRootState, IRootState>) => {
|
||||
log(initializeSite, 'start to initialize site');
|
||||
console.debug('start to initialize site');
|
||||
const origin = getSiteOrigin(state?.site);
|
||||
try {
|
||||
const { data } = await siteOperator.initialize({ origin });
|
||||
commit('setSite', data);
|
||||
log(initializeSite, 'initialize site success', data);
|
||||
console.debug('initialize site success', data);
|
||||
} catch (error) {
|
||||
log(initializeSite, 'initialize site failed', error);
|
||||
console.error('initialize site failed', error);
|
||||
dispatch('login');
|
||||
}
|
||||
};
|
||||
|
||||
export const getSite = async ({ state, commit }: ActionContext<IRootState, IRootState>) => {
|
||||
log(getSite, 'start to get site');
|
||||
console.debug('start to get site');
|
||||
try {
|
||||
const origin = getSiteOrigin(state?.site);
|
||||
const site = (
|
||||
@@ -114,9 +116,9 @@ export const getSite = async ({ state, commit }: ActionContext<IRootState, IRoot
|
||||
})
|
||||
)?.data?.items?.[0];
|
||||
commit('setSite', site);
|
||||
log(getSite, 'get site success', site);
|
||||
console.debug('get site success', site);
|
||||
} catch (error) {
|
||||
log(getSite, 'get site failed', error);
|
||||
console.error('get site failed', error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import chatState from '../chat/state';
|
||||
import midjourneyState from '../midjourney/state';
|
||||
import chatdocState from '../chatdoc/state';
|
||||
import qrartState from '../qrart/state';
|
||||
import sunoState from '../suno/state';
|
||||
|
||||
export default (): IRootState => {
|
||||
return {
|
||||
@@ -19,6 +20,7 @@ export default (): IRootState => {
|
||||
chatdoc: chatdocState(),
|
||||
chat: chatState(),
|
||||
midjourney: midjourneyState(),
|
||||
qrart: qrartState()
|
||||
qrart: qrartState(),
|
||||
suno: sunoState()
|
||||
};
|
||||
};
|
||||
@@ -1,7 +1,6 @@
|
||||
import { applicationOperator, midjourneyOperator, serviceOperator } from '@/operators';
|
||||
import { IMidjourneyState } from './models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IRootState } from '../common/models';
|
||||
import {
|
||||
IApplication,
|
||||
@@ -19,7 +18,7 @@ export const resetAll = ({ commit }: ActionContext<IMidjourneyState, IRootState>
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
log(setCredential, 'set credential', payload);
|
||||
console.debug(setCredential, 'set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
@@ -32,7 +31,7 @@ export const setMode = ({ commit }: any, payload: string) => {
|
||||
};
|
||||
|
||||
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
|
||||
log(setService, 'set service', payload);
|
||||
console.debug('set service', payload);
|
||||
commit('setService', payload);
|
||||
};
|
||||
|
||||
@@ -45,8 +44,8 @@ export const getApplication = async ({
|
||||
state,
|
||||
rootState
|
||||
}: ActionContext<IMidjourneyState, IRootState>): Promise<IApplication> => {
|
||||
log(getApplication, 'start to get application for midjourney');
|
||||
return new Promise(async (resolve, reject) => {
|
||||
console.debug('start to get application for midjourney');
|
||||
return new Promise((resolve, reject) => {
|
||||
state.status.getApplication = Status.Request;
|
||||
applicationOperator
|
||||
.getAll({
|
||||
@@ -54,6 +53,7 @@ export const getApplication = async ({
|
||||
service_id: MIDJOURNEY_SERVICE_ID
|
||||
})
|
||||
.then((response) => {
|
||||
console.debug('get application success', response?.data);
|
||||
state.status.getApplication = Status.Success;
|
||||
commit('setApplication', response.data.items[0]);
|
||||
const credential = response.data.items?.[0]?.credentials?.find(
|
||||
@@ -61,6 +61,7 @@ export const getApplication = async ({
|
||||
);
|
||||
commit('setCredential', credential);
|
||||
resolve(response.data.items[0]);
|
||||
console.debug('save application success', response.data.items[0]);
|
||||
})
|
||||
.catch((error) => {
|
||||
state.status.getApplication = Status.Error;
|
||||
@@ -74,8 +75,8 @@ export const setTasks = ({ commit }: any, payload: IMidjourneyTask[]) => {
|
||||
};
|
||||
|
||||
export const getService = async ({ commit, state }: ActionContext<IMidjourneyState, IRootState>): Promise<IService> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getService, 'start to get service for midjourney');
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get service for midjourney');
|
||||
state.status.getService = Status.Request;
|
||||
serviceOperator
|
||||
.get(MIDJOURNEY_SERVICE_ID)
|
||||
@@ -95,8 +96,8 @@ export const getTasks = async (
|
||||
{ commit, state }: ActionContext<IMidjourneyState, IRootState>,
|
||||
{ offset, limit }: { offset?: number; limit?: number }
|
||||
): Promise<IMidjourneyTasksResponse> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getTasks, 'start to get tasks', offset, limit);
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get tasks', offset, limit);
|
||||
const credential = state.credential;
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
@@ -114,7 +115,7 @@ export const getTasks = async (
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
log(getTasks, 'get tasks success', response.data);
|
||||
console.debug('get tasks success', response.data);
|
||||
commit('setTasks', response.data);
|
||||
resolve(response.data);
|
||||
})
|
||||
|
||||
+13
-10
@@ -1,7 +1,6 @@
|
||||
import { applicationOperator, qrartOperator, serviceOperator } from '@/operators';
|
||||
import { IQrartState } from './models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IRootState } from '../common/models';
|
||||
import { IApplication, ICredential, IQrartConfig, IQrartTask, IService } from '@/models';
|
||||
import { Status } from '@/models/common';
|
||||
@@ -12,7 +11,7 @@ export const resetAll = ({ commit }: ActionContext<IQrartState, IRootState>): vo
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
log(setCredential, 'set credential', payload);
|
||||
console.debug('set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
@@ -21,7 +20,7 @@ export const setConfig = ({ commit }: any, payload: IQrartConfig) => {
|
||||
};
|
||||
|
||||
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
|
||||
log(setService, 'set service', payload);
|
||||
console.debug('set service', payload);
|
||||
commit('setService', payload);
|
||||
};
|
||||
|
||||
@@ -34,8 +33,8 @@ export const getApplication = async ({
|
||||
state,
|
||||
rootState
|
||||
}: ActionContext<IQrartState, IRootState>): Promise<IApplication> => {
|
||||
log(getApplication, 'start to get application for qrart');
|
||||
return new Promise(async (resolve, reject) => {
|
||||
console.debug('start to get application for qrart');
|
||||
return new Promise((resolve, reject) => {
|
||||
state.status.getApplication = Status.Request;
|
||||
applicationOperator
|
||||
.getAll({
|
||||
@@ -43,15 +42,19 @@ export const getApplication = async ({
|
||||
service_id: QRART_SERVICE_ID
|
||||
})
|
||||
.then((response) => {
|
||||
console.debug('get application success', response?.data);
|
||||
state.status.getApplication = Status.Success;
|
||||
commit('setApplication', response.data.items[0]);
|
||||
const credential = response.data.items?.[0]?.credentials?.find(
|
||||
(credential) => credential?.host === window.location.origin
|
||||
);
|
||||
console.debug('get credential success', credential);
|
||||
commit('setCredential', credential);
|
||||
resolve(response.data.items[0]);
|
||||
console.debug('save application success', response.data.items[0]);
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error('get application error', error);
|
||||
state.status.getApplication = Status.Error;
|
||||
reject(error);
|
||||
});
|
||||
@@ -75,8 +78,8 @@ export const setTasksActive = ({ commit }: any, payload: IQrartTask) => {
|
||||
};
|
||||
|
||||
export const getService = async ({ commit, state }: ActionContext<IQrartState, IRootState>): Promise<IService> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getService, 'start to get service for qrart');
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get service for qrart');
|
||||
state.status.getService = Status.Request;
|
||||
serviceOperator
|
||||
.get(QRART_SERVICE_ID)
|
||||
@@ -96,8 +99,8 @@ export const getTasks = async (
|
||||
{ commit, state }: ActionContext<IQrartState, IRootState>,
|
||||
{ offset, limit }: { offset?: number; limit?: number }
|
||||
): Promise<IQrartTask[]> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getTasks, 'start to get tasks', offset, limit);
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get tasks', offset, limit);
|
||||
const credential = state.credential;
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
@@ -113,7 +116,7 @@ export const getTasks = async (
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
log(getTasks, 'get imagine tasks success', response.data.items);
|
||||
console.debug('get imagine tasks success', response.data.items);
|
||||
commit('setTasksItems', response.data.items);
|
||||
commit('setTasksTotal', response.data.count);
|
||||
resolve(response.data.items);
|
||||
|
||||
+10
-11
@@ -1,7 +1,6 @@
|
||||
import { applicationOperator, sunoOperator, serviceOperator } from '@/operators';
|
||||
import { ISunoState } from './models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IRootState } from '../common/models';
|
||||
import { IApplication, ICredential, ISunoConfig, ISunoTask, IService, Song } from '@/models';
|
||||
import { Status } from '@/models/common';
|
||||
@@ -12,7 +11,7 @@ export const resetAll = ({ commit }: ActionContext<ISunoState, IRootState>): voi
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
log(setCredential, 'set credential', payload);
|
||||
console.debug('set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
@@ -21,7 +20,7 @@ export const setConfig = ({ commit }: any, payload: ISunoConfig) => {
|
||||
};
|
||||
|
||||
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
|
||||
log(setService, 'set service', payload);
|
||||
console.debug('set service', payload);
|
||||
commit('setService', payload);
|
||||
};
|
||||
|
||||
@@ -34,8 +33,8 @@ export const getApplication = async ({
|
||||
state,
|
||||
rootState
|
||||
}: ActionContext<ISunoState, IRootState>): Promise<IApplication> => {
|
||||
log(getApplication, 'start to get application for suno');
|
||||
return new Promise(async (resolve, reject) => {
|
||||
console.debug('start to get application for suno');
|
||||
return new Promise((resolve, reject) => {
|
||||
state.status.getApplication = Status.Request;
|
||||
applicationOperator
|
||||
.getAll({
|
||||
@@ -78,9 +77,9 @@ export const setAudio = ({ commit }: any, payload: any) => {
|
||||
commit('setAudio', payload);
|
||||
};
|
||||
|
||||
export const getService = async ({ commit, state }: ActionContext<RootState, IRootState>): Promise<IService> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getService, 'start to get service for suno');
|
||||
export const getService = async ({ commit, state }: ActionContext<ISunoState, IRootState>): Promise<IService> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get service for suno');
|
||||
state.status.getService = Status.Request;
|
||||
serviceOperator
|
||||
.get(SUNO_SERVICE_ID)
|
||||
@@ -100,8 +99,8 @@ export const getTasks = async (
|
||||
{ commit, state }: ActionContext<ISunoState, IRootState>,
|
||||
{ offset, limit }: { offset?: number; limit?: number }
|
||||
): Promise<ISunoTask[]> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getTasks, 'start to get tasks', offset, limit);
|
||||
return new Promise((resolve, reject) => {
|
||||
console.debug('start to get tasks', offset, limit);
|
||||
const credential = state.credential;
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
@@ -117,7 +116,7 @@ export const getTasks = async (
|
||||
}
|
||||
)
|
||||
.then((response) => {
|
||||
log(getTasks, 'get imagine tasks success', response.data.items);
|
||||
console.debug('get imagine tasks success', response.data.items);
|
||||
commit('setTasksItems', response.data.items);
|
||||
commit('setTasksTotal', response.data.count);
|
||||
resolve(response.data.items);
|
||||
|
||||
Reference in new issue
Block a user