feat: persist upload creation metadata
Add the first upload API endpoint from PLAN.md. POST /api/uploads now validates the requested file name, generates a server-owned upload id, creates the staging and complete directory layout, and writes durable meta.json before returning chunk scheduling details to the browser. Keep filesystem layout knowledge in storage.rs so later chunk upload and completion work can reuse the same boundary. API handlers translate storage errors into JSON HTTP responses without leaking layout details into the router. Document the new modules and UPL_DATA_DIR configuration, and extend TESTS.md with the automated creation coverage. Test Plan: - just check Refs: PLAN.md milestone 2
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub const CHUNK_SIZE: u64 = 16 * 1024 * 1024;
|
||||
|
||||
#[derive(Debug, Deserialize)]
|
||||
pub struct CreateUploadRequest {
|
||||
pub name: String,
|
||||
pub size: u64,
|
||||
pub last_modified: i64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct CreateUploadResponse {
|
||||
pub upload_id: String,
|
||||
pub chunk_size: u64,
|
||||
pub total_chunks: u64,
|
||||
pub completed_chunks: Vec<u64>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct UploadMeta {
|
||||
pub id: String,
|
||||
pub original_name: String,
|
||||
pub safe_name: String,
|
||||
pub size: u64,
|
||||
pub last_modified: i64,
|
||||
pub chunk_size: u64,
|
||||
pub total_chunks: u64,
|
||||
pub created_at: String,
|
||||
}
|
||||
|
||||
impl UploadMeta {
|
||||
#[must_use]
|
||||
pub fn create_response(&self) -> CreateUploadResponse {
|
||||
CreateUploadResponse {
|
||||
upload_id: self.id.clone(),
|
||||
chunk_size: self.chunk_size,
|
||||
total_chunks: self.total_chunks,
|
||||
completed_chunks: Vec::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user