fix(nextcloud): detect MIME type via magic bytes instead of trusting client header

Nextcloud app uploads sent application/octet-stream as Content-Type,
causing images to not be recognized. Now both WebDAV PUT and chunked
upload paths call refine_content_type() which detects via magic bytes,
then extension, then falls back to the client header. Also fixes
update_file() which previously hardcoded application/octet-stream.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
zjean
2026-03-04 15:51:47 +01:00
parent 40b269c4eb
commit fdbb144cd8
6 changed files with 163 additions and 15 deletions
+6 -1
View File
@@ -63,7 +63,12 @@ pub trait FileUploadUseCase: Send + Sync + 'static {
) -> Result<FileDto, DomainError>;
/// Updates the content of an existing file (for WebDAV)
async fn update_file(&self, path: &str, content: &[u8]) -> Result<(), DomainError>;
async fn update_file(
&self,
path: &str,
content: &[u8],
content_type: &str,
) -> Result<(), DomainError>;
/// Streaming update — spools body to a temp file with incremental hash,
/// then atomically replaces the file content via dedup store.
@@ -222,7 +222,12 @@ impl FileUploadUseCase for FileUploadService {
///
/// Spools the in-memory `&[u8]` to a temp file with hash-on-write,
/// then delegates to the streaming update/create path.
async fn update_file(&self, path: &str, content: &[u8]) -> Result<(), DomainError> {
async fn update_file(
&self,
path: &str,
content: &[u8],
content_type: &str,
) -> Result<(), DomainError> {
// Spool to temp file + hash
let temp = tempfile::NamedTempFile::new()
.map_err(|e| DomainError::internal_error("FileUpload", format!("temp file: {e}")))?;
@@ -235,7 +240,7 @@ impl FileUploadUseCase for FileUploadService {
path,
temp.path(),
content.len() as u64,
"application/octet-stream",
content_type,
Some(hash),
)
.await