This commit is contained in:
HCode authored and GitHub committed 2025-02-19 15:01:06 +00:00
1 parent 1203ef569b
commit 5d8902e566
40 files changed
+2416 -1

No files matched your search

@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "add flux",
"packageName": "@acedatacloud/nexior",
"email": "1348977728@qq.com",
"dependentChangeType": "patch"
}
+38
View File
@@ -0,0 +1,38 @@
<template>
<el-menu mode="horizontal" :default-active="active">
<el-menu-item v-if="site?.features?.midjourney?.enabled" index="/midjourney" @click="$router.push('/midjourney')">
{{ $t('common.nav.midjourney') }}
</el-menu-item>
<el-menu-item v-if="site?.features?.flux?.enabled" index="/flux" @click="$router.push('/flux')">
{{ $t('common.nav.flux') }}
</el-menu-item>
</el-menu>
</template>
<script lang="ts">
import { ElMenu, ElMenuItem } from 'element-plus';
import { defineComponent } from 'vue';
export default defineComponent({
name: 'ImageNavigator',
components: {
ElMenu,
ElMenuItem
},
computed: {
site() {
return this.$store.state.site;
},
active() {
console.log(this.$route.path);
return this.$route.path;
}
}
});
</script>
<style lang="scss" scoped>
.el-menu {
justify-content: center;
}
</style>
+78
View File
@@ -0,0 +1,78 @@
<template>
<div class="panel">
<div class="config">
<prompt-input class="mb-4" />
<model-selector class="mb-4" />
<div class="actions">
<el-button
v-if="config?.video_url !== undefined || config?.custom"
type="primary"
class="btn w-full"
round
@click="onGenerate"
>
<font-awesome-icon icon="fa-solid fa-magic" class="mr-2" />
{{ $t('flux.button.extend') }}
</el-button>
<el-button v-else type="primary" class="btn w-full" round @click="onGenerate">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-2" />
{{ $t('flux.button.generate') }}
</el-button>
</div>
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import ModelSelector from './config/ModelSelector.vue';
import PromptInput from './config/PromptInput.vue';
// import RatioSelector from './config/RatioSelector.vue';
// import NumbersSelector from './config/NumbersSelector.vue';
// import QualitySelector from './config/QualitySelector.vue';
export default defineComponent({
name: 'PresetPanel',
components: {
ElButton,
FontAwesomeIcon,
PromptInput,
ModelSelector
},
emits: ['generate'],
computed: {
config() {
return this.$store.state.flux?.config;
}
},
methods: {
onGenerate() {
this.$emit('generate');
}
}
});
</script>
<style lang="scss" scoped>
.panel {
height: 100%;
padding: 15px;
display: flex;
flex-direction: column;
.config {
width: 100%;
height: calc(100% - 50px);
flex: 1;
}
.actions {
height: 50px;
display: flex;
justify-content: center;
align-items: center;
.btn {
width: 100%;
}
}
}
</style>
+23
View File
@@ -0,0 +1,23 @@
<template>
<div class="panel detail">
<task-detail />
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import TaskDetail from './task/Detail.vue';
export default defineComponent({
name: 'DetailPanel',
components: {
TaskDetail
},
data() {
return {
job: 0
};
},
computed: {}
});
</script>
+100
View File
@@ -0,0 +1,100 @@
<template>
<div class="image-gallery">
<div class="image-container">
<img :src="modelValue.image_url" alt="Image" />
<button class="view-button" @click="viewImage(modelValue.image_url)">
{{ $t('flux.button.viewImage') }}
</button>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, computed } from 'vue';
import { IFluxImage } from '@/models';
interface IDataItem {
image_url: string;
// Add other properties if necessary
}
interface IResponse {
data: IDataItem[];
}
export default defineComponent({
name: 'ImageGallery',
props: {
modelValue: {
type: Object as () => IFluxImage | undefined,
required: true
}
},
setup(props) {
// Computed property to extract the first two images
// Method to handle the "View Image" button click
const viewImage = (url: string) => {
window.open(url, '_blank');
};
return {
viewImage
};
}
});
</script>
<style lang="scss" scoped>
.image-gallery {
display: flex;
justify-content: space-between;
gap: 16px;
}
.image-container {
position: relative;
width: 48%; /* Ensures two images fit side by side with some space */
overflow: hidden;
border: 1px solid #ddd;
border-radius: 8px;
img {
width: 100%;
height: auto;
display: block;
transition: transform 0.3s ease;
}
/* Zoom effect on hover */
&:hover img {
transform: scale(1.05);
}
.view-button {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background-color: rgba(0, 0, 0, 0.6);
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 4px;
cursor: pointer;
opacity: 0;
transition: opacity 0.3s ease;
/* Optional: Add a slight delay for smoother appearance */
transition-delay: 0.1s;
&:hover {
background-color: rgba(0, 0, 0, 0.8);
}
}
/* Show the button on hover */
&:hover .view-button {
opacity: 1;
}
}
</style>
+77
View File
@@ -0,0 +1,77 @@
<template>
<div>
<el-card v-show="operating">
<content-input class="mb-4" />
<prompt-input class="mb-4" />
<preset-selector class="mb-4" />
<div class="actions">
<el-button type="primary" class="btn w-full" round @click="onGenerate">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-2" />
{{ $t('flux.button.generate') }}
</el-button>
</div>
</el-card>
<div>
<el-button type="primary" class="btn btn-operate" @click="operating = !operating">+</el-button>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElButton, ElCard } from 'element-plus';
import PresetSelector from './config/PresetSelector2.vue';
import ContentInput from './config/ContentInput.vue';
import PromptInput from './config/PromptInput.vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
export default defineComponent({
name: 'OperationPanel',
components: {
ElButton,
ElCard,
PresetSelector,
ContentInput,
PromptInput,
FontAwesomeIcon
},
emits: ['generate'],
data() {
return {
operating: false
};
},
methods: {
onGenerate() {
this.$emit('generate');
this.operating = false;
}
}
});
</script>
<style lang="scss" scoped>
.el-card {
width: 580px;
height: fit-content;
overflow-y: scroll;
position: absolute;
bottom: 70px;
left: calc(50% - 300px);
@media (max-width: 767px) {
width: 100%;
left: 0;
}
}
.btn-operate {
width: 50px;
height: 50px;
border-radius: 50%;
font-size: 24px;
line-height: 40px;
padding: 0;
margin: auto;
display: block;
}
</style>
+141
View File
@@ -0,0 +1,141 @@
<template>
<div ref="panel" class="panel recent" @scroll="onHandleScroll">
<div v-if="tasks?.items === undefined" class="tasks">
<div v-for="_ in 3" :key="_" class="task placeholder">
<div class="left">
<el-skeleton animated>
<template #template>
<el-skeleton-item variant="image" class="avatar" />
</template>
</el-skeleton>
</div>
<div class="main">
<el-skeleton animated>
<template #template>
<el-skeleton-item variant="p" class="title" />
<el-skeleton-item variant="image" class="icon" />
</template>
</el-skeleton>
</div>
</div>
</div>
<div v-else-if="tasks?.items?.length && tasks?.items?.length > 0" class="tasks">
<task-preview v-for="(task, taskIndex) in tasks?.items" :key="taskIndex" :model-value="task" class="preview" />
</div>
<p v-if="tasks?.items?.length === 0" class="description">
{{ $t('flux.message.noTasks') }}
</p>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import TaskPreview from './task/Preview.vue';
import { ElSkeleton, ElSkeletonItem } from 'element-plus';
export default defineComponent({
name: 'RecentPanel',
components: {
TaskPreview,
ElSkeleton,
ElSkeletonItem
},
emits: ['reach-top'],
data() {
return {
job: 0
};
},
computed: {
tasks() {
// reverse the order of the tasks.items
return {
...this.$store.state.flux?.tasks,
items: this.$store.state.flux?.tasks?.items?.slice()
};
}
},
methods: {
onHandleScroll() {
const el = this.$refs.panel as HTMLElement;
console.log('reach-top reach-top reach-top');
if (el.scrollTop === 0) {
this.$emit('reach-top');
}
}
}
});
</script>
<style lang="scss" scoped>
.panel {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
height: 100%;
&.recent {
width: 100%;
height: 100%;
display: flex;
overflow-y: auto;
flex-direction: column;
.preview {
margin-right: 15px;
}
.description {
text-align: left;
font-size: 14px;
color: var(--el-text-color-secondary);
}
.tasks {
width: 100%;
.task {
margin-bottom: 15px;
width: 100%;
height: fit-content;
text-align: left;
&.placeholder {
display: flex;
flex-direction: row;
.left {
width: 70px;
padding: 10px;
.avatar {
width: 50px;
height: 50px;
border-radius: 50%;
}
}
.main {
width: calc(100% - 70px);
flex: 1;
padding: 10px;
margin-bottom: 10px;
.icon {
display: flex;
height: 200px;
width: 300px;
}
.title {
display: block;
width: 200px;
height: 20px;
margin-bottom: 15px;
}
}
}
.operations {
height: fit-content !important;
}
}
}
}
}
</style>
+40
View File
@@ -0,0 +1,40 @@
<template>
<div>
<vue-plyr :options="options" class="video">
<video controls crossorigin playsinline :data-poster="modelValue?.image_url">
<source size="1080" :src="modelValue?.video_url" type="video/mp4" />
</video>
</vue-plyr>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
// @ts-ignore
import VuePlyr from '@skjnldsv/vue-plyr';
// @ts-ignore
import { IPikaVideo } from '@/models';
import '@skjnldsv/vue-plyr/dist/vue-plyr.css';
export default defineComponent({
name: 'VideoPlayer',
components: { VuePlyr },
props: {
modelValue: {
type: Object as () => IPikaVideo | undefined,
required: true
}
},
data() {
return {
options: { quality: { default: '1080p' } }
};
}
});
</script>
<style lang="scss" scoped>
.video {
max-width: 100%;
height: 450px;
}
</style>
@@ -0,0 +1,115 @@
<template>
<div class="field">
<h2 class="title">{{ $t('pika.name.effect') }}</h2>
<el-select v-model="value" class="value" :placeholder="$t('pika.placeholder.select')" clearable>
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value">
<span class="float-left">{{ item.label }}</span>
<!-- <span class="float-right">{{ item.value }}</span> -->
</el-option>
</el-select>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSelect, ElOption } from 'element-plus';
export default defineComponent({
name: 'EffectSelector',
components: {
ElSelect,
ElOption
},
data() {
return {};
},
computed: {
options() {
return [
{
value: 'Levitate',
label: this.$t('pika.style.effect1')
},
{
value: 'Decapitate',
label: this.$t('pika.style.effect2')
},
{
value: 'Eye-pop',
label: this.$t('pika.style.effect3')
},
{
value: 'Ta-da',
label: this.$t('pika.style.effect4')
},
{
value: 'Deflate',
label: this.$t('pika.style.effect5')
},
{
value: 'Crumble',
label: this.$t('pika.style.effect6')
},
{
value: 'Dissolve',
label: this.$t('pika.style.effect7')
},
{
value: 'Squish',
label: this.$t('pika.style.effect8')
},
{
value: 'Inflate',
label: this.$t('pika.style.effect9')
},
{
value: 'Melt',
label: this.$t('pika.style.effect10')
},
{
value: 'Cake-ify',
label: this.$t('pika.style.effect11')
},
{
value: 'Crush',
label: this.$t('pika.style.effect12')
},
{
value: 'Explode',
label: this.$t('pika.style.effect13')
}
];
},
value: {
get() {
return this.$store.state.pika?.config?.effect;
},
set(val) {
this.$store.commit('pika/setConfig', {
...this.$store.state.pika?.config,
effect: val
});
}
}
},
watch: {},
mounted() {}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
.title {
font-size: 14px;
margin: 0;
width: 30%;
}
.value {
flex: 1;
}
}
</style>
@@ -0,0 +1,87 @@
<template>
<div class="field">
<h2 class="title">{{ $t('flux.name.model') }}</h2>
<el-select v-model="value" class="value" :placeholder="$t('flux.placeholder.select')">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSelect, ElOption } from 'element-plus';
import { FLUX_DEFAULT_MODEL } from '@/constants';
export default defineComponent({
name: 'ModelSelector',
components: {
ElSelect,
ElOption
},
props: {
modelValue: {
type: String,
default: undefined
}
},
emits: ['update:modelValue'],
data() {
return {
options: [
{
value: 'flux',
label: 'flux'
},
{
value: 'flux-schnell',
label: 'flux-schnell'
},
{
value: 'flux-dev',
label: 'flux-dev'
},
{
value: 'flux-pro',
label: 'flux-pro'
}
]
};
},
computed: {
value: {
get() {
return this.$store.state.flux?.config?.model;
},
set(val) {
this.$store.commit('flux/setConfig', {
...this.$store.state.flux.config,
model: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = FLUX_DEFAULT_MODEL;
}
}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
.title {
font-size: 14px;
margin: 0;
width: 30%;
}
.value {
width: 80px;
}
}
</style>
@@ -0,0 +1,51 @@
<template>
<div>
<div class="flex justify-between">
<div class="flex justify-start items-center">
<span class="text-sm font-bold">{{ $t('flux.name.numbers') }}</span>
<info-icon :content="$t('flux.description.numbers')" />
</div>
<div class="flex justify-end items-center">
<el-input-number v-model="value" size="small" controls-position="right" />
</div>
</div>
<div class="w-full">
<el-slider v-model="value" :min="1" :max="4" :step="1" />
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSlider, ElInputNumber } from 'element-plus';
import InfoIcon from '@/components/common/InfoIcon.vue';
import { FLUX_DEFAULT_NUMBERS } from '@/constants';
export default defineComponent({
name: 'NumbersSelector',
components: {
ElSlider,
InfoIcon,
ElInputNumber
},
computed: {
value: {
get() {
return this.$store.state.flux?.config?.numbers;
},
set(val) {
console.debug('set stylize', val);
this.$store.commit('flux/setConfig', {
...this.$store.state.flux?.config,
numbers: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = FLUX_DEFAULT_NUMBERS;
}
}
});
</script>
@@ -0,0 +1,71 @@
<template>
<div class="field">
<div class="box">
<h2 class="title">{{ $t('flux.name.prompt') }}</h2>
<info-icon :content="$t('flux.description.prompt')" class="info" />
</div>
<el-input
v-model="prompt"
:rows="3"
type="textarea"
class="prompt"
:placeholder="$t('flux.placeholder.prompt')"
:maxlength="300"
show-word-limit
/>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElInput } from 'element-plus';
import InfoIcon from '@/components/common/InfoIcon.vue';
export const DEFAULT_PROMPT = '';
export default defineComponent({
name: 'PromptInput',
components: {
ElInput,
InfoIcon
},
computed: {
prompt: {
get() {
return this.$store.state.flux?.config?.prompt;
},
set(val) {
console.debug('set prompt', val);
this.$store.commit('flux/setConfig', {
...this.$store.state.flux?.config,
prompt: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = DEFAULT_PROMPT;
}
}
});
</script>
<style lang="scss" scoped>
.field {
.box {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between; // Add this line to move the icon to the right
position: relative;
.title {
font-size: 14px;
margin-bottom: 10px;
}
}
.info {
margin-left: auto; // Ensure the icon stays on the right
}
}
</style>
@@ -0,0 +1,68 @@
<template>
<div>
<div class="flex justify-between">
<div class="flex justify-start items-center">
<span class="text-sm font-bold">{{ $t('flux.name.quality') }}</span>
<info-icon :content="$t('flux.description.quality')" />
</div>
<div class="flex justify-end items-center">
<el-input-number v-model="value" size="small" controls-position="right" />
</div>
</div>
<div class="w-full">
<el-slider v-model="value" :min="1" :max="100" :step="1" />
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { ElSlider, ElInputNumber } from 'element-plus';
import InfoIcon from '@/components/common/InfoIcon.vue';
import { FLUX_DEFAULT_QUALITY } from '@/constants';
export default defineComponent({
name: 'QualitySelector',
components: {
ElSlider,
InfoIcon,
ElInputNumber
},
computed: {
value: {
get() {
return this.$store.state.flux.config.quality;
},
set(val) {
console.debug('set quality', val);
this.$store.commit('flux/setConfig', {
...this.$store.state.flux.config,
quality: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = FLUX_DEFAULT_QUALITY;
}
}
});
</script>
<style lang="scss" scoped>
.field {
display: flex;
flex-direction: row;
align-items: center;
.title {
font-size: 14px;
margin: 0;
width: 30%;
}
.value {
flex: 1;
}
}
</style>
@@ -0,0 +1,168 @@
<template>
<div>
<h2 class="title">{{ $t('flux.name.ratio') }}</h2>
<div class="items">
<div
v-for="(option, optionKey) in options"
:key="optionKey"
:class="{ active: active === optionKey, item: true }"
@click="value = option.value"
>
<div class="preview" :class="option.label">
<div class="rect" :style="{ width: option.width + 'px', height: option.height + 'px' }"></div>
</div>
<p class="name">
{{ option.label }}
</p>
</div>
</div>
</div>
</template>
<script>
import { defineComponent } from 'vue';
import { FLUX_DEFAULT_ASPECT_RATIO } from '@/constants';
export default defineComponent({
name: 'RatioSelector',
data() {
return {
options: [
{
value: '1:1',
label: '1:1',
width: 20,
height: 20
},
{
value: '2:3',
label: '2:3',
width: 18,
height: 27
},
{
value: '3:2',
label: '3:2',
width: 27,
height: 18
},
{
value: '4:3',
label: '4:3',
width: 20,
height: 15
},
{
value: '3:4',
label: '3:4',
width: 15,
height: 20
},
{
value: '16:9',
label: '16:9',
width: 25,
height: 13
},
{
value: '9:16',
label: '9:16',
width: 13,
height: 25
}
]
};
},
computed: {
active() {
return this.options.findIndex((option) => option.value === this.value) || 0;
},
value: {
get() {
return this.$store.state.flux?.config?.aspect_ratio;
},
set(val) {
console.debug('set ratio', val);
this.$store.commit('flux/setConfig', {
...this.$store.state.flux.config,
aspect_ratio: val
});
}
}
},
mounted() {
if (!this.value) {
this.value = FLUX_DEFAULT_ASPECT_RATIO;
}
}
});
</script>
<style lang="scss" scoped>
.title {
font-size: 14px;
margin-bottom: 10px;
}
.items {
display: grid;
grid-template-columns: repeat(5, 48px); // 固定每行5列
gap: 8px; // 元素间距
justify-content: start; // 左对齐
.item {
width: 48px;
height: 65px;
border: 2px solid var(--el-border-color);
display: flex;
flex-direction: column;
align-items: center;
cursor: pointer;
border-radius: 5px;
flex-shrink: 0;
.preview {
margin-top: 8px;
width: 30px;
height: 30px;
display: flex;
align-items: center;
justify-content: center;
.rect {
border: 2px solid var(--el-border-color);
width: 20px;
height: 20px;
border-radius: 2px;
}
}
.name {
display: block;
font-size: 12px;
color: var(--el-text-color-primary);
}
&.active {
border-color: var(--el-color-primary);
.rect {
border-color: var(--el-color-primary);
}
}
}
}
/* 响应式处理 */
@media (max-width: 480px) {
.items {
grid-template-columns: repeat(5, 48px); // 固定每行5列
gap: 8px; // 元素间距
}
}
@media (min-width: 481px) and (max-width: 768px) {
.items {
grid-template-columns: repeat(5, 48px); // 固定每行5列
gap: 8px; // 元素间距
}
}
</style>
+306
View File
@@ -0,0 +1,306 @@
<template>
<div v-for="(image, imageIndex) in images" :key="imageIndex" class="preview">
<div class="left">
<el-image src="https://cdn.acedata.cloud/i80tgn.png" class="avatar" />
</div>
<div class="main">
<div class="bot">
{{ $t('flux.name.fluxBot') }}
<span class="datetime">
{{ $dayjs.format('' + new Date(parseFloat(modelValue?.created_at || '') * 1000)) }}
</span>
</div>
<div class="info">
<p v-if="modelValue?.request?.prompt" class="prompt mt-2">
{{ modelValue?.request?.prompt }}
<span v-if="!modelValue?.response"> - ({{ $t('flux.status.pending') }}) </span>
<span v-if="image?.state === 'processing' || image?.state === 'pending' || image?.state === 'completed'">
- ({{ $t('flux.status.processing') }})
</span>
</p>
</div>
<!-- Display success message -->
<div v-if="modelValue?.response?.success === true" :class="{ content: true, failed: true }">
<div class="image-wrapper">
<image-gallery :model-value="image" />
</div>
<div v-if="image" :class="{ operations: true, 'mt-2': true }">
<el-tooltip class="box-item" effect="dark" :content="$t('flux.message.downloadImage')" placement="top-start">
<el-button type="info" size="small" class="btn-action" @click="onDownload($event, image?.image_url)">
{{ $t('flux.button.download') }}
</el-button>
</el-tooltip>
</div>
<el-alert :closable="false" class="mt-2 success">
<p class="description">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
{{ $t('flux.name.taskId') }}:
{{ modelValue?.id }}
<copy-to-clipboard :content="modelValue?.id!" class="btn-copy" />
</p>
</el-alert>
</div>
<!-- Display error message -->
<div v-if="modelValue?.response?.success === false" :class="{ content: true }">
<el-alert :closable="false" class="failure">
<template #template>
<font-awesome-icon icon="fa-solid fa-exclamation-triangle" class="mr-1" />
{{ $t('flux.name.failure') }}
</template>
<p class="description">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
{{ $t('flux.name.taskId') }}:
{{ modelValue?.id }}
<copy-to-clipboard :content="modelValue?.id!" class="btn-copy" />
</p>
<p class="description">
<font-awesome-icon icon="fa-solid fa-circle-info" class="mr-1" />
{{ $t('flux.name.failureReason') }}:
{{ modelValue?.response?.error?.message }}
<copy-to-clipboard :content="modelValue?.response?.error?.message!" class="btn-copy" />
</p>
<p class="description">
<font-awesome-icon icon="fa-solid fa-hashtag" class="mr-1" />
{{ $t('flux.name.traceId') }}:
{{ modelValue?.response?.trace_id }}
<copy-to-clipboard :content="modelValue?.response?.trace_id" class="btn-copy" />
</p>
</el-alert>
</div>
<!-- Display error message -->
<div
v-if="!modelValue?.response || image?.state === 'processing' || image?.state === 'pending'"
:class="{ content: true }"
>
<el-alert :closable="false" class="info">
<template #template>
<font-awesome-icon icon="fa-solid fa-exclamation-triangle" class="mr-1" />
{{ $t('flux.name.failure') }}
</template>
<p class="description">
<font-awesome-icon icon="fa-solid fa-magic" class="mr-1" />
{{ $t('flux.name.taskId') }}:
{{ modelValue?.id }}
<copy-to-clipboard :content="modelValue?.id!" class="btn-copy" />
</p>
</el-alert>
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElImage, ElAlert, ElButton, ElTooltip } from 'element-plus';
import { IFluxTask, IFluxGenerateResponse, IFluxImage } from '@/models';
import CopyToClipboard from '@/components/common/CopyToClipboard.vue';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import ImageGallery from '../ImageGallery.vue';
export default defineComponent({
name: 'TaskPreview',
components: {
ElImage,
CopyToClipboard,
FontAwesomeIcon,
ElAlert,
ElTooltip,
ElButton,
ImageGallery
},
props: {
modelValue: {
type: Object as () => IFluxTask | undefined,
required: true
}
},
data() {
return {};
},
computed: {
application() {
return this.$store.state.flux?.application;
},
config() {
return this.$store.state.flux?.config;
},
images(): IFluxImage[] {
let result: IFluxImage[] = [];
// @ts-ignore
const action = this.modelValue?.request?.action;
if (Array.isArray(this.modelValue?.response?.data)) {
this.modelValue?.response?.data?.forEach((item: any) => {
let image = item as IFluxImage;
// Add the action field to the image object
if (action) {
image.action = action;
}
result.push(image);
});
}
return result;
}
},
methods: {
onDownload(event: MouseEvent, image_url: string) {
event.stopPropagation();
console.log('on download');
// download url here
window.open(image_url, '_blank');
},
onOpenImage(url: string) {
window.open(url, '_blank');
}
}
});
</script>
<style lang="scss" scoped>
$left-width: 70px;
.preview {
width: 100%;
height: fit-content;
text-align: left;
display: flex;
flex-direction: row;
margin-bottom: 15px;
.left {
width: $left-width;
.avatar {
background-color: rgb(34, 34, 34);
padding: 2px;
width: 50px;
height: 50px;
margin: 10px;
border-radius: 50%;
}
}
.main {
flex: 1;
width: calc(100% - $left-width);
padding: 10px 10px 0 10px;
.bot {
font-size: 16px;
font-weight: bold;
color: rgb(46, 204, 113);
margin-bottom: 0;
margin-top: 0;
.datetime {
font-size: 12px;
font-weight: normal;
color: var(--el-text-color-secondary);
margin-left: 10px;
}
}
.info {
.prompt {
font-size: 14px;
font-weight: bold;
color: var(--el-text-color-regular);
margin-bottom: 10px;
}
}
.content {
.el-alert {
border-left-width: 2px;
border-left-style: solid;
&.failure {
border-color: var(--el-color-danger);
}
&.success {
border-color: var(--el-color-success);
}
&.info {
border-color: var(--el-color-info);
}
}
}
.image-wrapper {
position: relative;
width: fit-content;
min-height: 50px;
min-width: 100px;
.image {
max-height: 400px;
max-width: 500px;
display: block;
width: fit-content;
}
.btn-raw {
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
z-index: 1000;
display: none;
}
.play-icon {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 48px;
color: white;
z-index: 500;
pointer-events: none; /* Ensure the icon doesn't interfere with hover */
}
&:hover {
.image {
filter: brightness(0.6);
}
.btn-raw {
display: block;
}
.play-icon {
display: none;
}
}
}
.operations {
display: flex;
justify-content: left;
flex-direction: row;
width: 100%;
align-items: baseline;
flex-wrap: wrap;
overflow: hidden;
text-align: center;
color: var(--el-text-color-regular);
font-size: 14px;
overflow-y: scroll;
&.full {
height: 70px;
}
.btn-action {
margin-bottom: 10px;
}
}
}
}
</style>
<style lang="scss">
.preview {
.image.error {
background: var(--el-bg-color-page);
.image-slot {
font-size: 14px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
}
.failure {
background: var(--el-fill-color-light);
width: 100%;
}
}
</style>
+6
View File
@@ -0,0 +1,6 @@
export const FLUX_SERVICE_ID = 'e8ebe055-429a-48e9-9d34-5089eae5fd89';
export const FLUX_DEFAULT_MODEL = 'flux';
export const FLUX_DEFAULT_ASPECT_RATIO = '1:1';
export const FLUX_DEFAULT_NUMBERS = 1;
export const FLUX_DEFAULT_QUALITY = 80;
+1
View File
@@ -7,6 +7,7 @@ export * from './midjourney';
export * from './qrart';
export * from './luma';
export * from './pika';
export * from './flux';
export * from './hailuo';
export * from './headshots';
export * from './suno';
+1
View File
@@ -73,6 +73,7 @@ export const loadLocaleMessages = async (i18n: I18n, locale: string) => {
'qrart',
'luma',
'pika',
'flux',
'hailuo',
'headshots',
'suno',
+4
View File
@@ -311,6 +311,10 @@
"message": "Suno",
"description": "网站导航栏中的文本,用于显示Suno页面,请不要翻译此字段,必须保持为'Suno'"
},
"nav.flux": {
"message": "Flux",
"description": "网站导航栏中的文本,用于显示Flux页面,请不要翻译此字段,必须保持为'Flux'"
},
"nav.luma": {
"message": "Luma",
"description": "网站导航栏中的文本,用于显示Luma页面,请不要翻译此字段,必须保持为'Luma'"
+222
View File
@@ -0,0 +1,222 @@
{
"name.taskId": {
"message": "任务 ID",
"description": "任务的 ID"
},
"name.type": {
"message": "类型",
"description": "要生成的 FLux图片的内容类型,如'链接'、'文本'等"
},
"name.failure": {
"message": "失败",
"description": "任务的失败状态"
},
"name.failureReason": {
"message": "失败原因",
"description": "任务失败的原因"
},
"name.status": {
"message": "状态",
"description": "任务的状态"
},
"name.traceId": {
"message": "追踪 ID",
"description": "任务的追踪 ID"
},
"name.createdAt": {
"message": "创建时间",
"description": "生成 Flux 图片的日期和时间"
},
"name.numbers": {
"message": "图片数量",
"description": "要生成的图片数量"
},
"name.quality": {
"message": "图片质量",
"description": "图片质量"
},
"name.prompt": {
"message": "图像提示",
"description": "内容输入的提示"
},
"name.ratio": {
"message": "比例",
"description": "比例参数的名称"
},
"name.model": {
"message": "模型版本",
"description": "要生成图像所采用的模型版本"
},
"name.fluxBot": {
"message": "Flux Bot",
"description": "Flux 图片生成器的名称"
},
"description.numbers": {
"message": "指定生成图片的数量,值的范围为:1-4。",
"description": "参数'numbers'的描述"
},
"description.quality": {
"message": "指定生成图片的质量,值的范围为:1-100。",
"description": "参数'quality'的描述"
},
"description.prompt": {
"message": "生成Flux图像的提示词",
"description": "参数'prompt'的描述"
},
"status.pending": {
"message": "等待中",
"description": "任务的等待状态"
},
"status.processing": {
"message": "处理中",
"description": "任务的等待状态"
},
"placeholder.paddingNoise": {
"message": "请选择...",
"description": "填充噪音输入的占位符"
},
"placeholder.select": {
"message": "选择",
"description": "选择字段中的占位文本"
},
"placeholder.paddingLevel": {
"message": "请选择...",
"description": "填充级别的占位符"
},
"placeholder.prompt": {
"message": "输入要生成的图片风格的提示词,例如:a white siamese cat",
"description": "提示字段中的占位文本"
},
"placeholder.position": {
"message": "请选择...",
"description": "位置输入的占位符"
},
"placeholder.aspectRatio": {
"message": "请选择...",
"description": "宽高比输入的占位符"
},
"placeholder.preset": {
"message": "请选择...",
"description": "预设输入的占位符"
},
"placeholder.markerShape": {
"message": "请选择...",
"description": "标记形状输入的占位符"
},
"placeholder.rotate": {
"message": "请选择...",
"description": "旋转输入的占位符"
},
"placeholder.subMarker": {
"message": "请选择...",
"description": "子标记输入的占位符"
},
"button.generate": {
"message": "生成",
"description": "生成Flux图像的按钮文本"
},
"button.extend": {
"message": "扩展图片",
"description": "扩展图片按钮文本"
},
"button.viewImage": {
"message": "查看原图",
"description": "生成Flux图片 的按钮文本"
},
"button.download": {
"message": "下载图片",
"description": "下载图片按钮文本"
},
"message.downloadImage": {
"message": "打开图片新窗口",
"description": "打开图片新窗口"
},
"message.uploadReferencesExceed": {
"message": "最多可上传 5 张图片",
"description": "上传的图片数量超过限制时的错误消息"
},
"message.uploadReferencesSuccess": {
"message": "成功上传图片",
"description": "成功上传图片时的成功消息"
},
"message.uploadReferencesError": {
"message": "上传图片失败,请稍后重试",
"description": "图片上传失败时的错误消息"
},
"message.startingTask": {
"message": "正在启动任务...",
"description": "绘图任务开始时的消息"
},
"message.startTaskSuccess": {
"message": "成功发起生成任务",
"description": "成功启动任务时的成功消息"
},
"message.startTaskFailed": {
"message": "发起任务失败,请联系管理员",
"description": "启动绘图任务失败时的错误消息"
},
"message.usedUp": {
"message": "您的积分已用完,请购买更多积分后继续使用",
"description": "已用完时的消息"
},
"message.generating": {
"message": "生成中...",
"description": "图像正在生成时的消息"
},
"message.downloadVideo": {
"message": "下载此图片",
"description": "图像正在生成时的消息"
},
"message.extendVideo": {
"message": "继续生成此图片",
"description": "图像正在生成时的消息"
},
"message.generateFailed": {
"message": "生成图像失败",
"description": "图像生成失败时的消息"
},
"message.uploadVideoExceed": {
"message": "上传首帧图片数量超过限制",
"description": "上传首帧图片数量超过限制时的错误信息"
},
"message.uploadVideoSizeExceed": {
"message": "上传文件大小不能超过 10MB!",
"description": "上传文件大小不能超过 10MB!时的错误信息"
},
"message.uploadVideoTypeFailed": {
"message": "上传文件必须是 MP4 格式!",
"description": "上传文件必须是 MP4 格式!的错误信息"
},
"message.uploadStartImageExceed": {
"message": "上传首帧图片数量超过限制",
"description": "上传首帧图片数量超过限制时的错误信息"
},
"message.uploadEndImageExceed": {
"message": "上传尾帧图片数量超过限制",
"description": "上传首帧图片数量超过限制时的错误信息"
},
"message.uploadStartImageError": {
"message": "上传首帧图片失败",
"description": "上传首帧图片失败时的错误信息"
},
"message.uploadVideoError": {
"message": "上传图片失败",
"description": "上传首帧图片失败时的错误信息"
},
"message.uploadEndImageError": {
"message": "上传尾帧图片失败",
"description": "上传尾帧图片失败时的错误信息"
},
"message.uploadDocumentsError": {
"message": "上传文档失败",
"description": "上传文档失败时的错误信息"
},
"message.noOperations": {
"message": "没有可用操作",
"description": "没有可用操作时的消息"
},
"message.noTasks": {
"message": "没有历史任务,请点击左方生成图片",
"description": "没有任务时的消息"
}
}
+8
View File
@@ -79,6 +79,10 @@
"message": "Suno",
"description": "展示在编辑框的标题"
},
"field.featuresFlux": {
"message": "Flux",
"description": "展示在编辑框的标题"
},
"field.featuresSupport": {
"message": "客服支持",
"description": "展示在编辑框的标题"
@@ -267,6 +271,10 @@
"message": "打开或关闭 Suno 功能模块。",
"description": "Suno 功能的描述"
},
"message.featuresFlux": {
"message": "打开或关闭 FLux 功能模块。",
"description": "FLux 功能的描述"
},
"message.featuresLuma": {
"message": "打开或关闭 Luma 功能模块。",
"description": "Luma 功能的描述"
+83
View File
@@ -0,0 +1,83 @@
<template>
<div class="main">
<div class="config">
<image-navigator />
<slot name="config" />
</div>
<div class="result">
<slot name="result" />
</div>
<el-button round class="menu" @click="drawer = true">
<font-awesome-icon icon="fa-solid fa-gear" class="icon-menu" />
</el-button>
<el-drawer v-model="drawer" :with-header="false" size="340px" class="drawer">
<slot name="config" />
</el-drawer>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElDrawer, ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import ImageNavigator from '@/components/common/ImageNavigator.vue';
export default defineComponent({
name: 'LayoutFlux',
components: {
ElDrawer,
ElButton,
FontAwesomeIcon,
ImageNavigator
},
data() {
return {
drawer: false
};
}
});
</script>
<style lang="scss" scoped>
.main {
flex: 1;
display: flex;
flex-direction: row;
.config {
width: 300px;
height: 100%;
overflow-y: scroll;
border-right: 1px solid var(--el-border-color);
}
.result {
height: 100%;
padding: 15px;
flex: 1;
width: calc(100% - 300px);
height: 100%;
display: flex;
flex-direction: column;
}
}
.menu {
display: none;
}
@media (max-width: 767px) {
.config {
display: none;
}
.result {
width: 100%;
}
.menu {
display: block;
position: fixed;
left: 15px;
top: 15px;
z-index: 2000;
}
}
</style>
+4 -1
View File
@@ -1,6 +1,7 @@
<template>
<div class="main">
<div class="presets">
<image-navigator />
<slot name="presets" />
</div>
<div class="operation">
@@ -19,13 +20,15 @@
import { defineComponent } from 'vue';
import { ElDrawer, ElButton } from 'element-plus';
import { FontAwesomeIcon } from '@fortawesome/vue-fontawesome';
import ImageNavigator from '@/components/common/ImageNavigator.vue';
export default defineComponent({
name: 'LayoutMidjourney',
components: {
ElDrawer,
ElButton,
FontAwesomeIcon
FontAwesomeIcon,
ImageNavigator
},
data() {
return {
+45
View File
@@ -0,0 +1,45 @@
export interface IFluxConfig {
action?: string;
prompt?: string;
model?: string;
callback_url?: string;
}
export interface IFluxGenerateRequest {
action?: string;
prompt?: string;
model?: string;
callback_url?: string;
mirror?: boolean;
}
export interface IFluxImage {
image_url?: string;
timings?: number;
prompt?: string;
action?: string;
seed?: number;
}
export interface IFluxGenerateResponse {
success: boolean;
task_id: string;
trace_id: string;
data?: IFluxImage[];
error?: {
code?: string;
message?: string;
};
}
export interface IFluxTask {
id: string;
created_at?: number;
request?: IFluxGenerateRequest;
response?: IFluxGenerateResponse;
}
export type IFluxTaskResponse = IFluxTask;
export interface IFluxTasksResponse {
count: number;
items: IFluxTask[];
}
+1
View File
@@ -14,6 +14,7 @@ export * from './credential';
export * from './qrart';
export * from './luma';
export * from './pika';
export * from './flux';
export * from './hailuo';
export * from './headshots';
export * from './suno';
+112
View File
@@ -0,0 +1,112 @@
import axios, { AxiosResponse } from 'axios';
import { IFluxGenerateRequest, IFluxGenerateResponse, IFluxTaskResponse, IFluxTasksResponse } from '@/models';
import { BASE_URL_API } from '@/constants';
class FluxOperator {
async task(id: string, options: { token: string }): Promise<AxiosResponse<IFluxTaskResponse>> {
return await axios.post(
`/flux/tasks`,
{
action: 'retrieve',
id: id
},
{
headers: {
accept: 'application/json',
'content-type': 'application/json',
authorization: `Bearer ${options.token}`,
'x-record-exempt': 'true'
},
baseURL: BASE_URL_API
}
);
}
async tasks(
filter: {
ids?: string[];
applicationId?: string;
userId?: string;
type?: string;
limit?: number;
offset?: number;
createdAtMax?: number;
createdAtMin?: number;
},
options: { token: string }
): Promise<AxiosResponse<IFluxTasksResponse>> {
return await axios.post(
`/flux/tasks`,
{
action: 'retrieve_batch',
...(filter.ids
? {
ids: filter.ids
}
: {}),
...(filter.applicationId
? {
application_id: filter.applicationId
}
: {}),
...(filter.userId
? {
user_id: filter.userId
}
: {}),
...(filter.type
? {
type: filter.type
}
: {}),
...(filter.limit !== undefined
? {
limit: filter.limit
}
: {}),
...(filter.offset !== undefined
? {
offset: filter.offset
}
: {}),
...(filter.createdAtMax !== undefined
? {
created_at_max: filter.createdAtMax
}
: {}),
...(filter.createdAtMin !== undefined
? {
created_at_min: filter.createdAtMin
}
: {})
},
{
headers: {
accept: 'application/json',
'content-type': 'application/json',
authorization: `Bearer ${options.token}`,
'x-record-exempt': 'true'
},
baseURL: BASE_URL_API
}
);
}
async generate(
data: IFluxGenerateRequest,
options: {
token: string;
}
): Promise<AxiosResponse<IFluxGenerateResponse>> {
return await axios.post('/flux/images', data, {
headers: {
authorization: `Bearer ${options.token}`,
'content-type': 'application/json',
accept: 'application/x-ndjson'
},
baseURL: BASE_URL_API
});
}
}
export const fluxOperator = new FluxOperator();
+1
View File
@@ -14,6 +14,7 @@ export * from './credential';
export * from './qrart';
export * from './luma';
export * from './pika';
export * from './flux';
export * from './hailuo';
export * from './headshots';
export * from './site';
+229
View File
@@ -0,0 +1,229 @@
<template>
<layout>
<template #config>
<config-panel @generate="onGenerateVideo" />
</template>
<template #result>
<application-status
:initializing="initializing"
:application="application"
:service="service"
:need-apply="needApply"
class="mb-4"
@refresh="onGetApplication"
/>
<recent-panel class="panel recent" @reach-top="onReachTop" />
<!-- <operation-panel class="panel operation" @generate="onGenerate" /> -->
</template>
</layout>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import Layout from '@/layouts/Flux.vue';
import ConfigPanel from '@/components/flux/ConfigPanel.vue';
import { applicationOperator, fluxOperator } from '@/operators';
import { IApplicationDetailResponse, IFluxGenerateRequest, Status } from '@/models';
import { ElMessage } from 'element-plus';
import { ERROR_CODE_DUPLICATION, ERROR_CODE_USED_UP } from '@/constants';
import ApplicationStatus from '@/components/application/Status.vue';
import RecentPanel from '@/components/flux/RecentPanel.vue';
import { IFluxTask } from '@/models';
const CALLBACK_URL = 'https://webhook.acedata.cloud/flux';
interface IData {
task: IFluxTask | undefined;
job: number;
timer: NodeJS.Timer;
}
export default defineComponent({
name: 'FluxIndex',
components: {
ConfigPanel,
Layout,
ApplicationStatus,
RecentPanel
},
data(): IData {
return {
task: undefined,
job: 0,
// @ts-ignore
timer: undefined
};
},
computed: {
loading() {
return this.$store.state.flux?.status?.getApplications === Status.Request;
},
service() {
return this.$store.state.flux?.service;
},
credential() {
return this.$store.state.flux?.credential;
},
config() {
return this.$store.state.flux?.config;
},
initializing() {
return this.$store.state.flux?.status?.getApplications === Status.Request;
},
needApply() {
return this.$store.state.flux?.status?.getApplications === Status.Success && !this.application;
},
application() {
return this.$store.state.flux?.application;
},
tasks() {
return this.$store.state.flux?.tasks;
}
},
watch: {
tasks: {
handler(value, oldValue) {
// scroll down if new tasks are added
if (value?.items?.length > oldValue?.items?.length) {
console.debug('new tasks detected');
// this.onScrollDown();
}
},
deep: true
}
},
async mounted() {
await this.onGetService();
await this.onGetApplication();
await this.onScrollDown();
await this.onGetTasks();
// await this.onScrollDown();
// @ts-ignore
this.job = setInterval(() => {
this.onGetTasks();
}, 5000);
},
async unmounted() {
clearInterval(this.job);
clearInterval(this.timer);
},
methods: {
async onReachTop() {
console.debug('reached top');
await this.onGetTasks({
createdAtMax: this.tasks?.items?.[0]?.created_at
});
},
async onGetService() {
console.debug('start onGetService');
await this.$store.dispatch('flux/getService');
console.debug('end onGetService');
},
async onGetApplication() {
console.debug('start onGetApplication');
await this.$store.dispatch('flux/getApplications');
console.debug('end onGetApplication');
await this.onGetTasks();
},
onApply() {
applicationOperator
.create({
// @ts-ignore
application: this.application
})
.then(({ data: data }: { data: IApplicationDetailResponse }) => {
this.application = data;
ElMessage.success(this.$t('application.message.applySuccessfully'));
})
.catch((error) => {
if (error?.response?.data?.code === ERROR_CODE_DUPLICATION) {
ElMessage.error(this.$t('application.message.alreadyApplied'));
}
});
},
async onScrollDown() {
setTimeout(() => {
// scroll to bottom for `.recent`
const el = document.querySelector('.recent');
if (el) {
el.scrollTop = el.scrollHeight;
}
}, 500);
},
async onGetTasks(payload?: { limit?: number; createdAtMin?: number; createdAtMax?: number }) {
if (this.loading) {
console.debug('loading');
return;
}
console.debug('start onGetTasks', payload);
const { limit = 5, createdAtMin, createdAtMax } = payload || {};
console.debug('limit', limit, 'createdAtMin', createdAtMin, 'createdAtMax', createdAtMax);
await this.$store.dispatch('flux/getTasks', {
limit,
createdAtMin,
createdAtMax
});
},
async onGenerateVideo() {
const request = {
...this.config,
callback_url: CALLBACK_URL
} as IFluxGenerateRequest;
const token = this.credential?.token;
if (!token) {
console.error('no token specified');
return;
}
ElMessage.info(this.$t('flux.message.startingTask'));
fluxOperator
.generate(request, {
token
})
.then(() => {
ElMessage.success(this.$t('flux.message.startTaskSuccess'));
this.$store.commit('flux/setConfig', {
config: undefined
});
})
.catch((error) => {
const response = error?.response?.data;
if (response?.error?.code === ERROR_CODE_USED_UP) {
ElMessage.error(this.$t('flux.message.usedUp'));
} else {
ElMessage.error(this.$t('flux.message.startTaskFailed'));
}
})
.finally(async () => {
setTimeout(async () => {
await this.onGetTasks();
await this.onScrollDown();
}, 1000);
});
}
}
});
</script>
<style lang="scss" scoped>
.status {
margin-bottom: 10px;
}
.panel {
&.detail {
width: 100%;
flex: 1;
overflow-y: scroll;
}
&.recent {
height: 100%;
width: 100%;
margin-bottom: 10px;
position: relative;
justify-content: initial;
}
&.operation {
position: relative;
}
}
</style>
+1
View File
@@ -181,6 +181,7 @@
'suno',
'luma',
'pika',
'flux',
'hailuo',
'headshots',
'support'
+3
View File
@@ -19,6 +19,9 @@ export const ROUTE_LUMA_HISTORY = 'luma-history';
export const ROUTE_PIKA_INDEX = 'pika-index';
export const ROUTE_PIKA_HISTORY = 'pika-history';
export const ROUTE_FLUX_INDEX = 'flux-index';
export const ROUTE_FLUX_HISTORY = 'flux-history';
export const ROUTE_HAILUO_INDEX = 'hailuo-index';
export const ROUTE_HAILUO_HISTORY = 'hailuo-history';
+16
View File
@@ -0,0 +1,16 @@
import { ROUTE_FLUX_INDEX } from './constants';
export default {
path: '/flux',
meta: {
auth: true
},
component: () => import('@/layouts/Main.vue'),
children: [
{
path: '',
name: ROUTE_FLUX_INDEX,
component: () => import('@/pages/flux/Index.vue')
}
]
};
+2
View File
@@ -8,6 +8,7 @@ import chatdoc from './chatdoc';
import qrart from './qrart';
import luma from './luma';
import pika from './pika';
import flux from './flux';
import hailuo from './hailuo';
import headshots from './headshots';
import suno from './suno';
@@ -37,6 +38,7 @@ const routes = [
qrart,
luma,
pika,
flux,
hailuo,
headshots,
suno,
+2
View File
@@ -5,6 +5,7 @@ import { IChatdocState } from '../chatdoc/models';
import { IQrartState } from '../qrart/models';
import { ILumaState } from '../luma/models';
import { IPikaState } from '../pika/models';
import { IFluxState } from '../flux/models';
import { IHailuoState } from '../hailuo/models';
import { IHeadshotsState } from '../headshots/models';
import { ISunoState } from '../suno/models';
@@ -36,6 +37,7 @@ export interface IRootState extends ICommonState {
qrart: IQrartState;
luma: ILumaState;
pika: IPikaState;
flux: IFluxState;
hailuo: IHailuoState;
headshots: IHeadshotsState;
suno: ISunoState;
+175
View File
@@ -0,0 +1,175 @@
import { applicationOperator, fluxOperator, serviceOperator } from '@/operators';
import { IFluxState } from './models';
import { ActionContext } from 'vuex';
import { IRootState } from '../common/models';
import { IApplication, ICredential, IFluxConfig, IFluxTask, IService, IApplicationType } from '@/models';
import { Status } from '@/models/common';
import { FLUX_SERVICE_ID } from '@/constants';
import { mergeAndSortLists } from '@/utils/merge';
export const resetAll = ({ commit }: ActionContext<IFluxState, IRootState>): void => {
commit('resetAll');
};
export const setCredential = async ({ commit }: any, payload: ICredential): Promise<void> => {
console.debug('set credential', payload);
commit('setCredential', payload);
};
export const setConfig = ({ commit }: any, payload: IFluxConfig) => {
commit('setConfig', payload);
};
export const setService = async ({ commit }: any, payload: IService): Promise<void> => {
console.debug('set service', payload);
commit('setService', payload);
};
export const setApplication = ({ commit }: any, payload: IApplication[]) => {
commit('setApplication', payload);
};
export const getApplications = async ({
commit,
state,
rootState
}: ActionContext<IFluxState, IRootState>): Promise<IApplication[]> => {
console.debug('start to get applications for flux');
return new Promise((resolve, reject) => {
state.status.getApplications = Status.Request;
applicationOperator
.getAll({
user_id: rootState?.user?.id,
service_id: FLUX_SERVICE_ID
})
.then((response) => {
console.debug('get applications success', response?.data);
state.status.getApplications = Status.Success;
// 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);
} else {
console.debug('set application with null', response.data.items?.[0]);
commit('setApplication', response.data.items?.[0]);
}
resolve(response.data.items);
console.debug('save application success', response.data.items[0]);
})
.catch((error) => {
state.status.getApplications = Status.Error;
reject(error);
});
});
};
export const setTasks = ({ commit }: any, payload: any) => {
commit('setTasks', payload);
};
export const setTasksItems = ({ commit }: any, payload: IFluxTask[]) => {
commit('setTasksItems', payload);
};
export const setTasksTotal = ({ commit }: any, payload: number) => {
commit('setTasksTotal', payload);
};
export const setTasksActive = ({ commit }: any, payload: IFluxTask) => {
commit('setTasksActive', payload);
};
export const getService = async ({ commit, state }: ActionContext<IFluxState, IRootState>): Promise<IService> => {
return new Promise((resolve, reject) => {
console.debug('start to get service for flux');
state.status.getService = Status.Request;
serviceOperator
.get(FLUX_SERVICE_ID)
.then((response) => {
state.status.getService = Status.Success;
commit('setService', response.data);
resolve(response.data);
})
.catch((error) => {
state.status.getService = Status.Error;
reject(error);
});
});
};
export const getTasks = async (
{ commit, state, rootState }: ActionContext<IFluxState, IRootState>,
{
offset,
limit,
createdAtMin,
createdAtMax
}: { offset?: number; limit?: number; createdAtMin?: number; createdAtMax?: number }
): Promise<IFluxTask[]> => {
return new Promise((resolve, reject) => {
console.debug('start to get tasks', offset, limit);
const credential = state.credential;
const token = credential?.token;
if (!token) {
return reject('no token');
}
fluxOperator
.tasks(
{
userId: rootState?.user?.id,
createdAtMin,
createdAtMax,
type: 'images'
},
{
token
}
)
.then((response) => {
console.debug('get videos tasks success', response.data.items);
// merge with existing tasks
const existingItems = state?.tasks?.items || [];
console.debug('existing items', existingItems);
const newItems = response.data.items || [];
console.debug('new items', newItems);
// sort and de-duplicate using created_at
const mergedItems = mergeAndSortLists(existingItems, newItems);
commit('setTasksItems', mergedItems);
commit('setTasksTotal', response.data.count);
resolve(response.data.items);
})
.catch((error) => {
return reject(error);
});
});
};
export default {
setService,
getService,
resetAll,
setCredential,
setConfig,
setApplication,
getApplications,
setTasks,
setTasksItems,
setTasksTotal,
setTasksActive,
getTasks
};
+14
View File
@@ -0,0 +1,14 @@
import { Module } from 'vuex';
import { IFluxState } from './models';
import actions from './actions';
import mutations from './mutations';
import state from './state';
export const flux: Module<IFluxState, any> = {
namespaced: true,
state,
mutations,
actions
};
export default flux;
+22
View File
@@ -0,0 +1,22 @@
import { IApplication, ICredential, IService, Status } from '@/models';
import { IFluxConfig, IFluxTask } from '@/models';
export interface IFluxState {
application: IApplication | undefined;
applications: IApplication[] | undefined;
service: IService | undefined;
credential: ICredential | undefined;
config: IFluxConfig | undefined;
tasks:
| {
items: IFluxTask[] | undefined;
total: number | undefined;
active: IFluxTask | undefined;
}
| undefined;
status: {
getService: Status;
getApplications: Status;
getTasks: Status;
};
}
+71
View File
@@ -0,0 +1,71 @@
import { IApplication, ICredential, IFluxConfig, IFluxTask, IService } from '@/models';
import { IFluxState } from './models';
export const resetAll = (state: IFluxState): void => {
state.service = undefined;
state.application = undefined;
state.config = undefined;
state.credential = undefined;
state.tasks = undefined;
};
export const setService = (state: IFluxState, payload: IService): void => {
state.service = payload;
};
export const setCredential = (state: IFluxState, payload: ICredential): void => {
state.credential = payload;
};
export const setApplication = (state: IFluxState, payload: IApplication): void => {
state.application = payload;
};
export const setApplications = (state: IFluxState, payload: IApplication[]): void => {
state.applications = payload;
};
export const setConfig = (state: IFluxState, payload: IFluxConfig): void => {
state.config = payload;
};
export const setTasksItems = (state: IFluxState, payload: IFluxTask[]): void => {
const newPayload = {
...state.tasks,
items: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasksTotal = (state: IFluxState, payload: number): void => {
const newPayload = {
...state.tasks,
total: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasksActive = (state: IFluxState, payload: IFluxTask): void => {
const newPayload = {
...state.tasks,
active: payload
} as typeof state.tasks;
state.tasks = newPayload;
};
export const setTasks = (state: IFluxState, payload: any): void => {
state.tasks = payload;
};
export default {
setTasks,
setApplication,
setApplications,
setConfig,
setCredential,
setService,
setTasksActive,
setTasksItems,
setTasksTotal,
resetAll
};
+1
View File
@@ -0,0 +1 @@
export default ['flux.credential', 'flux.application'];
+18
View File
@@ -0,0 +1,18 @@
import { IFluxState } from './models';
import { Status } from '@/models';
export default (): IFluxState => {
return {
service: undefined,
application: undefined,
applications: undefined,
tasks: undefined,
credential: undefined,
config: undefined,
status: {
getService: Status.None,
getApplications: Status.None,
getTasks: Status.None
}
};
};
+4
View File
@@ -6,6 +6,7 @@ import chatdoc from './chatdoc';
import qrart from './qrart';
import luma from './luma';
import pika from './pika';
import flux from './flux';
import hailuo from './hailuo';
import headshots from './headshots';
import suno from './suno';
@@ -16,6 +17,7 @@ import persistChatdoc from './chatdoc/persist';
import persistQrart from './qrart/persist';
import persistLuma from './luma/persist';
import persistPika from './pika/persist';
import persistFlux from './flux/persist';
import persistHailuo from './hailuo/persist';
import persistHeadshots from './headshots/persist';
import persistSuno from './suno/persist';
@@ -29,6 +31,7 @@ const store = createStore({
qrart: qrart,
luma: luma,
pika: pika,
flux: flux,
hailuo: hailuo,
headshots: headshots,
suno: suno,
@@ -44,6 +47,7 @@ const store = createStore({
...persistQrart,
...persistLuma,
...persistPika,
...persistFlux,
...persistHailuo,
...persistHeadshots,
...persistSuno