fixed bugs

This commit is contained in:
2026-10-29 11:32:33 +08:00
parent 031f3c6f21
commit a87228cdc9
7 changed files with 229 additions and 114 deletions

View File

@@ -812,7 +812,10 @@ def create_app(
raise HTTPException(status_code=404, detail="Course is not available.") from None
except ValueError as exc:
raise HTTPException(status_code=400, detail=str(exc)) from exc
application.state.subtitle_translations.refresh(video_hash)
if payload.process_timings:
application.state.subtitle_translations.refresh(video_hash)
else:
application.state.subtitle_translations.invalidate(video_hash)
return result
@application.put(
@@ -833,7 +836,7 @@ def create_app(
)
if sentence is None:
raise HTTPException(status_code=404, detail="Sentence was not found.")
application.state.subtitle_translations.refresh(video_hash)
application.state.subtitle_translations.invalidate(video_hash)
return sentence
@application.put(
@@ -891,7 +894,7 @@ def create_app(
raise HTTPException(status_code=400, detail=str(exc)) from exc
if sentence is None:
raise HTTPException(status_code=404, detail="Sentence was not found.")
application.state.subtitle_translations.refresh(video_hash)
application.state.subtitle_translations.invalidate(video_hash)
return sentence
@application.put(
@@ -1261,6 +1264,7 @@ def _replace_admin_sentences(
end_ms=item.end_ms,
text=item.text.strip(),
language=item.language,
zh_text=item.zh_text,
reference_speech_duration_ms=item.reference_speech_duration_ms,
)
)
@@ -1279,7 +1283,32 @@ def _replace_admin_sentences(
group = payload.sentences[position:group_end]
source = old_sentences.get(source_key)
if source is None:
raise ValueError("The original sentence for a queued split no longer exists.")
if payload.process_timings:
# A split may already have been persisted with provisional
# boundaries. Reconstruct its audio range from the saved rows so
# timing refinement can be retried after a dialog is reopened.
missing = [
item
for item in group
if (item.start_ms, item.end_ms) not in old_sentences
]
if missing:
raise ValueError("The original sentence for a queued split no longer exists.")
source = SentenceBoundary(
index=0,
start_ms=source_key[0],
end_ms=source_key[1],
text="\n".join(item.text.strip() for item in group),
language=next(
(item.language for item in group if item.language is not None),
None,
),
reference_speech_duration_ms=sum(
item.reference_speech_duration_ms for item in group
),
)
else:
source = None
if len(group) == 1:
if "\n" in group[0].text or "\r" in group[0].text:
raise ValueError("Unsplit batch sentences cannot contain line breaks.")
@@ -1290,9 +1319,24 @@ def _replace_admin_sentences(
end_ms=group[0].end_ms,
text=group[0].text.strip(),
language=group[0].language,
zh_text=group[0].zh_text,
reference_speech_duration_ms=group[0].reference_speech_duration_ms,
)
)
elif not payload.process_timings:
for item in group:
rows.append(
SentenceBoundary(
index=index,
start_ms=item.start_ms,
end_ms=item.end_ms,
text=item.text.strip(),
language=item.language,
zh_text=item.zh_text,
reference_speech_duration_ms=item.reference_speech_duration_ms,
)
)
index += 1
else:
split_text = "\n".join(item.text.strip() for item in group if item.text.strip())
replacements = split_sentence_text(
@@ -1319,6 +1363,7 @@ def _replace_admin_sentences(
if item.language is not None
else source.language
),
zh_text=None,
reference_speech_duration_ms=replacement.reference_speech_duration_ms,
)
)