mirror of
https://github.com/azaion/detections.git
synced 2026-04-22 22:16:31 +00:00
9411103041
Made-with: Cursor
2.7 KiB
2.7 KiB
Media Table Integration
Task: AZ-175_media_table_integration Name: Integrate Media table: create record on upload, store file, track status Description: When a file is uploaded to the detections API, create a Media record in the DB, store the file at the proper path, and update MediaStatus throughout processing. Complexity: 2 points Dependencies: Annotations service needs Media CRUD endpoints Component: Media Management Jira: AZ-175 Parent: AZ-172
Problem
Currently, uploaded files are written to temp files, processed, and deleted. No Media record is created in the database. File persistence and status tracking are missing.
Current State
/detect: writes upload totempfile.NamedTemporaryFile, processes, deletes viaos.unlink/detect/{media_id}: accepts a media_id parameter but doesn't create or manage Media records- No XxHash64 ID generation in the detections module
- No file storage to persistent paths
Target State
On Upload
- Receive file bytes from HTTP upload
- Compute XxHash64 of file content using the sampling algorithm
- Determine MediaType from file extension (Video or Image)
- Store file at proper path (from DirectorySettings: VideosDir or ImagesDir)
- Create Media record via annotations service:
POST /api/media- Id: XxHash64 hex string
- Name: original filename
- Path: storage path
- MediaType: Video|Image
- MediaStatus: New (1)
- UserId: from JWT
During Processing
- Update MediaStatus to AIProcessing (2) via
PUT /api/media/{id}/status - Run detection (stream-based per AZ-173)
- Update MediaStatus to AIProcessed (3) on success, or Error (6) on failure
XxHash64 Sampling Algorithm
For files >= 3072 bytes:
Input = file_size_as_8_bytes + first_1024_bytes + middle_1024_bytes + last_1024_bytes
Output = XxHash64(input) as hex string
For files < 3072 bytes:
Input = file_size_as_8_bytes + entire_file_content
Output = XxHash64(input) as hex string
Virtual hashes (in-memory only) prefixed with "V".
Acceptance Criteria
- XxHash64 ID computed correctly using the sampling algorithm
- Media record created in DB on upload with correct fields
- File stored at proper persistent path (not temp)
- MediaStatus transitions: New → AIProcessing → AIProcessed (or Error)
- UserId correctly extracted from JWT and associated with Media record
File Changes
| File | Action | Description |
|---|---|---|
src/main.py |
Modified | Upload handling, Media API calls, status updates |
src/media_hash.py |
New | XxHash64 sampling hash utility |
requirements.txt |
Modified | Add xxhash library if not present |