Add sora duration support (#282)

This commit is contained in:
Germey authored and GitHub committed 2025-10-28 12:22:55 +08:00
1 parent c371ea794c
commit fee415e490
5 files changed
+40 -65

No files matched your search

@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "change duration limit",
"packageName": "@acedatacloud/nexior",
"email": "cqc@cuiqingcai.com",
"dependentChangeType": "patch"
}
+13 -26
View File
@@ -2,18 +2,17 @@
<div class="field">
<div class="control">
<h2 class="title font-bold">{{ $t('sora.name.duration') }}</h2>
<el-select v-model="value" class="value" :placeholder="$t('sora.placeholder.select')" :disabled="isLocked">
<el-select v-model="value" class="value" :placeholder="$t('sora.placeholder.select')">
<el-option v-for="item in optionsForModel" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</div>
<p v-if="isLocked" class="hint">{{ $t('sora.tip.proOnly') }}</p>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElSelect, ElOption } from 'element-plus';
import { SORA_ALLOWED_DURATIONS, SORA_DEFAULT_DURATION, SORA_DEFAULT_MODEL, SORA_MODEL_PRO } from '@/constants';
import { SORA_ALLOWED_DURATIONS_BY_MODEL, SORA_DEFAULT_DURATION, SORA_DEFAULT_MODEL } from '@/constants';
export default defineComponent({
name: 'DurationSelector',
@@ -21,26 +20,18 @@ export default defineComponent({
ElSelect,
ElOption
},
data() {
return {
options: SORA_ALLOWED_DURATIONS.map((duration) => ({
value: duration,
label: `${duration}s`
}))
};
},
computed: {
model(): string {
return this.$store.state.sora?.config?.model || SORA_DEFAULT_MODEL;
},
isLocked(): boolean {
return this.model !== SORA_MODEL_PRO;
allowedDurations(): number[] {
return SORA_ALLOWED_DURATIONS_BY_MODEL[this.model] || [SORA_DEFAULT_DURATION];
},
optionsForModel(): Array<{ value: number; label: string }> {
if (this.isLocked) {
return this.options.filter((option) => option.value === SORA_DEFAULT_DURATION);
}
return this.options;
return this.allowedDurations.map((duration) => ({
value: duration,
label: `${duration}s`
}));
},
value: {
get(): number | undefined {
@@ -56,9 +47,11 @@ export default defineComponent({
}
},
watch: {
isLocked(newValue: boolean) {
if (newValue && this.value !== SORA_DEFAULT_DURATION) {
this.value = SORA_DEFAULT_DURATION;
allowedDurations() {
const durations = this.allowedDurations;
if (!durations.includes(this.value as number)) {
const fallback = durations.includes(SORA_DEFAULT_DURATION) ? SORA_DEFAULT_DURATION : durations[0];
this.value = fallback;
}
}
},
@@ -92,10 +85,4 @@ export default defineComponent({
.value {
width: 120px;
}
.hint {
margin-top: 4px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
</style>
+12 -9
View File
@@ -11,6 +11,7 @@
import { defineComponent } from 'vue';
import { ElSelect, ElOption } from 'element-plus';
import {
SORA_ALLOWED_DURATIONS_BY_MODEL,
SORA_DEFAULT_DURATION,
SORA_DEFAULT_MODEL,
SORA_DEFAULT_SIZE,
@@ -52,19 +53,21 @@ export default defineComponent({
},
set(val: string) {
const currentConfig = this.$store.state.sora?.config || {};
const allowedDurations = SORA_ALLOWED_DURATIONS_BY_MODEL[val] || [SORA_DEFAULT_DURATION];
const currentDuration = currentConfig.duration as number | undefined;
const resolvedDuration =
currentDuration && allowedDurations.includes(currentDuration)
? currentDuration
: allowedDurations.includes(SORA_DEFAULT_DURATION)
? SORA_DEFAULT_DURATION
: allowedDurations[0];
const nextConfig = {
...currentConfig,
model: val
model: val,
duration: resolvedDuration,
size: currentConfig.size || SORA_DEFAULT_SIZE
} as Record<string, any>;
if (val === SORA_MODEL_STANDARD) {
nextConfig.duration = SORA_DEFAULT_DURATION;
nextConfig.size = SORA_DEFAULT_SIZE;
} else if (val === SORA_MODEL_PRO) {
nextConfig.duration = nextConfig.duration || SORA_DEFAULT_DURATION;
nextConfig.size = nextConfig.size || SORA_DEFAULT_SIZE;
}
this.$store.commit('sora/setConfig', nextConfig);
}
}
+3 -29
View File
@@ -2,18 +2,17 @@
<div class="field">
<div class="control">
<h2 class="title font-bold">{{ $t('sora.name.size') }}</h2>
<el-select v-model="value" class="value" :placeholder="$t('sora.placeholder.select')" :disabled="isLocked">
<el-option v-for="item in optionsForModel" :key="item.value" :label="item.label" :value="item.value" />
<el-select v-model="value" class="value" :placeholder="$t('sora.placeholder.select')">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</div>
<p v-if="isLocked" class="hint">{{ $t('sora.tip.proOnly') }}</p>
</div>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
import { ElSelect, ElOption } from 'element-plus';
import { SORA_ALLOWED_SIZES, SORA_DEFAULT_MODEL, SORA_DEFAULT_SIZE, SORA_MODEL_PRO } from '@/constants';
import { SORA_ALLOWED_SIZES, SORA_DEFAULT_SIZE } from '@/constants';
const formatSizeLabel = (value: string): string => {
if (!value) {
@@ -37,18 +36,6 @@ export default defineComponent({
};
},
computed: {
model(): string {
return this.$store.state.sora?.config?.model || SORA_DEFAULT_MODEL;
},
isLocked(): boolean {
return this.model !== SORA_MODEL_PRO;
},
optionsForModel(): Array<{ value: string; label: string }> {
if (this.isLocked) {
return this.options.filter((option) => option.value === SORA_DEFAULT_SIZE);
}
return this.options;
},
value: {
get(): string | undefined {
return this.$store.state.sora?.config?.size;
@@ -62,13 +49,6 @@ export default defineComponent({
}
}
},
watch: {
isLocked(newValue: boolean) {
if (newValue && this.value !== SORA_DEFAULT_SIZE) {
this.value = SORA_DEFAULT_SIZE;
}
}
},
mounted() {
if (!this.value) {
this.value = SORA_DEFAULT_SIZE;
@@ -99,10 +79,4 @@ export default defineComponent({
.value {
width: 120px;
}
.hint {
margin-top: 4px;
font-size: 12px;
color: var(--el-text-color-secondary);
}
</style>
+5 -1
View File
@@ -5,10 +5,14 @@ export const SORA_MODEL_PRO = 'sora-2-pro';
export const SORA_DEFAULT_MODEL = SORA_MODEL_STANDARD;
export const SORA_DEFAULT_DURATION = 10;
export const SORA_ALLOWED_DURATIONS = [10, 15];
export const SORA_DEFAULT_SIZE = 'small';
export const SORA_ALLOWED_SIZES = ['small', 'large'];
export const SORA_DEFAULT_ACTION = 'text2video';
export const SORA_DEFAULT_ORIENTATION = 'landscape';
export const SORA_DEFAULT_TRANSLATION = false;
export const SORA_DEFAULT_EXTEND_IMG = false;
export const SORA_ALLOWED_DURATIONS_BY_MODEL: Record<string, number[]> = {
[SORA_MODEL_STANDARD]: [10, 15],
[SORA_MODEL_PRO]: [10, 15, 25]
};