Skip to content

Commit

Permalink
fit get applications (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyf-github-user committed Aug 17, 2024
1 parent 7c8a649 commit 5eb453d
Show file tree
Hide file tree
Showing 17 changed files with 113 additions and 35 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "fit getApplications",
"packageName": "@acedatacloud/nexior",
"email": "1348977728@qq.com",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion src/components/chatdoc/UploadDocument.vue
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export default defineComponent({
ElMessage.success(this.$t('chatdoc.message.createDocumentSuccess'));
this.dialogVisible = false;
this.$store.dispatch('chatdoc/getDocuments', { repositoryId: this.$route.params.repositoryId });
this.$store.dispatch('chatdoc/getApplication');
this.$store.dispatch('chatdoc/getApplications');
})
.catch(() => {
ElMessage.error(this.$t('chatdoc.message.createDocumentError'));
Expand Down
2 changes: 1 addition & 1 deletion src/layouts/Chatdoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default defineComponent({
await this.$store.dispatch('chatdoc/getService');
},
async onGetApplications() {
await this.$store.dispatch('chatdoc/getApplication');
await this.$store.dispatch('chatdoc/getApplications');
},
async onGetRepositories() {
await this.$store.dispatch('chatdoc/getRepositories');
Expand Down
2 changes: 1 addition & 1 deletion src/pages/chatdoc/Conversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:application="application"
:need-apply="needApply"
:service="service"
@refresh="$store.dispatch('chatdoc/getApplication')"
@refresh="$store.dispatch('chatdoc/getApplications')"
/>
</div>
<div class="dialogue">
Expand Down
6 changes: 3 additions & 3 deletions src/pages/chatdoc/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
:application="application"
:need-apply="needApply"
:service="service"
@refresh="$store.dispatch('chatdoc/getApplication')"
@refresh="$store.dispatch('chatdoc/getApplications')"
/>
</div>
<el-row class="repositories" :gutter="15">
Expand Down Expand Up @@ -93,7 +93,7 @@ export default defineComponent({
return this.$store.state.chatdoc.repositories;
},
needApply() {
return this.$store.state.chatdoc.status.getApplication === Status.Success && !this.application;
return this.$store.state.chatdoc.status.getApplications === Status.Success && !this.application;
},
application() {
return this.$store.state.chatdoc.application;
Expand All @@ -102,7 +102,7 @@ export default defineComponent({
return this.$store.state.chatdoc.service;
},
initializing() {
return this.$store.state.chatdoc.status.getApplication === Status.Request;
return this.$store.state.chatdoc.status.getApplications === Status.Request;
}
},
async mounted() {},
Expand Down
6 changes: 3 additions & 3 deletions src/pages/chatdoc/Manage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
:application="application"
:need-apply="needApply"
:service="service"
@refresh="$store.dispatch('chatdoc/getApplication')"
@refresh="$store.dispatch('chatdoc/getApplications')"
/>
</div>
<div class="operations">
Expand Down Expand Up @@ -99,7 +99,7 @@ export default defineComponent({
return this.repository?.documents;
},
needApply() {
return this.$store.state.chatdoc.status.getApplication === Status.Success && !this.application;
return this.$store.state.chatdoc.status.getApplications === Status.Success && !this.application;
},
service() {
return this.$store.state.chatdoc.service;
Expand All @@ -108,7 +108,7 @@ export default defineComponent({
return this.$store.state.chatdoc.application;
},
initializing() {
return this.$store.state.chatdoc.status.getApplication === Status.Request;
return this.$store.state.chatdoc.status.getApplications === Status.Request;
}
},
async mounted() {
Expand Down
8 changes: 4 additions & 4 deletions src/pages/luma/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default defineComponent({
},
computed: {
loading() {
return this.$store.state.luma?.status?.getApplication === Status.Request;
return this.$store.state.luma?.status?.getApplications === Status.Request;
},
service() {
return this.$store.state.luma.service;
Expand All @@ -65,10 +65,10 @@ export default defineComponent({
return this.$store.state.luma.config;
},
initializing() {
return this.$store.state.luma.status.getApplication === Status.Request;
return this.$store.state.luma.status.getApplications === Status.Request;
},
needApply() {
return this.$store.state.luma.status.getApplication === Status.Success && !this.application;
return this.$store.state.luma.status.getApplications === Status.Success && !this.application;
},
application() {
return this.$store.state.luma.application;
Expand Down Expand Up @@ -96,7 +96,7 @@ export default defineComponent({
},
async onGetApplication() {
console.debug('start onGetApplication');
await this.$store.dispatch('luma/getApplication');
await this.$store.dispatch('luma/getApplications');
console.debug('end onGetApplication');
await this.onGetTasks();
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/qrart/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default defineComponent({
},
computed: {
loading() {
return this.$store.state.qrart?.status?.getApplication === Status.Request;
return this.$store.state.qrart?.status?.getApplications === Status.Request;
},
service() {
return this.$store.state.qrart.service;
Expand Down
2 changes: 1 addition & 1 deletion src/pages/suno/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default defineComponent({
},
computed: {
loading() {
return this.$store.state.suno?.status?.getApplication === Status.Request;
return this.$store.state.suno?.status?.getApplications === Status.Request;
},
service() {
return this.$store.state.suno.service;
Expand Down
10 changes: 10 additions & 0 deletions src/store/chat/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,19 @@ export const getApplications = async ({
if (application && application?.remaining_amount) {
console.debug('set application with Period', application);
commit('setApplication', application);
const credential = application?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Period', application);
commit('setCredential', credential);
} else if (application2) {
console.debug('set application with Usage', application2);
commit('setApplication', application2);
const credential = application2?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Usage', application);
commit('setCredential', credential);
}
resolve(response.data.items);
console.debug('save applications success', response.data.items);
Expand Down
53 changes: 37 additions & 16 deletions src/store/chatdoc/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import {
IChatdocRepository,
ICredential,
IService,
Status
Status,
IApplicationType
} from '@/models';
import { chatdocOperator, applicationOperator, serviceOperator } from '@/operators';
import { CHATDOC_SERVICE_ID } from '@/constants';
Expand All @@ -32,29 +33,49 @@ export const setRepository = async ({ commit }: any, payload: { repository: ICha
commit('setRepository', payload);
};

export const getApplication = async ({
export const getApplications = async ({
commit,
rootState,
state
}: ActionContext<IChatdocState, IRootState>): Promise<IApplication> => {
return new Promise(async (resolve, reject) => {
state.status.getApplication = Status.Request;
state,
rootState
}: ActionContext<IChatdocState, IRootState>): Promise<IApplication[]> => {
console.debug('start to get applications for chatdoc');
return new Promise((resolve, reject) => {
state.status.getApplications = Status.Request;
applicationOperator
.getAll({
user_id: rootState?.user?.id,
service_id: CHATDOC_SERVICE_ID
})
.then((response) => {
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
);
commit('setCredential', credential);
resolve(response.data.items[0]);
console.debug('get applications success', response?.data);
state.status.getApplications = Status.Success;
commit('setApplications', response.data.items);
// check if there is any application with 'Period' type
const application = response.data.items?.find((application) => application?.type === IApplicationType.PERIOD);
const application2 = response.data.items?.find((application) => application?.type === IApplicationType.USAGE);
if (application && application?.remaining_amount) {
console.debug('set application with Period', application);
commit('setApplication', application);
const credential = application?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Period', application);
commit('setCredential', credential);
} else if (application2) {
console.debug('set application with Usage', application2);
commit('setApplication', application2);
const credential = application2?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Usage', application);
commit('setCredential', credential);
}
resolve(response.data.items);
console.debug('save applications success', response.data.items);
})
.catch((error) => {
state.status.getApplication = Status.Error;
console.error('get applications error', error);
state.status.getApplications = Status.Error;
reject(error);
});
});
Expand Down Expand Up @@ -301,7 +322,7 @@ export default {
getService,
createRepository,
setApplication,
getApplication,
getApplications,
getRepositories,
setCredential,
deleteRepository,
Expand Down
2 changes: 1 addition & 1 deletion src/store/chatdoc/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface IChatdocState {
credential: ICredential | undefined;
status: {
getService: Status;
getApplication: Status;
getApplications: Status;
getRepositories: Status;
};
}
2 changes: 1 addition & 1 deletion src/store/chatdoc/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default (): IChatdocState => {
credential: undefined,
status: {
getService: Status.None,
getApplication: Status.None,
getApplications: Status.None,
getRepositories: Status.None
}
};
Expand Down
14 changes: 12 additions & 2 deletions src/store/luma/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,19 @@ export const getApplications = async ({
if (application && application?.remaining_amount) {
console.debug('set application with Period', application);
commit('setApplication', application);
const credential = application?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Period', application);
commit('setCredential', credential);
} else if (application2) {
console.debug('set application with Usage', application2);
commit('setApplication', application2);
const credential = application2?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Usage', application);
commit('setCredential', credential);
}
resolve(response.data.items);
console.debug('save applications success', response.data.items);
Expand Down Expand Up @@ -101,7 +111,7 @@ export const getService = async ({ commit, state }: ActionContext<ILumaState, IR
};

export const getTasks = async (
{ commit, state }: ActionContext<ILumaState, IRootState>,
{ commit, state, rootState }: ActionContext<ILumaState, IRootState>,
{ offset, limit }: { offset?: number; limit?: number }
): Promise<ILumaTask[]> => {
return new Promise((resolve, reject) => {
Expand All @@ -114,7 +124,7 @@ export const getTasks = async (
lumaOperator
.tasks(
{
applicationId: state.application?.id
userId: rootState?.user?.id
},
{
token
Expand Down
10 changes: 10 additions & 0 deletions src/store/midjourney/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,19 @@ export const getApplications = async ({
if (application && application?.remaining_amount) {
console.debug('set application with Period', application);
commit('setApplication', application);
const credential = application?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Period', application);
commit('setCredential', credential);
} else if (application2) {
console.debug('set application with Usage', application2);
commit('setApplication', application2);
const credential = application2?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Usage', application);
commit('setCredential', credential);
}
resolve(response.data.items);
console.debug('save application success', response.data.items[0]);
Expand Down
10 changes: 10 additions & 0 deletions src/store/qrart/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,19 @@ export const getApplications = async ({
if (application && application?.remaining_amount) {
console.debug('set application with Period', application);
commit('setApplication', application);
const credential = application?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Period', application);
commit('setCredential', credential);
} else if (application2) {
console.debug('set application with Usage', application2);
commit('setApplication', application2);
const credential = application2?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Usage', application);
commit('setCredential', credential);
}
resolve(response.data.items);
console.debug('save applications success', response.data.items);
Expand Down
10 changes: 10 additions & 0 deletions src/store/suno/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,19 @@ export const getApplications = async ({
if (application && application?.remaining_amount) {
console.debug('set application with Period', application);
commit('setApplication', application);
const credential = application?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Period', application);
commit('setCredential', credential);
} else if (application2) {
console.debug('set application with Usage', application2);
commit('setApplication', application2);
const credential = application2?.credentials?.find(
(credential) => credential?.host === window.location.origin
);
console.debug('set credential with Usage', application);
commit('setCredential', credential);
}
resolve(response.data.items);
console.debug('save applications success', response.data.items);
Expand Down

0 comments on commit 5eb453d

Please sign in to comment.