update mj history
This commit is contained in:
1 parent
d4e406feab
commit
443375fbed
22 files changed
+780
-99
No files matched your search
@@ -0,0 +1,153 @@
|
||||
<template>
|
||||
<div class="page">
|
||||
<div class="presets">
|
||||
<preset-panel v-model="preset" />
|
||||
</div>
|
||||
<div class="main">
|
||||
<channel-selector v-model="channel" class="mb-4" @select="onSelectChannel" />
|
||||
<api-status :application="application" class="mb-4" />
|
||||
<task-full-list :applications="applications" @custom="onCustom" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from 'vue';
|
||||
import PresetPanel from '@/components/midjourney/PresetPanel.vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import ChannelSelector from '@/components/midjourney/ChannelSelector.vue';
|
||||
import ApiStatus from '@/components/common/ApiStatus.vue';
|
||||
import {
|
||||
IApplication,
|
||||
IMidjourneyChannel,
|
||||
MidjourneyImagineAction,
|
||||
IMidjourneyPreset,
|
||||
MIDJOURNEY_CHANNEL_FAST,
|
||||
MIDJOURNEY_CHANNEL_TURBO,
|
||||
MIDJOURNEY_CHANNEL_RELAX,
|
||||
applicationOperator,
|
||||
midjourneyOperator,
|
||||
IMidjourneyImagineTask,
|
||||
IMidjourneyImagineRequest
|
||||
} from '@/operators';
|
||||
import TaskFullList from '@/components/midjourney/tasks/TaskFullList.vue';
|
||||
|
||||
interface IData {
|
||||
channel: IMidjourneyChannel;
|
||||
preset: IMidjourneyPreset;
|
||||
prompt: string;
|
||||
elements: string[];
|
||||
ignore: string;
|
||||
initializing: boolean;
|
||||
applied: boolean | undefined;
|
||||
applications: IApplication[];
|
||||
references: string[];
|
||||
task: IMidjourneyImagineTask | undefined;
|
||||
}
|
||||
|
||||
const CALLBACK_URL = 'https://webhook.zhishuyun.com/midjourney';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MidjourneyIndex',
|
||||
components: {
|
||||
PresetPanel,
|
||||
TaskFullList,
|
||||
ChannelSelector,
|
||||
ApiStatus
|
||||
},
|
||||
data(): IData {
|
||||
return {
|
||||
applications: [],
|
||||
channel: MIDJOURNEY_CHANNEL_FAST,
|
||||
preset: {},
|
||||
prompt: '',
|
||||
elements: [],
|
||||
ignore: '',
|
||||
initializing: false,
|
||||
applied: undefined,
|
||||
task: undefined,
|
||||
references: []
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
application() {
|
||||
if (this.applications && this.applications.length > 0) {
|
||||
return this.applications.filter((item) => item.api_id === this.channel.apiId)[0];
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.onFetchApplications();
|
||||
},
|
||||
methods: {
|
||||
async onFetchApplications() {
|
||||
this.initializing = true;
|
||||
const { data: applications } = await applicationOperator.getAll({
|
||||
user_id: this.$store.state.user.id,
|
||||
api_id: [MIDJOURNEY_CHANNEL_FAST.apiId, MIDJOURNEY_CHANNEL_RELAX.apiId, MIDJOURNEY_CHANNEL_TURBO.apiId]
|
||||
});
|
||||
this.initializing = false;
|
||||
this.applications = applications?.items;
|
||||
},
|
||||
async onSelectChannel() {
|
||||
await this.onFetchApplications();
|
||||
},
|
||||
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');
|
||||
return;
|
||||
}
|
||||
midjourneyOperator
|
||||
.imagine(request, {
|
||||
token,
|
||||
endpoint,
|
||||
path
|
||||
})
|
||||
.then(() => {
|
||||
ElMessage.info(this.$t('midjourney.message.startTaskSuccess'));
|
||||
})
|
||||
.catch(() => {
|
||||
ElMessage.info(this.$t('midjourney.message.startTaskFailed'));
|
||||
});
|
||||
},
|
||||
async onCustom(payload: { image_id: string; action: MidjourneyImagineAction }) {
|
||||
const request = {
|
||||
image_id: payload.image_id,
|
||||
action: payload.action,
|
||||
callback_url: CALLBACK_URL
|
||||
};
|
||||
this.onStartTask(request);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.page {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
.presets {
|
||||
width: 260px;
|
||||
height: 100%;
|
||||
// background-color: var(--el-bg-color-page);
|
||||
}
|
||||
.main {
|
||||
flex: 1;
|
||||
padding: 15px;
|
||||
width: calc(100% - 260px);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
.title {
|
||||
font-size: 14px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -15,8 +15,8 @@
|
||||
<el-button type="primary" :disabled="!finalPrompt" @click="onGenerate"> 生成 </el-button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="tasks">
|
||||
<task-brief-list v-model:active-task="task" :applications="applications" @custom="onCustom" />
|
||||
<div class="result">
|
||||
<task-brief-list :applications="applications" @custom="onCustom" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -62,6 +62,8 @@ interface IData {
|
||||
task: IMidjourneyImagineTask | undefined;
|
||||
}
|
||||
|
||||
const CALLBACK_URL = 'https://webhook.zhishuyun.com/midjourney';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'MidjourneyIndex',
|
||||
components: {
|
||||
@@ -162,44 +164,24 @@ export default defineComponent({
|
||||
console.error('no token or endpoint or question');
|
||||
return;
|
||||
}
|
||||
this.task = {
|
||||
...this.task,
|
||||
request,
|
||||
state: MidjourneyImagineState.PENDING
|
||||
};
|
||||
ElMessage.info(this.$t('midjourney.message.startTaskSuccess'));
|
||||
midjourneyOperator
|
||||
.imagine(request, {
|
||||
token,
|
||||
endpoint,
|
||||
path,
|
||||
stream: (response: IMidjourneyImagineResponse) => {
|
||||
console.log(response);
|
||||
this.task = {
|
||||
...this.task,
|
||||
state: MidjourneyImagineState.GENERATING,
|
||||
response
|
||||
};
|
||||
}
|
||||
path
|
||||
})
|
||||
.then(() => {
|
||||
this.task = {
|
||||
...this.task,
|
||||
state: MidjourneyImagineState.FINISHED
|
||||
};
|
||||
ElMessage.info(this.$t('midjourney.message.startTaskSuccess'));
|
||||
})
|
||||
.catch((error) => {
|
||||
this.task = {
|
||||
...this.task,
|
||||
state: MidjourneyImagineState.FAILED,
|
||||
response: error?.response as IMidjourneyImagineResponse
|
||||
};
|
||||
.catch(() => {
|
||||
ElMessage.info(this.$t('midjourney.message.startTaskFailed'));
|
||||
});
|
||||
},
|
||||
async onCustom(payload: { image_id: string; action: MidjourneyImagineAction }) {
|
||||
const request = {
|
||||
image_id: payload.image_id,
|
||||
action: payload.action
|
||||
action: payload.action,
|
||||
callback_url: CALLBACK_URL
|
||||
};
|
||||
this.onStartTask(request);
|
||||
},
|
||||
@@ -207,7 +189,8 @@ export default defineComponent({
|
||||
const request = {
|
||||
prompt: this.finalPrompt,
|
||||
action: MidjourneyImagineAction.GENERATE,
|
||||
translation: this.preset?.translation
|
||||
translation: this.preset?.translation,
|
||||
callback_url: CALLBACK_URL
|
||||
};
|
||||
this.onStartTask(request);
|
||||
}
|
||||
@@ -234,7 +217,8 @@ export default defineComponent({
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
}
|
||||
.tasks {
|
||||
.result {
|
||||
overflow-y: scroll;
|
||||
width: 400px;
|
||||
height: 100%;
|
||||
// background-color: var(--el-bg-color-page);
|
||||
|
||||
Reference in new issue
Block a user