chore(server): improve transcript stability (#13821)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Enhanced audio/video detection for MP4 files to better distinguish
audio-only vs. video.

* **Dependencies**
* Added MP4 parsing dependency and updated AI provider libraries
(Anthropic, Google, OpenAI, etc.).

* **Bug Fixes**
  * Tightened authentication state validation for magic-link/OTP flows.
* Stricter space-join validation to reject invalid client
types/versions.
  * Improved transcript entry deduplication and data handling.

* **API**
* Transcript submit payload now requires infos and removes deprecated
url/mimeType fields.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
DarkSky
2025-10-29 17:48:15 +08:00
committed by GitHub
parent d74087fdc5
commit b7ac7caab4
11 changed files with 176 additions and 126 deletions

View File

@@ -1,12 +1,41 @@
use mp4parse::{read_mp4, TrackType};
use napi_derive::napi;
#[napi]
pub fn get_mime(input: &[u8]) -> String {
if let Some(kind) = infer::get(&input[..4096.min(input.len())]) {
let mimetype = if let Some(kind) = infer::get(&input[..4096.min(input.len())]) {
kind.mime_type().to_string()
} else {
file_format::FileFormat::from_bytes(input)
.media_type()
.to_string()
};
if mimetype == "video/mp4" {
detect_mp4_flavor(input)
} else {
mimetype
}
}
fn detect_mp4_flavor(input: &[u8]) -> String {
let mut cursor = std::io::Cursor::new(input);
match read_mp4(&mut cursor) {
Ok(ctx) => {
let mut has_video = false;
let mut has_audio = false;
for track in ctx.tracks.iter() {
match track.track_type {
TrackType::Video | TrackType::AuxiliaryVideo | TrackType::Picture => has_video = true,
TrackType::Audio => has_audio = true,
_ => {}
}
}
if !has_video && has_audio {
"audio/m4a".to_string()
} else {
"video/mp4".to_string()
}
}
Err(_) => "video/mp4".to_string(),
}
}