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

+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>