admin can split a sentence into 2 sentences

This commit is contained in:
2026-08-30 09:25:34 +08:00
parent abc052e42d
commit a99c0cfd17
8 changed files with 577 additions and 13 deletions

View File

@@ -186,7 +186,7 @@ async function openSentences(video) {
elements.sentenceMeta.textContent = `${sentences.length} 句 / ${detail.video.video_hash}`;
elements.sentenceRows.replaceChildren();
for (const sentence of sentences) {
elements.sentenceRows.append(sentenceRow(video.video_hash, sentence));
elements.sentenceRows.append(sentenceRow(video, sentence));
}
elements.dialog.showModal();
} catch (error) {
@@ -194,7 +194,7 @@ async function openSentences(video) {
}
}
function sentenceRow(videoHash, sentence) {
function sentenceRow(video, sentence) {
const row = document.createElement("tr");
const textArea = document.createElement("textarea");
textArea.value = sentence.text || "";
@@ -214,12 +214,23 @@ function sentenceRow(videoHash, sentence) {
const save = button("保存", async () => {
save.disabled = true;
try {
await api(`/api/v1/admin/videos/${videoHash}/sentences/${sentence.index}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ text: textArea.value, language: language.value || null }),
});
save.textContent = "已保存";
const body = JSON.stringify({ text: textArea.value, language: language.value || null });
if (/\r?\n/.test(textArea.value)) {
await api(`/api/v1/admin/videos/${video.video_hash}/sentences/${sentence.index}/split`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body,
});
save.textContent = "已拆分";
await openSentences(video);
} else {
await api(`/api/v1/admin/videos/${video.video_hash}/sentences/${sentence.index}`, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body,
});
save.textContent = "已保存";
}
} catch (error) {
save.textContent = error.message;
} finally {