forked from 77media/video-flow
55 lines
1.3 KiB
TypeScript
55 lines
1.3 KiB
TypeScript
import { TextItem } from '../domain/Item';
|
|
import { updateText } from '@/api/video_flow';
|
|
|
|
/**
|
|
* 文本编辑用例
|
|
* 负责单个文本内容的初始化、修改和优化
|
|
*/
|
|
export class TextEditUseCase {
|
|
constructor(private readonly textItem: TextItem) {
|
|
this.textItem = textItem;
|
|
}
|
|
/**
|
|
* 修改文本内容
|
|
* @param newContent 新内容
|
|
* @returns 更新后的文本项
|
|
*/
|
|
async updateText(newContent: string): Promise<TextItem> {
|
|
if (!this.textItem) {
|
|
throw new Error('文本项未初始化,请先调用 initializeText');
|
|
}
|
|
|
|
if (this.textItem.entity.disableEdit) {
|
|
throw new Error('文本项已禁用编辑');
|
|
}
|
|
|
|
const response = await updateText({
|
|
textId: this.textItem.entity.id,
|
|
content: newContent
|
|
});
|
|
|
|
if (response.successful) {
|
|
this.textItem.setEntity(response.data);
|
|
return this.textItem;
|
|
} else {
|
|
throw new Error(`修改文案失败: ${response.message}`);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取优化后的文案内容
|
|
* @param optimizationOptions 优化选项
|
|
* @returns 优化后的内容
|
|
*/
|
|
async getOptimizedContent(
|
|
): Promise<string> {
|
|
if (!this.textItem) {
|
|
throw new Error('没有内容可优化');
|
|
}
|
|
return this.textItem.entity.content;
|
|
}
|
|
|
|
}
|
|
|
|
|