update history
This commit is contained in:
1 parent
ac78a5ea6f
commit
96708de3a4
12 files changed
+407
-95
No files matched your search
@@ -1,51 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="preview">
|
|
||||||
<el-image
|
|
||||||
v-if="modelValue?.image_url"
|
|
||||||
v-loading="state === midjourneyImagineState.PENDING"
|
|
||||||
:src="modelValue?.image_url"
|
|
||||||
fit="fill"
|
|
||||||
class="image"
|
|
||||||
/>
|
|
||||||
<p v-if="modelValue?.progress !== undefined">{{ modelValue?.progress }}%</p>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script lang="ts">
|
|
||||||
import { defineComponent } from 'vue';
|
|
||||||
import { ElImage } from 'element-plus';
|
|
||||||
import { IMidjourneyImagineResponse, MidjourneyImagineState } from '@/operators';
|
|
||||||
|
|
||||||
export default defineComponent({
|
|
||||||
name: 'ImaginePreview',
|
|
||||||
components: {
|
|
||||||
ElImage
|
|
||||||
},
|
|
||||||
props: {
|
|
||||||
modelValue: {
|
|
||||||
type: Object as () => IMidjourneyImagineResponse,
|
|
||||||
default: undefined
|
|
||||||
},
|
|
||||||
state: {
|
|
||||||
type: Object as () => MidjourneyImagineState,
|
|
||||||
default: undefined
|
|
||||||
}
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
midjourneyImagineState: MidjourneyImagineState
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
.preview {
|
|
||||||
width: 100%;
|
|
||||||
text-align: center;
|
|
||||||
.image {
|
|
||||||
width: 300px;
|
|
||||||
height: 300px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</style>
|
|
||||||
@@ -0,0 +1,86 @@
|
|||||||
|
<template>
|
||||||
|
<div class="tasks">
|
||||||
|
<div v-for="(task, taskKey) in tasks" :key="taskKey" class="task">
|
||||||
|
<task-preview :model-value="task" @custom="$emit('custom', $event)" />
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import { ElSlider } from 'element-plus';
|
||||||
|
import TaskPreview from './TaskPreview.vue';
|
||||||
|
import { IApplication, IMidjourneyImagineTask, apiUsageOperator, midjourneyOperator } from '@/operators';
|
||||||
|
|
||||||
|
interface IData {
|
||||||
|
historyTasks: IMidjourneyImagineTask[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'TaskBriefList',
|
||||||
|
components: {
|
||||||
|
TaskPreview
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
activeTask: {
|
||||||
|
type: Object as () => IMidjourneyImagineTask | undefined,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
application: {
|
||||||
|
type: Object as () => IApplication | undefined,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['update:modelValue', 'custom'],
|
||||||
|
data(): IData {
|
||||||
|
return {
|
||||||
|
historyTasks: []
|
||||||
|
};
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
tasks() {
|
||||||
|
return [...(this.activeTask ? [this.activeTask] : []), ...this.historyTasks];
|
||||||
|
}
|
||||||
|
},
|
||||||
|
watch: {
|
||||||
|
application(val) {
|
||||||
|
if (val) {
|
||||||
|
this.getHistoryTasks();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
async getHistoryTasks() {
|
||||||
|
const {
|
||||||
|
data: { items: apiUsages }
|
||||||
|
} = await apiUsageOperator.getAll({
|
||||||
|
user_id: this.$store.state.user.id,
|
||||||
|
application_id: this.application?.id,
|
||||||
|
offset: 0,
|
||||||
|
limit: 5,
|
||||||
|
ordering: '-created_at'
|
||||||
|
});
|
||||||
|
const tasks = await Promise.all(
|
||||||
|
apiUsages.map(async (apiUsage) => {
|
||||||
|
const taskId = apiUsage.metadata?.task_id;
|
||||||
|
const { data: task } = await midjourneyOperator.task(taskId);
|
||||||
|
return task;
|
||||||
|
})
|
||||||
|
);
|
||||||
|
this.historyTasks = tasks.filter((task) => task && task?.response);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.tasks {
|
||||||
|
padding-top: 20px;
|
||||||
|
height: 100%;
|
||||||
|
overflow-y: scroll;
|
||||||
|
border-left: 1px solid var(--el-border-color);
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,149 @@
|
|||||||
|
<template>
|
||||||
|
<div class="preview">
|
||||||
|
<div class="info mb-4">
|
||||||
|
<div class="left">
|
||||||
|
<el-tag v-if="modelValue?.response?.success === true" type="success">成功</el-tag>
|
||||||
|
<el-tag v-if="modelValue?.response?.success === false" type="danger">失败</el-tag>
|
||||||
|
</div>
|
||||||
|
<div class="right"></div>
|
||||||
|
</div>
|
||||||
|
<div v-if="modelValue?.state === midjourneyImagineState.PENDING" class="content">
|
||||||
|
<p>图像生成中...</p>
|
||||||
|
</div>
|
||||||
|
<div v-else class="content">
|
||||||
|
<el-image
|
||||||
|
v-if="modelValue?.response?.image_url"
|
||||||
|
:src="modelValue?.response?.image_url"
|
||||||
|
fit="fill"
|
||||||
|
class="image"
|
||||||
|
/>
|
||||||
|
<p v-if="modelValue?.response?.progress !== undefined && modelValue?.response?.progress !== 100" class="progress">
|
||||||
|
{{ modelValue?.response?.progress }}%
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
<div class="operations">
|
||||||
|
<el-button
|
||||||
|
v-for="(action, actionKey) in modelValue?.response?.actions"
|
||||||
|
:key="actionKey"
|
||||||
|
type="info"
|
||||||
|
size="small"
|
||||||
|
class="btn-action"
|
||||||
|
@click="onCustom(action)"
|
||||||
|
>
|
||||||
|
{{ actionMapping[action] }}
|
||||||
|
</el-button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts">
|
||||||
|
import { defineComponent } from 'vue';
|
||||||
|
import { ElImage, ElTag, ElButton } from 'element-plus';
|
||||||
|
import { IMidjourneyImagineTask, MidjourneyImagineAction, MidjourneyImagineState } from '@/operators';
|
||||||
|
|
||||||
|
interface IData {
|
||||||
|
midjourneyImagineState: typeof MidjourneyImagineState;
|
||||||
|
actionMapping: Record<MidjourneyImagineAction, string>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default defineComponent({
|
||||||
|
name: 'TaskPreview',
|
||||||
|
components: {
|
||||||
|
ElImage,
|
||||||
|
ElTag,
|
||||||
|
ElButton
|
||||||
|
},
|
||||||
|
props: {
|
||||||
|
modelValue: {
|
||||||
|
type: Object as () => IMidjourneyImagineTask | undefined,
|
||||||
|
required: true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
emits: ['custom'],
|
||||||
|
data(): IData {
|
||||||
|
return {
|
||||||
|
midjourneyImagineState: MidjourneyImagineState,
|
||||||
|
actionMapping: {
|
||||||
|
[MidjourneyImagineAction.GENERATE]: 'Generate',
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE1]: 'U1',
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE2]: 'U2',
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE3]: 'U3',
|
||||||
|
[MidjourneyImagineAction.UPSAMPLE4]: 'U4',
|
||||||
|
[MidjourneyImagineAction.VARIATION1]: 'V1',
|
||||||
|
[MidjourneyImagineAction.VARIATION2]: 'V2',
|
||||||
|
[MidjourneyImagineAction.VARIATION3]: 'V3',
|
||||||
|
[MidjourneyImagineAction.VARIATION4]: 'V4',
|
||||||
|
[MidjourneyImagineAction.HIGH_VARIATION]: 'Vary (Strong)',
|
||||||
|
[MidjourneyImagineAction.LOW_VARIATION]: 'Vary (Subtle)',
|
||||||
|
[MidjourneyImagineAction.ZOOM_OUT_2X]: 'Zoom Out 2x',
|
||||||
|
[MidjourneyImagineAction.ZOOM_OUT_1_5X]: 'Zoom Out 1.5x',
|
||||||
|
[MidjourneyImagineAction.SQUARE]: 'Make Square',
|
||||||
|
[MidjourneyImagineAction.PAN_LEFT]: '⬅️',
|
||||||
|
[MidjourneyImagineAction.PAN_UP]: '⬆️',
|
||||||
|
[MidjourneyImagineAction.PAN_DOWN]: '⬇️',
|
||||||
|
[MidjourneyImagineAction.PAN_RIGHT]: '➡️',
|
||||||
|
[MidjourneyImagineAction.REROLL]: '🔄'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
},
|
||||||
|
methods: {
|
||||||
|
onCustom(action: string) {
|
||||||
|
this.$emit('custom', {
|
||||||
|
action,
|
||||||
|
image_id: this.modelValue?.response?.image_id
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style lang="scss" scoped>
|
||||||
|
.preview {
|
||||||
|
width: 350px;
|
||||||
|
padding: 15px;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: 20px;
|
||||||
|
margin-bottom: 20px;
|
||||||
|
border: 1px solid var(--el-border-color);
|
||||||
|
|
||||||
|
.info {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: stretch;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.content {
|
||||||
|
width: 100%;
|
||||||
|
position: relative;
|
||||||
|
margin-bottom: 10px;
|
||||||
|
.image {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
.progress {
|
||||||
|
position: absolute;
|
||||||
|
top: 49%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
font-size: 20px;
|
||||||
|
font-weight: bold;
|
||||||
|
color: white;
|
||||||
|
text-shadow: 0 0 5px black;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.operations {
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
flex-direction: row;
|
||||||
|
width: 100%;
|
||||||
|
align-items: baseline;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
|
||||||
|
.btn-action {
|
||||||
|
margin-bottom: 10px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
export const ENDPOINT_API = 'https://api.zhishuyun.com';
|
||||||
|
export const ENDPOINT_DATA = 'https://data.zhishuyun.com';
|
||||||
@@ -4,3 +4,4 @@ export * from './user';
|
|||||||
export * from './api';
|
export * from './api';
|
||||||
export * from './chat';
|
export * from './chat';
|
||||||
export * from './midjourney';
|
export * from './midjourney';
|
||||||
|
export * from './usage';
|
||||||
@@ -15,7 +15,24 @@ export interface IMidjourneyPreset {
|
|||||||
|
|
||||||
export enum MidjourneyImagineAction {
|
export enum MidjourneyImagineAction {
|
||||||
GENERATE = 'generate',
|
GENERATE = 'generate',
|
||||||
UPSAMPLE1 = 'upsample1'
|
UPSAMPLE1 = 'upsample1',
|
||||||
|
UPSAMPLE2 = 'upsample2',
|
||||||
|
UPSAMPLE3 = 'upsample3',
|
||||||
|
UPSAMPLE4 = 'upsample4',
|
||||||
|
VARIATION1 = 'variation1',
|
||||||
|
VARIATION2 = 'variation2',
|
||||||
|
VARIATION3 = 'variation3',
|
||||||
|
VARIATION4 = 'variation4',
|
||||||
|
HIGH_VARIATION = 'high_variation',
|
||||||
|
LOW_VARIATION = 'low_variation',
|
||||||
|
ZOOM_OUT_2X = 'zoom_out_2x',
|
||||||
|
ZOOM_OUT_1_5X = 'zoom_out_1_5x',
|
||||||
|
SQUARE = 'square',
|
||||||
|
PAN_LEFT = 'pan_left',
|
||||||
|
PAN_UP = 'pan_up',
|
||||||
|
PAN_DOWN = 'pan_down',
|
||||||
|
PAN_RIGHT = 'pan_right',
|
||||||
|
REROLL = 'reroll'
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum MidjourneyImagineState {
|
export enum MidjourneyImagineState {
|
||||||
@@ -26,8 +43,8 @@ export enum MidjourneyImagineState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface IMidjourneyImagineRequest {
|
export interface IMidjourneyImagineRequest {
|
||||||
action: MidjourneyImagineAction;
|
action?: MidjourneyImagineAction;
|
||||||
prompt: string;
|
prompt?: string;
|
||||||
image_id?: string;
|
image_id?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,11 +54,20 @@ export interface IMidjourneyImagineResponse {
|
|||||||
image_id: string;
|
image_id: string;
|
||||||
image_url: string;
|
image_url: string;
|
||||||
actions: MidjourneyImagineAction[];
|
actions: MidjourneyImagineAction[];
|
||||||
|
code?: string;
|
||||||
|
detail?: string;
|
||||||
|
success?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IMidjourneyImagineTask {
|
||||||
|
request?: IMidjourneyImagineRequest;
|
||||||
|
response?: IMidjourneyImagineResponse;
|
||||||
|
state?: MidjourneyImagineState;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IMidjourneyImagineOptions {
|
export interface IMidjourneyImagineOptions {
|
||||||
stream?: (response: IMidjourneyImagineResponse) => void;
|
stream?: (response: IMidjourneyImagineResponse) => void;
|
||||||
token: string;
|
token?: string;
|
||||||
endpoint: string;
|
endpoint?: string;
|
||||||
path: string;
|
path?: string;
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,33 @@
|
|||||||
import axios, { AxiosResponse } from 'axios';
|
import axios, { AxiosResponse } from 'axios';
|
||||||
import { IMidjourneyImagineOptions, IMidjourneyImagineRequest, IMidjourneyImagineResponse } from './models';
|
import { IMidjourneyImagineRequest, IMidjourneyImagineResponse, IMidjourneyImagineTask } from './models';
|
||||||
|
import { ENDPOINT_API } from '../common/contants';
|
||||||
|
|
||||||
class MidjourneyOperator {
|
class MidjourneyOperator {
|
||||||
|
async task(id: string): Promise<AxiosResponse<IMidjourneyImagineTask>> {
|
||||||
|
return await axios.post(
|
||||||
|
`/midjourney/tasks`,
|
||||||
|
{
|
||||||
|
action: 'retrieve',
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
accept: 'application/json',
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
baseURL: ENDPOINT_API
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
async imagine(
|
async imagine(
|
||||||
data: IMidjourneyImagineRequest,
|
data: IMidjourneyImagineRequest,
|
||||||
options: IMidjourneyImagineOptions
|
options: {
|
||||||
|
stream: (response: IMidjourneyImagineResponse) => void;
|
||||||
|
token: string;
|
||||||
|
endpoint: string;
|
||||||
|
path: string;
|
||||||
|
}
|
||||||
): Promise<AxiosResponse<IMidjourneyImagineResponse>> {
|
): Promise<AxiosResponse<IMidjourneyImagineResponse>> {
|
||||||
return await axios.post(options.path, data, {
|
return await axios.post(options.path, data, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
Whitespace-only changes.
@@ -0,0 +1,2 @@
|
|||||||
|
export * from './operator';
|
||||||
|
export * from './models';
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
import { IApi } from '../api';
|
||||||
|
|
||||||
|
export interface IApiUsage {
|
||||||
|
id?: string;
|
||||||
|
api?: IApi;
|
||||||
|
api_id?: string;
|
||||||
|
application_id?: string;
|
||||||
|
trace_id?: string;
|
||||||
|
metadata?: any;
|
||||||
|
created_at?: string;
|
||||||
|
updated_at?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IApiUsageListResponse {
|
||||||
|
count: number;
|
||||||
|
items: IApiUsage[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type IApiUsageDetailResponse = IApiUsage;
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import { AxiosResponse } from 'axios';
|
||||||
|
import { httpClient } from '../instance';
|
||||||
|
import { IApiUsageDetailResponse, IApiUsageListResponse } from './models';
|
||||||
|
|
||||||
|
export interface IApiUsageQuery {
|
||||||
|
user_id?: string;
|
||||||
|
offset?: number;
|
||||||
|
limit?: number;
|
||||||
|
application_id?: string;
|
||||||
|
ordering?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ApiUsageOperator {
|
||||||
|
key = 'usage/apis';
|
||||||
|
|
||||||
|
async getAll(query: IApiUsageQuery): Promise<AxiosResponse<IApiUsageListResponse>> {
|
||||||
|
return await httpClient.get(`/${this.key}/`, {
|
||||||
|
params: query
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async get(id: string): Promise<AxiosResponse<IApiUsageDetailResponse>> {
|
||||||
|
return await httpClient.get(`/${this.key}/${id}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const apiUsageOperator = new ApiUsageOperator();
|
||||||
@@ -10,7 +10,9 @@
|
|||||||
<elements-selector v-model="elements" class="mb-4" />
|
<elements-selector v-model="elements" class="mb-4" />
|
||||||
<ignore-selector v-model="ignore" class="mb-4" />
|
<ignore-selector v-model="ignore" class="mb-4" />
|
||||||
<el-button type="primary" @click="onGenerate"> 生成 </el-button>
|
<el-button type="primary" @click="onGenerate"> 生成 </el-button>
|
||||||
<imagine-preview v-model="response" :state="state" />
|
</div>
|
||||||
|
<div class="tasks">
|
||||||
|
<task-brief-list :active-task="task" :application="application" @custom="onCustom" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -23,7 +25,6 @@ import ElementsSelector from '@/components/midjourney/ElementsSelector.vue';
|
|||||||
import IgnoreSelector from '@/components/midjourney/IgnoreSelector.vue';
|
import IgnoreSelector from '@/components/midjourney/IgnoreSelector.vue';
|
||||||
import { ElButton, ElImage } from 'element-plus';
|
import { ElButton, ElImage } from 'element-plus';
|
||||||
import ChannelSelector from '@/components/midjourney/ChannelSelector.vue';
|
import ChannelSelector from '@/components/midjourney/ChannelSelector.vue';
|
||||||
import ImaginePreview from '@/components/midjourney/ImaginePreview.vue';
|
|
||||||
import {
|
import {
|
||||||
IApplication,
|
IApplication,
|
||||||
IMidjourneyChannel,
|
IMidjourneyChannel,
|
||||||
@@ -33,9 +34,12 @@ import {
|
|||||||
MIDJOURNEY_CHANNEL_FAST,
|
MIDJOURNEY_CHANNEL_FAST,
|
||||||
applicationOperator,
|
applicationOperator,
|
||||||
midjourneyOperator,
|
midjourneyOperator,
|
||||||
MidjourneyImagineState
|
MidjourneyImagineState,
|
||||||
|
IMidjourneyImagineTask,
|
||||||
|
IMidjourneyImagineRequest
|
||||||
} from '@/operators';
|
} from '@/operators';
|
||||||
import ApiStatus from '@/components/common/ApiStatus.vue';
|
import ApiStatus from '@/components/common/ApiStatus.vue';
|
||||||
|
import TaskBriefList from '@/components/midjourney/TaskBriefList.vue';
|
||||||
|
|
||||||
interface IData {
|
interface IData {
|
||||||
channel: IMidjourneyChannel;
|
channel: IMidjourneyChannel;
|
||||||
@@ -46,8 +50,7 @@ interface IData {
|
|||||||
initializing: boolean;
|
initializing: boolean;
|
||||||
applied: boolean | undefined;
|
applied: boolean | undefined;
|
||||||
application: IApplication | undefined;
|
application: IApplication | undefined;
|
||||||
response: IMidjourneyImagineResponse | undefined;
|
task: IMidjourneyImagineTask | undefined;
|
||||||
state: MidjourneyImagineState | undefined;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
@@ -59,8 +62,8 @@ export default defineComponent({
|
|||||||
ElementsSelector,
|
ElementsSelector,
|
||||||
IgnoreSelector,
|
IgnoreSelector,
|
||||||
ElButton,
|
ElButton,
|
||||||
ImaginePreview,
|
ApiStatus,
|
||||||
ApiStatus
|
TaskBriefList
|
||||||
},
|
},
|
||||||
data(): IData {
|
data(): IData {
|
||||||
return {
|
return {
|
||||||
@@ -72,18 +75,17 @@ export default defineComponent({
|
|||||||
ignore: '',
|
ignore: '',
|
||||||
initializing: false,
|
initializing: false,
|
||||||
applied: undefined,
|
applied: undefined,
|
||||||
response: undefined,
|
task: undefined
|
||||||
state: undefined
|
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.onFetchChannel();
|
this.onFetchApplication();
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async onSelectChannel() {
|
async onSelectChannel() {
|
||||||
await this.onFetchChannel();
|
await this.onFetchApplication();
|
||||||
},
|
},
|
||||||
async onFetchChannel() {
|
async onFetchApplication() {
|
||||||
this.initializing = true;
|
this.initializing = true;
|
||||||
const { data: applications } = await applicationOperator.getAll({
|
const { data: applications } = await applicationOperator.getAll({
|
||||||
user_id: this.$store.state.user.id,
|
user_id: this.$store.state.user.id,
|
||||||
@@ -96,39 +98,60 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
this.application = applications.items[0];
|
this.application = applications.items[0];
|
||||||
},
|
},
|
||||||
async onGenerate() {
|
async onStartTask(request: IMidjourneyImagineRequest) {
|
||||||
this.state = MidjourneyImagineState.PENDING;
|
|
||||||
const token = this.application?.credential?.token;
|
const token = this.application?.credential?.token;
|
||||||
const endpoint = this.application?.api?.endpoint;
|
const endpoint = this.application?.api?.endpoint;
|
||||||
const path = this.application?.api?.path;
|
const path = this.application?.api?.path;
|
||||||
if (!token || !endpoint || !this.prompt || !path) {
|
if (!token || !endpoint || !path) {
|
||||||
console.error('no token or endpoint or question');
|
console.error('no token or endpoint or question');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
this.task = {
|
||||||
|
...this.task,
|
||||||
|
request,
|
||||||
|
state: MidjourneyImagineState.PENDING
|
||||||
|
};
|
||||||
midjourneyOperator
|
midjourneyOperator
|
||||||
.imagine(
|
.imagine(request, {
|
||||||
{
|
token,
|
||||||
prompt: this.prompt,
|
endpoint,
|
||||||
action: MidjourneyImagineAction.GENERATE
|
path,
|
||||||
},
|
stream: (response: IMidjourneyImagineResponse) => {
|
||||||
{
|
console.log(response);
|
||||||
token,
|
this.task = {
|
||||||
endpoint,
|
...this.task,
|
||||||
path,
|
state: MidjourneyImagineState.GENERATING,
|
||||||
stream: (response: IMidjourneyImagineResponse) => {
|
response
|
||||||
console.log(response);
|
};
|
||||||
this.state = MidjourneyImagineState.GENERATING;
|
|
||||||
this.response = response;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
)
|
|
||||||
.then((res) => {
|
|
||||||
this.state = MidjourneyImagineState.FINISHED;
|
|
||||||
console.log(res);
|
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.then(() => {
|
||||||
this.state = MidjourneyImagineState.FAILED;
|
this.task = {
|
||||||
|
...this.task,
|
||||||
|
state: MidjourneyImagineState.FINISHED
|
||||||
|
};
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
this.task = {
|
||||||
|
...this.task,
|
||||||
|
state: MidjourneyImagineState.FAILED,
|
||||||
|
response: error?.response as IMidjourneyImagineResponse
|
||||||
|
};
|
||||||
});
|
});
|
||||||
|
},
|
||||||
|
async onCustom(payload: { image_id: string; action: MidjourneyImagineAction }) {
|
||||||
|
const request = {
|
||||||
|
image_id: payload.image_id,
|
||||||
|
action: payload.action
|
||||||
|
};
|
||||||
|
this.onStartTask(request);
|
||||||
|
},
|
||||||
|
async onGenerate() {
|
||||||
|
const request = {
|
||||||
|
prompt: this.prompt,
|
||||||
|
action: MidjourneyImagineAction.GENERATE
|
||||||
|
};
|
||||||
|
this.onStartTask(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -143,7 +166,7 @@ export default defineComponent({
|
|||||||
.presets {
|
.presets {
|
||||||
width: 260px;
|
width: 260px;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
background-color: var(--el-bg-color-page);
|
// background-color: var(--el-bg-color-page);
|
||||||
}
|
}
|
||||||
.main {
|
.main {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
@@ -153,5 +176,10 @@ export default defineComponent({
|
|||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
.tasks {
|
||||||
|
width: 400px;
|
||||||
|
height: 100%;
|
||||||
|
// background-color: var(--el-bg-color-page);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
Reference in new issue
Block a user