Add support for renew credentials (#27)
This commit is contained in:
1 parent
d8aadea2fe
commit
ada9fbe674
30 files changed
+228
-75
No files matched your search
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"type": "minor",
|
||||
"comment": "add support for renew credentials",
|
||||
"packageName": "@acedatacloud/hub",
|
||||
"email": "cqc@cuiqingcai.com",
|
||||
"dependentChangeType": "patch"
|
||||
}
|
||||
@@ -94,6 +94,16 @@ export default defineComponent({
|
||||
}
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// check if the credential is created
|
||||
if (
|
||||
this.application &&
|
||||
!this.application?.credentials?.find((credential) => credential.host === window.location.origin)
|
||||
) {
|
||||
console.log('create extra credential');
|
||||
this.onCreateCredential(this.application);
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onBuyMore(application: IApplication) {
|
||||
this.$router.push({
|
||||
@@ -103,6 +113,22 @@ export default defineComponent({
|
||||
}
|
||||
});
|
||||
},
|
||||
onCreateCredential(application: IApplication | undefined) {
|
||||
credentialOperator
|
||||
.create({
|
||||
application_id: application?.id,
|
||||
host: window.location.origin
|
||||
})
|
||||
.then(() => {
|
||||
setTimeout(() => {
|
||||
this.$emit('refresh');
|
||||
}, 2000);
|
||||
this.confirming = false;
|
||||
})
|
||||
.finally(() => {
|
||||
this.$emit('applied');
|
||||
});
|
||||
},
|
||||
onApply() {
|
||||
applicationOperator
|
||||
.create({
|
||||
@@ -111,19 +137,7 @@ export default defineComponent({
|
||||
})
|
||||
.then(({ data: data }: { data: IApplicationDetailResponse }) => {
|
||||
ElMessage.success(this.$t('application.message.applySuccessfully'));
|
||||
credentialOperator
|
||||
.create({
|
||||
application_id: data.id
|
||||
})
|
||||
.then(() => {
|
||||
setTimeout(() => {
|
||||
this.$emit('refresh');
|
||||
}, 2000);
|
||||
this.confirming = false;
|
||||
})
|
||||
.finally(() => {
|
||||
this.$emit('applied');
|
||||
});
|
||||
this.onCreateCredential(data);
|
||||
})
|
||||
.catch((error) => {
|
||||
if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
|
||||
|
||||
@@ -159,7 +159,7 @@ textarea.input {
|
||||
background: none;
|
||||
box-shadow: none;
|
||||
resize: none;
|
||||
line-height: 30px;
|
||||
line-height: 35px;
|
||||
width: calc(100% - 80px);
|
||||
margin-left: 30px;
|
||||
}
|
||||
@@ -176,7 +176,7 @@ textarea.input:focus {
|
||||
background: none;
|
||||
box-shadow: none;
|
||||
resize: none;
|
||||
line-height: 30px;
|
||||
line-height: 35px;
|
||||
}
|
||||
}
|
||||
.el-upload-list {
|
||||
|
||||
@@ -96,7 +96,7 @@ export default defineComponent({
|
||||
return this.$store.state.chat.status.getConversations === Status.Request;
|
||||
},
|
||||
token() {
|
||||
return this.application?.credentials?.[0].token;
|
||||
return this.$store.state.chat?.credential?.token;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElSlider } from 'element-plus';
|
||||
import InfoIcon from '@/components/common/InfoIcon.vue';
|
||||
|
||||
const DEFAULT_IW = 1.0;
|
||||
import { MIDJOURNEY_DEFAULT_IMAGE_WEIGHT } from '@/constants';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'ImageWeightSelector',
|
||||
@@ -35,7 +34,7 @@ export default defineComponent({
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = DEFAULT_IW;
|
||||
this.value = MIDJOURNEY_DEFAULT_IMAGE_WEIGHT;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -21,8 +21,7 @@
|
||||
|
||||
<script>
|
||||
import { defineComponent } from 'vue';
|
||||
|
||||
const DEFAULT_RATIO = '1:1';
|
||||
import { MIDJOURNEY_DEFAULT_RATIO } from '@/constants';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'RatioSelector',
|
||||
@@ -81,7 +80,7 @@ export default defineComponent({
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = DEFAULT_RATIO;
|
||||
this.value = MIDJOURNEY_DEFAULT_RATIO;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElSlider } from 'element-plus';
|
||||
import InfoIcon from '@/components/common/InfoIcon.vue';
|
||||
|
||||
const DEFAULT_STYLIZE = 100;
|
||||
import { MIDJOURNEY_DEFAULT_STYLIZE } from '@/constants';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'StylizeSelector',
|
||||
@@ -35,7 +34,7 @@ export default defineComponent({
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = DEFAULT_STYLIZE;
|
||||
this.value = MIDJOURNEY_DEFAULT_STYLIZE;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -10,8 +10,7 @@
|
||||
import { defineComponent } from 'vue';
|
||||
import { ElSlider } from 'element-plus';
|
||||
import InfoIcon from '@/components/common/InfoIcon.vue';
|
||||
|
||||
const DEFAULT_WEIRD = 0;
|
||||
import { MIDJOURNEY_DEFAULT_WIRED } from '@/constants';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'WeirdSelector',
|
||||
@@ -35,7 +34,7 @@ export default defineComponent({
|
||||
},
|
||||
mounted() {
|
||||
if (!this.value) {
|
||||
this.value = DEFAULT_WEIRD;
|
||||
this.value = MIDJOURNEY_DEFAULT_WIRED;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -63,6 +63,8 @@
|
||||
:preview-src-list="[modelValue?.response?.raw_image_url as string]"
|
||||
fit="contain"
|
||||
class="image"
|
||||
:lazy="true"
|
||||
@error="onReload($event)"
|
||||
/>
|
||||
<p v-if="modelValue?.response?.progress !== undefined && modelValue?.response?.progress !== 100" class="progress">
|
||||
{{ modelValue?.response?.progress }}%
|
||||
@@ -111,6 +113,7 @@ import {
|
||||
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
|
||||
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
|
||||
import { MIDJOURNEY_MODE_FAST, MIDJOURNEY_MODE_RELAX, MIDJOURNEY_MODE_TURBO } from '@/constants';
|
||||
import { parse } from 'path';
|
||||
|
||||
interface IData {
|
||||
midjourneyImagineState: typeof MidjourneyImagineState;
|
||||
@@ -222,6 +225,25 @@ export default defineComponent({
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
onReload(event: Event) {
|
||||
const target = event.target as HTMLImageElement;
|
||||
// append a random url query to existing url query, to force reload the image
|
||||
// extract exiting url query
|
||||
const url = new URL(target.src);
|
||||
// extract `retry` query
|
||||
const retry = url.searchParams.get('retry');
|
||||
if (!retry) {
|
||||
// if no retry query, set it as random string
|
||||
url.searchParams.set('retry', '1');
|
||||
} else if (parseInt(retry) < 2) {
|
||||
// if retry < 3, increase it by 1
|
||||
url.searchParams.set('retry', (parseInt(retry) + 1).toString());
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
// set the new url
|
||||
target.src = url.toString();
|
||||
},
|
||||
onCustom(action: string) {
|
||||
this.$emit('custom', {
|
||||
action,
|
||||
|
||||
@@ -24,3 +24,8 @@ export const MIDJOURNEY_MODE_TURBO: IMidjourneyMode = {
|
||||
name: MIDJOURNEY_MODE_NAME_TURBO,
|
||||
getDisplayName: () => i18n.global.t('midjourney.button.turbo')
|
||||
};
|
||||
|
||||
export const MIDJOURNEY_DEFAULT_RATIO = '1:1';
|
||||
export const MIDJOURNEY_DEFAULT_IMAGE_WEIGHT = 1.0;
|
||||
export const MIDJOURNEY_DEFAULT_STYLIZE = 100;
|
||||
export const MIDJOURNEY_DEFAULT_WIRED = 0;
|
||||
@@ -10,6 +10,7 @@ export interface ICredential {
|
||||
name?: string;
|
||||
type?: ICredentialType;
|
||||
limited_amount?: number;
|
||||
host?: string;
|
||||
used_amount?: number;
|
||||
expired_at?: string;
|
||||
token?: string;
|
||||
|
||||
@@ -99,6 +99,9 @@ export default defineComponent({
|
||||
application() {
|
||||
return this.$store.state.chat.application;
|
||||
},
|
||||
credential() {
|
||||
return this.$store.state.chat?.credential;
|
||||
},
|
||||
needApply() {
|
||||
return this.$store.state.chat.status.getApplication === Status.Success && !this.application;
|
||||
},
|
||||
@@ -178,7 +181,7 @@ export default defineComponent({
|
||||
}, 0);
|
||||
},
|
||||
async onFetchAnswer() {
|
||||
const token = this.application?.credentials?.[0]?.token;
|
||||
const token = this.credential?.token;
|
||||
const question = this.question;
|
||||
const references = this.references;
|
||||
log(this.onFetchAnswer, 'validated', question, references);
|
||||
|
||||
@@ -101,6 +101,9 @@ export default defineComponent({
|
||||
application() {
|
||||
return this.$store.state.chatdoc.application;
|
||||
},
|
||||
credential() {
|
||||
return this.$store.state.chatdoc.credential;
|
||||
},
|
||||
needApply() {
|
||||
return this.$store.state.chatdoc.status.getApplication === Status.Success && !this.application;
|
||||
},
|
||||
@@ -136,7 +139,7 @@ export default defineComponent({
|
||||
}, 0);
|
||||
},
|
||||
async onFetchAnswer() {
|
||||
const token = this.application?.credentials?.[0]?.token;
|
||||
const token = this.credential?.token;
|
||||
const question = this.question;
|
||||
log(this.onFetchAnswer, 'validated', question);
|
||||
// reset question and references
|
||||
|
||||
@@ -63,6 +63,9 @@ export default defineComponent({
|
||||
application() {
|
||||
return this.$store.state.midjourney.application;
|
||||
},
|
||||
credential() {
|
||||
return this.$store.state.midjourney.credential;
|
||||
},
|
||||
initializing() {
|
||||
return this.$store.state.midjourney.status.getApplication === Status.Request;
|
||||
},
|
||||
@@ -83,7 +86,7 @@ export default defineComponent({
|
||||
await this.$store.dispatch('midjourney/getApplication');
|
||||
},
|
||||
async onStartTask(request: IMidjourneyImagineRequest) {
|
||||
const token = this.application?.credentials?.[0]?.token;
|
||||
const token = this.credential?.token;
|
||||
if (!token) {
|
||||
console.error('no token found');
|
||||
return;
|
||||
|
||||
@@ -47,6 +47,12 @@ import FinalPrompt from '@/components/midjourney/FinalPrompt.vue';
|
||||
import { ERROR_CODE_DUPLICATION } from '@/constants/errorCode';
|
||||
import { MidjourneyImagineMode, Status } from '@/models';
|
||||
import { IMidjourneyImagineRequest, IApplicationDetailResponse, MidjourneyImagineAction } from '@/models';
|
||||
import {
|
||||
MIDJOURNEY_DEFAULT_IMAGE_WEIGHT,
|
||||
MIDJOURNEY_DEFAULT_RATIO,
|
||||
MIDJOURNEY_DEFAULT_STYLIZE,
|
||||
MIDJOURNEY_DEFAULT_WIRED
|
||||
} from '@/constants';
|
||||
|
||||
interface IData {
|
||||
prompt: string;
|
||||
@@ -87,6 +93,9 @@ export default defineComponent({
|
||||
mode() {
|
||||
return this.$store.state.midjourney.mode;
|
||||
},
|
||||
credential() {
|
||||
return this.$store.state.midjourney.credential;
|
||||
},
|
||||
preset() {
|
||||
return this.$store.state.midjourney.preset;
|
||||
},
|
||||
@@ -122,19 +131,34 @@ export default defineComponent({
|
||||
if (this.preset.quality && !content.includes(`--quality `) && !content.includes(`--q `)) {
|
||||
content += ` --quality ${this.preset.quality}`;
|
||||
}
|
||||
if (this.preset.ratio && !content.includes(`--aspect `) && !content.includes(`--ar `)) {
|
||||
if (
|
||||
this.preset.ratio &&
|
||||
!content.includes(`--aspect `) &&
|
||||
!content.includes(`--ar `) &&
|
||||
this.preset.ratio !== MIDJOURNEY_DEFAULT_RATIO
|
||||
) {
|
||||
content += ` --aspect ${this.preset.ratio}`;
|
||||
}
|
||||
if (this.preset.stylize && !content.includes(`--stylize `) && !content.includes(`--s `)) {
|
||||
if (
|
||||
this.preset.stylize &&
|
||||
!content.includes(`--stylize `) &&
|
||||
!content.includes(`--s `) &&
|
||||
this.preset.stylize !== MIDJOURNEY_DEFAULT_STYLIZE
|
||||
) {
|
||||
content += ` --stylize ${this.preset.stylize}`;
|
||||
}
|
||||
if (this.preset.weird && !content.includes(`--weird `) && !content.includes(`--w `)) {
|
||||
if (
|
||||
this.preset.weird &&
|
||||
!content.includes(`--weird `) &&
|
||||
!content.includes(`--w `) &&
|
||||
this.preset.weird !== MIDJOURNEY_DEFAULT_WIRED
|
||||
) {
|
||||
content += ` --weird ${this.preset.weird}`;
|
||||
}
|
||||
if (this.ignore && !content.includes(`--no `)) {
|
||||
content += ` --no ${this.ignore}`;
|
||||
}
|
||||
if (this.preset.iw && !content.includes(`--iw `)) {
|
||||
if (this.preset.iw && !content.includes(`--iw `) && this.preset.iw !== MIDJOURNEY_DEFAULT_IMAGE_WEIGHT) {
|
||||
content += ` --iw ${this.preset.iw}`;
|
||||
}
|
||||
if (this.preset.style && !content.includes(`--style`)) {
|
||||
@@ -164,7 +188,7 @@ export default defineComponent({
|
||||
await this.$store.dispatch('midjourney/getApplication');
|
||||
},
|
||||
async onStartTask(request: IMidjourneyImagineRequest) {
|
||||
const token = this.application?.credentials?.[0]?.token;
|
||||
const token = this.credential?.token;
|
||||
if (!token) {
|
||||
console.error('no token specified');
|
||||
return;
|
||||
|
||||
@@ -3,7 +3,7 @@ import { IRootState } from '../common/models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IChatState } from './models';
|
||||
import { IApplication, IChatConversation, IChatModel, IService, Status } from '@/models';
|
||||
import { IApplication, IChatConversation, IChatModel, ICredential, IService, Status } from '@/models';
|
||||
import { CHAT_SERVICE_ID } from '@/constants';
|
||||
|
||||
export const resetAll = ({ commit }: ActionContext<IChatState, IRootState>): void => {
|
||||
@@ -29,6 +29,11 @@ export const setConversations = async ({ commit }: any, payload: IChatConversati
|
||||
commit('setConversations', payload);
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
log(setCredential, 'set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
export const setConversation = async ({ commit, state }: any, payload: IChatConversation): Promise<void> => {
|
||||
log(setConversation, 'set conversation', payload);
|
||||
const conversations = state.conversations;
|
||||
@@ -76,6 +81,10 @@ export const getApplication = async ({
|
||||
.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]);
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -91,9 +100,9 @@ export const getConversations = async ({
|
||||
}: ActionContext<IChatState, IRootState>): Promise<IChatConversation[]> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
state.status.getConversations = Status.Request;
|
||||
const application = state.application;
|
||||
log(getConversations, 'application', application);
|
||||
const token = application?.credentials?.[0].token;
|
||||
const credential = state.credential;
|
||||
log(getConversations, 'credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
state.status.getConversations = Status.Error;
|
||||
return reject(new Error('Token not found'));
|
||||
@@ -126,6 +135,7 @@ export default {
|
||||
setModel,
|
||||
getService,
|
||||
setService,
|
||||
setCredential,
|
||||
setApplication,
|
||||
getApplication,
|
||||
setConversation,
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
import { IApplication, IChatConversation, IChatModel, IService, Status } from '@/models';
|
||||
import { IApplication, IChatConversation, IChatModel, ICredential, IService, Status } from '@/models';
|
||||
|
||||
export interface IChatState {
|
||||
model: IChatModel;
|
||||
application: IApplication | undefined;
|
||||
service: IService | undefined;
|
||||
conversations: IChatConversation[] | undefined;
|
||||
credential: ICredential | undefined;
|
||||
status: {
|
||||
getService: Status;
|
||||
getApplication: Status;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IApplication, IChatConversation, IChatModel, IService } from '@/models';
|
||||
import { IApplication, IChatConversation, IChatModel, ICredential, IService } from '@/models';
|
||||
import { IChatState } from './models';
|
||||
|
||||
export const resetAll = (state: IChatState): void => {
|
||||
@@ -10,6 +10,10 @@ export const setModel = (state: IChatState, payload: IChatModel): void => {
|
||||
state.model = payload;
|
||||
};
|
||||
|
||||
export const setCredential = (state: IChatState, payload: ICredential): void => {
|
||||
state.credential = payload;
|
||||
};
|
||||
|
||||
export const setApplication = (state: IChatState, payload: IApplication): void => {
|
||||
state.application = payload;
|
||||
};
|
||||
@@ -25,6 +29,7 @@ export const setConversations = (state: IChatState, payload: IChatConversation[]
|
||||
export default {
|
||||
setModel,
|
||||
setService,
|
||||
setCredential,
|
||||
setConversations,
|
||||
setApplication,
|
||||
resetAll
|
||||
|
||||
@@ -1 +1 @@
|
||||
export default ['chat.application', 'chat.service', 'chat.conversations', 'chat.model'];
|
||||
export default ['chat.application', 'chat.service', 'chat.credential', 'chat.conversations', 'chat.model'];
|
||||
@@ -7,7 +7,10 @@ export default (): IChatState => {
|
||||
model: CHAT_MODEL_GPT_3_5,
|
||||
application: undefined,
|
||||
conversations: undefined,
|
||||
service: undefined,
|
||||
credential: undefined,
|
||||
status: {
|
||||
getService: Status.None,
|
||||
getApplication: Status.None,
|
||||
getConversations: Status.None
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import {
|
||||
IChatdocDocument,
|
||||
IChatdocMessage,
|
||||
IChatdocRepository,
|
||||
ICredential,
|
||||
IService,
|
||||
Status
|
||||
} from '@/models';
|
||||
@@ -18,6 +19,11 @@ export const setApplication = async ({ commit }: any, payload: IApplication): Pr
|
||||
commit('setApplication', payload);
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
log(setCredential, 'set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
|
||||
log(setService, 'set service', payload);
|
||||
commit('setService', payload);
|
||||
@@ -42,6 +48,10 @@ export const getApplication = async ({
|
||||
.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]);
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -60,9 +70,9 @@ export const getRepositories = async ({
|
||||
state
|
||||
}: ActionContext<IChatdocState, IRootState>): Promise<IChatdocRepository[]> => {
|
||||
log(getRepositories, 'start to get repositories');
|
||||
const application = state.application;
|
||||
console.log('application', application);
|
||||
const token = application?.credentials?.[0]?.token;
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
commit('setRepositories', undefined);
|
||||
return Promise.reject('no token');
|
||||
@@ -84,9 +94,9 @@ export const deleteRepository = async (
|
||||
}
|
||||
): Promise<IChatdocRepository> => {
|
||||
log(deleteRepository, 'start to delete repository');
|
||||
const application = state.application;
|
||||
console.log('application', application);
|
||||
const token = application?.credentials?.[0]?.token;
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
@@ -106,9 +116,9 @@ export const deleteDocument = async (
|
||||
}
|
||||
): Promise<IChatdocDocument> => {
|
||||
log(deleteDocument, 'start to delete document');
|
||||
const application = state.application;
|
||||
console.log('application', application);
|
||||
const token = application?.credentials?.[0]?.token;
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
@@ -147,9 +157,9 @@ export const createRepository = async (
|
||||
}
|
||||
): Promise<IChatdocRepository> => {
|
||||
log(createRepository, 'start to create repository');
|
||||
const application = state.application;
|
||||
console.log('application', application);
|
||||
const token = application?.credentials?.[0]?.token;
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
@@ -171,9 +181,9 @@ export const createDocument = async (
|
||||
}
|
||||
): Promise<IChatdocDocument> => {
|
||||
log(createDocument, 'start to create document');
|
||||
const application = state.application;
|
||||
console.log('application', application);
|
||||
const token = application?.credentials?.[0]?.token;
|
||||
const credential = state.credential;
|
||||
console.log('credential', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
return Promise.reject('no token');
|
||||
}
|
||||
@@ -214,9 +224,9 @@ export const getDocuments = async (
|
||||
payload: { repositoryId: string }
|
||||
): Promise<IChatdocDocument[]> => {
|
||||
log(getRepositories, 'start to get documents');
|
||||
const application = state.application;
|
||||
console.log('application for getDocuments', application);
|
||||
const token = application?.credentials?.[0]?.token;
|
||||
const credential = state.credential;
|
||||
console.log('credential for getDocuments', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
commit('setRepository', {
|
||||
id: payload.repositoryId,
|
||||
@@ -242,9 +252,9 @@ export const getConversations = async (
|
||||
payload: { repositoryId: string }
|
||||
): Promise<IChatdocConversation[]> => {
|
||||
log(getConversations, 'start to get conversations');
|
||||
const application = state.application;
|
||||
console.log('application for getConversations', application);
|
||||
const token = application?.credentials?.[0]?.token;
|
||||
const credential = state.credential;
|
||||
console.log('credential for getConversations', credential);
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
commit('setRepository', {
|
||||
id: payload.repositoryId,
|
||||
@@ -272,8 +282,8 @@ export const getRepository = async (
|
||||
payload: { id: string }
|
||||
): Promise<IChatdocRepository> => {
|
||||
log(getRepository, 'start to get repository');
|
||||
const application = state.application;
|
||||
const token = application?.credentials?.[0]?.token;
|
||||
const credential = state.credential;
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
commit('setRepository', { id: payload.id });
|
||||
return Promise.reject('no token');
|
||||
@@ -296,6 +306,7 @@ export default {
|
||||
setApplication,
|
||||
getApplication,
|
||||
getRepositories,
|
||||
setCredential,
|
||||
deleteRepository,
|
||||
getRepository,
|
||||
setRepository,
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { IApplication, IChatdocRepository, IService, Status } from '@/models';
|
||||
import { IApplication, IChatdocRepository, ICredential, IService, Status } from '@/models';
|
||||
|
||||
export interface IChatdocState {
|
||||
service: IService | undefined;
|
||||
application: IApplication | undefined;
|
||||
repositories: IChatdocRepository[] | undefined;
|
||||
credential: ICredential | undefined;
|
||||
status: {
|
||||
getService: Status;
|
||||
getApplication: Status;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IApplication, IChatdocRepository, IService } from '@/models';
|
||||
import { IApplication, IChatdocRepository, ICredential, IService } from '@/models';
|
||||
import { IChatdocState } from './models';
|
||||
import { log } from '@/utils';
|
||||
|
||||
@@ -36,6 +36,10 @@ export const setRepositories = (state: IChatdocState, payload: IChatdocRepositor
|
||||
}
|
||||
};
|
||||
|
||||
export const setCredential = (state: IChatdocState, payload: ICredential): void => {
|
||||
state.credential = payload;
|
||||
};
|
||||
|
||||
export const setRepository = (state: IChatdocState, payload: IChatdocRepository): void => {
|
||||
log(setRepository, 'mutation', payload);
|
||||
// find the repository and set it
|
||||
@@ -62,5 +66,6 @@ export default {
|
||||
setApplication,
|
||||
setRepositories,
|
||||
setRepository,
|
||||
setCredential,
|
||||
resetAll
|
||||
};
|
||||
@@ -1 +1 @@
|
||||
export default ['chatdoc.repositories', 'chatdoc.service', 'chatdoc.application'];
|
||||
export default ['chatdoc.repositories', 'chatdoc.credential', 'chatdoc.service', 'chatdoc.application'];
|
||||
@@ -6,6 +6,7 @@ export default (): IChatdocState => {
|
||||
service: undefined,
|
||||
application: undefined,
|
||||
repositories: undefined,
|
||||
credential: undefined,
|
||||
status: {
|
||||
getService: Status.None,
|
||||
getApplication: Status.None,
|
||||
|
||||
@@ -3,7 +3,14 @@ import { IMidjourneyState } from './models';
|
||||
import { ActionContext } from 'vuex';
|
||||
import { log } from '@/utils/log';
|
||||
import { IRootState } from '../common/models';
|
||||
import { IApplication, IMidjourneyImagineTask, IMidjourneyMode, IMidjourneyPreset, IService } from '@/models';
|
||||
import {
|
||||
IApplication,
|
||||
ICredential,
|
||||
IMidjourneyImagineTask,
|
||||
IMidjourneyMode,
|
||||
IMidjourneyPreset,
|
||||
IService
|
||||
} from '@/models';
|
||||
import { Status } from '@/models/common';
|
||||
import { MIDJOURNEY_SERVICE_ID } from '@/constants';
|
||||
|
||||
@@ -11,6 +18,11 @@ export const resetAll = ({ commit }: ActionContext<IMidjourneyState, IRootState>
|
||||
commit('resetAll');
|
||||
};
|
||||
|
||||
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
|
||||
log(setCredential, 'set credential', payload);
|
||||
commit('setCredential', payload);
|
||||
};
|
||||
|
||||
export const setPreset = ({ commit }: any, payload: IMidjourneyPreset) => {
|
||||
commit('setPreset', payload);
|
||||
};
|
||||
@@ -44,6 +56,10 @@ export const getApplication = async ({
|
||||
.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]);
|
||||
})
|
||||
.catch((error) => {
|
||||
@@ -81,8 +97,8 @@ export const getImagineTasks = async (
|
||||
): Promise<IMidjourneyImagineTask[]> => {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
log(getImagineTasks, 'start to get imagine tasks', offset, limit);
|
||||
const application = state.application;
|
||||
const token = application?.credentials?.[0]?.token;
|
||||
const credential = state.credential;
|
||||
const token = credential?.token;
|
||||
if (!token) {
|
||||
return reject('no token');
|
||||
}
|
||||
@@ -111,6 +127,7 @@ export default {
|
||||
setService,
|
||||
getService,
|
||||
resetAll,
|
||||
setCredential,
|
||||
setPreset,
|
||||
setMode,
|
||||
setApplication,
|
||||
|
||||
@@ -1,10 +1,19 @@
|
||||
import { IApplication, IMidjourneyImagineTask, IMidjourneyMode, IMidjourneyPreset, IService, Status } from '@/models';
|
||||
import {
|
||||
IApplication,
|
||||
ICredential,
|
||||
IMidjourneyImagineTask,
|
||||
IMidjourneyMode,
|
||||
IMidjourneyPreset,
|
||||
IService,
|
||||
Status
|
||||
} from '@/models';
|
||||
|
||||
export interface IMidjourneyState {
|
||||
service: IService | undefined;
|
||||
application: IApplication | undefined;
|
||||
imagineTasks: IMidjourneyImagineTask[] | undefined;
|
||||
imagineTasksTotal: number | undefined;
|
||||
credential: ICredential | undefined;
|
||||
preset: IMidjourneyPreset;
|
||||
mode: IMidjourneyMode;
|
||||
status: {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IApplication, IMidjourneyMode, IMidjourneyPreset, IService } from '@/models';
|
||||
import { IApplication, ICredential, IMidjourneyMode, IMidjourneyPreset, IService } from '@/models';
|
||||
import { IMidjourneyState } from './models';
|
||||
|
||||
export const resetAll = (state: IMidjourneyState): void => {
|
||||
@@ -11,6 +11,10 @@ export const setService = (state: IMidjourneyState, payload: IService): void =>
|
||||
state.service = payload;
|
||||
};
|
||||
|
||||
export const setCredential = (state: IMidjourneyState, payload: ICredential): void => {
|
||||
state.credential = payload;
|
||||
};
|
||||
|
||||
export const setApplication = (state: IMidjourneyState, payload: IApplication): void => {
|
||||
state.application = payload;
|
||||
};
|
||||
@@ -34,6 +38,7 @@ export const setImagineTasksTotal = (state: IMidjourneyState, payload: number):
|
||||
export default {
|
||||
setApplication,
|
||||
setPreset,
|
||||
setCredential,
|
||||
setService,
|
||||
setMode,
|
||||
setImagineTasks,
|
||||
|
||||
@@ -1 +1,7 @@
|
||||
export default ['midjourney.preset', 'midjourney.mode', 'midjourney.application', 'midjourney.imagineTasks'];
|
||||
export default [
|
||||
'midjourney.preset',
|
||||
'midjourney.credential',
|
||||
'midjourney.mode',
|
||||
'midjourney.application',
|
||||
'midjourney.imagineTasks'
|
||||
];
|
||||
@@ -8,6 +8,7 @@ export default (): IMidjourneyState => {
|
||||
application: undefined,
|
||||
imagineTasks: undefined,
|
||||
imagineTasksTotal: undefined,
|
||||
credential: undefined,
|
||||
preset: {},
|
||||
mode: MIDJOURNEY_MODE_FAST,
|
||||
status: {
|
||||
|
||||
Reference in new issue
Block a user