feat: store raw upload chunks
Add the chunk upload and progress APIs from PLAN.md. PUT
/api/uploads/{id}/chunks/{index} now accepts raw octet-stream bodies, validates
unknown upload ids, out-of-range chunk indexes, and exact chunk lengths, then
writes through a temporary .part.tmp path before renaming the completed chunk
into place. Re-uploading an already-complete chunk is idempotent when the
existing file length matches the expected length.
GET /api/uploads/{id} now reports server-authoritative progress by scanning the
chunk directory and only counting chunk files whose lengths match metadata. The
router also raises Axum's request body limit to 64 MiB so the planned 16 MiB
chunks can reach the handler, matching the nginx deployment guidance.
Document the chunk storage responsibility and extend the reusable test checklist
with the new progress and validation coverage.
Test Plan:
- just check
Refs: PLAN.md milestones 3 and 4
This commit is contained in:
@@ -17,6 +17,16 @@ pub struct CreateUploadResponse {
|
||||
pub completed_chunks: Vec<u64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct UploadProgressResponse {
|
||||
pub upload_id: String,
|
||||
pub name: String,
|
||||
pub size: u64,
|
||||
pub chunk_size: u64,
|
||||
pub total_chunks: u64,
|
||||
pub completed_chunks: Vec<u64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct UploadMeta {
|
||||
pub id: String,
|
||||
@@ -39,4 +49,16 @@ impl UploadMeta {
|
||||
completed_chunks: Vec::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn progress_response(&self, completed_chunks: Vec<u64>) -> UploadProgressResponse {
|
||||
UploadProgressResponse {
|
||||
upload_id: self.id.clone(),
|
||||
name: self.original_name.clone(),
|
||||
size: self.size,
|
||||
chunk_size: self.chunk_size,
|
||||
total_chunks: self.total_chunks,
|
||||
completed_chunks,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user