Skip to content

Commit

Permalink
fix actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Germey committed Mar 3, 2024
1 parent 1e9d7aa commit 2e5f9be
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 102 deletions.
9 changes: 5 additions & 4 deletions src/components/midjourney/tasks/TaskBriefList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</div>
<div v-else-if="tasks.length > 0" class="tasks">
<div v-for="(task, taskKey) in tasks" :key="taskKey" class="task">
<task-preview :full="false" :model-value="task" :applications="applications" @custom="$emit('custom', $event)" />
<task-preview :full="false" :model-value="task" @custom="$emit('custom', $event)" />
</div>
<el-button type="primary" class="btn mb-4" @click="onLoadHistory">{{ $t('midjourney.button.history') }}</el-button>
</div>
Expand Down Expand Up @@ -44,17 +44,18 @@ export default defineComponent({
},
computed: {
loading() {
return this.$store.state.midjourney.getImagineTasksStatus === Status.Request;
return this.$store.state.midjourney.status.getApplication === Status.Request;
},
tasks() {
return this.$store.state.midjourney.imagineTasks;
},
applications() {
return this.$store.state.midjourney.applications;
application() {
return this.$store.state.midjourney.application;
}
},
async mounted() {
await this.$store.dispatch('midjourney/setImagineTasks', undefined);
// @ts-ignore
this.job = setInterval(() => {
this.getImagineTasks();
}, 5000);
Expand Down
17 changes: 11 additions & 6 deletions src/components/midjourney/tasks/TaskFullList.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<template>
<div v-if="tasks" class="tasks">
<div v-for="(task, taskKey) in tasks" :key="taskKey" class="task">
<task-preview :full="true" :model-value="task" :applications="applications" @custom="onCustom($event)" />
<task-preview :full="true" :model-value="task" @custom="onCustom($event)" />
</div>
</div>
<div v-else class="tasks">
Expand All @@ -26,6 +26,10 @@ import Pagination from '@/components/common/Pagination.vue';
import { ElCard, ElSkeleton, ElSkeletonItem } from 'element-plus';
import { Status } from '@/models';
interface IData {
job: number | undefined;
}
export default defineComponent({
name: 'TaskFullList',
components: {
Expand All @@ -36,9 +40,9 @@ export default defineComponent({
ElCard
},
emits: ['update:modelValue', 'custom'],
data() {
data(): IData {
return {
job: 0
job: undefined
};
},
computed: {
Expand All @@ -55,13 +59,13 @@ export default defineComponent({
return 12;
},
loading() {
return this.$store.state.midjourney.getImagineTasksStatus === Status.Request;
return this.$store.state.midjourney.status.getApplication === Status.Request;
},
tasks() {
return this.$store.state.midjourney.imagineTasks;
},
applications() {
return this.$store.state.midjourney.applications;
application() {
return this.$store.state.midjourney.application;
}
},
watch: {
Expand All @@ -74,6 +78,7 @@ export default defineComponent({
},
async mounted() {
await this.$store.dispatch('midjourney/setImagineTasks', undefined);
// @ts-ignore
this.job = setInterval(() => {
this.getImagineTasks();
}, 5000);
Expand Down
47 changes: 19 additions & 28 deletions src/components/midjourney/tasks/TaskPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
</el-tag>
</div>
<div class="right">
<el-tag v-if="channel" type="info" class="channel">
<font-awesome-icon :class="{ icon: true, [channel.name]: true }" :icon="channel?.icon" />
{{ channel?.displayName }}
<el-tag v-if="mode" type="info" class="channel">
<font-awesome-icon :class="{ icon: true, [mode.name]: true }" :icon="mode?.icon" />
{{ mode?.displayName }}
</el-tag>
</div>
</div>
Expand Down Expand Up @@ -103,7 +103,7 @@
<script lang="ts">
import { defineComponent } from 'vue';
import { ElImage, ElTag, ElButton, ElTooltip, ElSkeleton, ElAlert } from 'element-plus';
import { IApplication, IMidjourneyImagineTask, MidjourneyImagineAction, MidjourneyImagineState } from '@/models';
import { IMidjourneyImagineTask, MidjourneyImagineAction, MidjourneyImagineState } from '@/models';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
Expand All @@ -130,10 +130,6 @@ export default defineComponent({
type: Object as () => IMidjourneyImagineTask | undefined,
required: true
},
applications: {
type: Object as () => IApplication[] | undefined,
required: true
},
full: {
type: Boolean,
default: false
Expand All @@ -153,14 +149,16 @@ export default defineComponent({
[MidjourneyImagineAction.VARIATION2]: 'V2',
[MidjourneyImagineAction.VARIATION3]: 'V3',
[MidjourneyImagineAction.VARIATION4]: 'V4',
[MidjourneyImagineAction.HIGH_VARIATION]: 'Vary (Strong)',
[MidjourneyImagineAction.LOW_VARIATION]: 'Vary (Subtle)',
[MidjourneyImagineAction.VARIATION_STRONG]: 'Vary (Strong)',
[MidjourneyImagineAction.VARIATION_SUBTLE]: 'Vary (Subtle)',
[MidjourneyImagineAction.UPSCALE_CREATIVE]: 'Upscale (Creative)',
[MidjourneyImagineAction.UPSCALE_SUBTLE]: 'Upscale (Subtle)',
[MidjourneyImagineAction.ZOOM_OUT_2X]: 'Zoom Out 2x',
[MidjourneyImagineAction.ZOOM_OUT_1_5X]: 'Zoom Out 1.5x',
[MidjourneyImagineAction.UPSCALE4_2x]: 'Upsample 2x',
[MidjourneyImagineAction.UPSAMPLE_4X]: 'Upsample 4x',
[MidjourneyImagineAction.REDO_UPSCALE_2X]: 'Redo Upsample 2x',
[MidjourneyImagineAction.REDO_UPSAMPLE_4X]: 'Redo Upsample 4x',
[MidjourneyImagineAction.UPSCALE_2X]: 'Upscale 2x',
[MidjourneyImagineAction.UPSCALE_4X]: 'Upscale 4x',
[MidjourneyImagineAction.REDO_UPSCALE_2X]: 'Redo Upscale 2x',
[MidjourneyImagineAction.REDO_UPSCALE_4X]: 'Redo Upscale 4x',
[MidjourneyImagineAction.SQUARE]: 'Make Square',
[MidjourneyImagineAction.PAN_LEFT]: '⬅️',
[MidjourneyImagineAction.PAN_UP]: '⬆️',
Expand All @@ -182,10 +180,12 @@ export default defineComponent({
[MidjourneyImagineAction.VARIATION_SUBTLE]: this.$t('midjourney.description.variation_subtle'),
[MidjourneyImagineAction.ZOOM_OUT_2X]: this.$t('midjourney.description.zoom_out_2x'),
[MidjourneyImagineAction.ZOOM_OUT_1_5X]: this.$t('midjourney.description.zoom_out_1_5x'),
[MidjourneyImagineAction.UPSCALE_2x]: this.$t('midjourney.description.upscale_2x'),
[MidjourneyImagineAction.UPSCALE_2X]: this.$t('midjourney.description.upscale_2x'),
[MidjourneyImagineAction.UPSCALE_4X]: this.$t('midjourney.description.upscale_4x'),
[MidjourneyImagineAction.UPSCALE_SUBTLE]: this.$t('midjourney.description.upscale_subtle'),
[MidjourneyImagineAction.UPSCALE_CREATIVE]: this.$t('midjourney.description.upscale_creative'),
[MidjourneyImagineAction.REDO_UPSCALE_2X]: this.$t('midjourney.description.redo_upscale_2x'),
[MidjourneyImagineAction.REDO_UPSAMPLE_4X]: this.$t('midjourney.description.redo_upscale_4x'),
[MidjourneyImagineAction.REDO_UPSCALE_4X]: this.$t('midjourney.description.redo_upscale_4x'),
[MidjourneyImagineAction.SQUARE]: this.$t('midjourney.description.square'),
[MidjourneyImagineAction.PAN_LEFT]: this.$t('midjourney.description.pan_left'),
[MidjourneyImagineAction.PAN_UP]: this.$t('midjourney.description.pan_up'),
Expand All @@ -197,19 +197,10 @@ export default defineComponent({
},
computed: {
application() {
return this.applications?.find((application) => {
return application.id === this.modelValue?.request?.application_id;
});
return this.$store.state.midjourney.application;
},
channel() {
// if (this.application?.api_id === API_ID_MIDJOURNEY_FAST) {
// return MIDJOURNEY_CHANNEL_FAST;
// } else if (this.application?.api_id === API_ID_MIDJOURNEY_RELAX) {
// return MIDJOURNEY_CHANNEL_RELAX;
// } else if (this.application?.api_id === API_ID_MIDJOURNEY_TURBO) {
// return MIDJOURNEY_CHANNEL_TURBO;
// }
return undefined;
mode() {
return this.$store.state.midjourney.mode;
}
},
methods: {
Expand Down
11 changes: 3 additions & 8 deletions src/components/order/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
</template>

<script lang="ts">
import { IApplication, IApplicationType, IOrderDetailResponse, IPackage, orderOperator } from '@/operators';
import { IApplication, IApplicationType, IOrderDetailResponse, IPackage } from '@/models';
import { defineComponent } from 'vue';
import { ElMessage } from 'element-plus';
import { ROUTE_CONSOLE_ORDER_DETAIL } from '@/router';
Expand Down Expand Up @@ -92,17 +92,12 @@ export default defineComponent({
},
computed: {
price() {
if (this.application?.type === IApplicationType.API) {
if (this.application.api?.price && this.form.amount) {
return this.form.amount * this.application.api?.price;
}
}
return 0;
},
package() {
if (this.application?.type === IApplicationType.API) {
if (this.application.api?.packages && this.form.packageId) {
const filterPackages = this.application.api?.packages.filter((item) => item.id === this.form.packageId);
if (this.application.service?.packages && this.form.packageId) {
const filterPackages = this.application.service?.packages.filter((item) => item.id === this.form.packageId);
if (filterPackages.length > 0) {
return filterPackages[0];
}
Expand Down
3 changes: 2 additions & 1 deletion src/operators/midjourney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class MidjourneyOperator {
return await axios.post('/midjourney/imagine', data, {
headers: {
authorization: `Bearer ${options.token}`,
'content-type': 'application/json'
'content-type': 'application/json',
accept: 'application/json'
},
baseURL: BASE_URL_API
});
Expand Down
15 changes: 3 additions & 12 deletions src/pages/chatdoc/Conversation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@ import axios from 'axios';
import { isJSONString } from '@/utils/is';
import { Status } from '@/models';
import ApplicationStatus from '@/components/application/Status.vue';
import {
IApplication,
IChatdocChatResponse,
IChatdocConversation,
IChatdocMessageState,
IChatdocRepository
} from '@/models';
import { IChatdocChatResponse, IChatdocConversation, IChatdocMessageState, IChatdocRepository } from '@/models';
export default defineComponent({
name: 'ChatdocChat',
Expand All @@ -80,7 +74,6 @@ export default defineComponent({
repositoryId: this.$route.params.repositoryId.toString(),
answering: false,
question: ''
// references: []
};
},
computed: {
Expand Down Expand Up @@ -149,14 +142,12 @@ export default defineComponent({
}, 0);
},
async onFetchAnswer() {
const token = this.application?.credential?.token;
const endpoint = this.application?.api?.endpoint;
const path = this.application?.api?.path;
const token = this.application?.credentials?.[0]?.token;
const question = this.question;
log(this.onFetchAnswer, 'validated', question);
// reset question and references
this.question = '';
if (!token || !endpoint || !question || !path) {
if (!token || !question) {
console.error('no token or endpoint or question');
this.messages.push({
error: {
Expand Down
4 changes: 2 additions & 2 deletions src/pages/chatdoc/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export default defineComponent({
return this.$store.state.chatdoc.repositories;
},
needApply() {
return this.$store.state.chatdoc.getApplicationStatus === Status.Success && !this.application;
return this.$store.state.chatdoc.status.getApplication === Status.Success && !this.application;
},
application() {
return this.$store.state.chatdoc.application;
Expand All @@ -101,7 +101,7 @@ export default defineComponent({
return this.$store.state.chatdoc.service;
},
initializing() {
return this.$store.state.chatdoc.getApplicationStatus === Status.Request;
return this.$store.state.chatdoc.status.getApplication === Status.Request;
}
},
async mounted() {},
Expand Down
12 changes: 4 additions & 8 deletions src/pages/midjourney/History.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,14 @@ export default defineComponent({
await this.$store.dispatch('midjourney/getApplication');
},
async onStartTask(request: IMidjourneyImagineRequest) {
const token = this.application?.credential?.token;
const endpoint = this.application?.api?.endpoint;
const path = this.application?.api?.path;
if (!token || !endpoint || !path) {
console.error('no token or endpoint or question');
const token = this.application?.credentials?.[0]?.token;
if (!token) {
console.error('no token found');
return;
}
midjourneyOperator
.imagine(request, {
token,
endpoint,
path
token
})
.then(() => {
ElMessage.success(this.$t('midjourney.message.startTaskSuccess'));
Expand Down
12 changes: 5 additions & 7 deletions src/pages/midjourney/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
</template>
<template #operation>
<mode-selector class="mb-4" />
<api-status
<application-status
:initializing="initializing"
:application="application"
:api-id="channel.apiId"
:service="service"
:need-apply="needApply"
class="mb-4"
@refresh="onGetApplications"
Expand Down Expand Up @@ -41,7 +41,7 @@ import { ElButton, ElMessage } from 'element-plus';
import ModeSelector from '@/components/midjourney/ModeSelector.vue';
import ReferenceImage from '@/components/midjourney/ReferenceImage.vue';
import { applicationOperator, midjourneyOperator } from '@/operators';
import ApiStatus from '@/components/common/ApiStatus.vue';
import ApplicationStatus from '@/components/application/Status.vue';
import TaskBriefList from '@/components/midjourney/tasks/TaskBriefList.vue';
import FinalPrompt from '@/components/midjourney/FinalPrompt.vue';
import { ERROR_CODE_DUPLICATION } from '@/constants/errorCode';
Expand All @@ -67,7 +67,7 @@ export default defineComponent({
ElementsSelector,
IgnoreSelector,
ElButton,
ApiStatus,
ApplicationStatus,
TaskBriefList,
FinalPrompt,
Layout
Expand Down Expand Up @@ -174,9 +174,7 @@ export default defineComponent({
}
midjourneyOperator
.imagine(request, {
token,
endpoint,
path
token
})
.then(() => {
ElMessage.success(this.$t('midjourney.message.startTaskSuccess'));
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,6 +7,6 @@ export interface IChatdocState {
status: {
getService: Status;
getApplication: Status;
getConversations: Status;
getRepositories: Status;
};
}
7 changes: 6 additions & 1 deletion src/store/chatdoc/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { IApplication, IChatdocRepository } from '@/models';
import { IApplication, IChatdocRepository, IService } from '@/models';
import { IChatdocState } from './models';
import { log } from '@/utils';

Expand All @@ -7,6 +7,10 @@ export const resetAll = (state: IChatdocState): void => {
state.repositories = [];
};

export const setService = (state: IChatdocState, payload: IService): void => {
state.service = payload;
};

export const setApplication = (state: IChatdocState, payload: IApplication): void => {
state.application = payload;
};
Expand Down Expand Up @@ -54,6 +58,7 @@ export const setRepository = (state: IChatdocState, payload: IChatdocRepository)
};

export default {
setService,
setApplication,
setRepositories,
setRepository,
Expand Down
9 changes: 8 additions & 1 deletion src/store/chatdoc/state.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { Status } from '@/models';
import { IChatdocState } from './models';

export default (): IChatdocState => {
return {
service: undefined,
application: undefined,
repositories: undefined
repositories: undefined,
status: {
getService: Status.None,
getApplication: Status.None,
getRepositories: Status.None
}
};
};
Loading

0 comments on commit 2e5f9be

Please sign in to comment.