mirror of
https://github.com/azaion/loader.git
synced 2026-04-22 08:26:32 +00:00
Quality cleanup refactoring
Made-with: Cursor
This commit is contained in:
@@ -17,7 +17,6 @@ Central API client that orchestrates authentication, encrypted resource download
|
||||
| token | str | JWT bearer token |
|
||||
| cdn_manager | CDNManager | CDN upload/download client |
|
||||
| api_url | str | Base URL for the resource API |
|
||||
| folder | str | Declared in `.pxd` but never assigned — dead attribute |
|
||||
|
||||
#### Methods
|
||||
|
||||
@@ -28,17 +27,12 @@ Central API client that orchestrates authentication, encrypted resource download
|
||||
| `set_credentials` | cdef | `(self, Credentials credentials)` | Internal: set credentials, lazy-init CDN manager |
|
||||
| `login` | cdef | `(self)` | POST `/login`, store JWT token |
|
||||
| `set_token` | cdef | `(self, str token)` | Decode JWT claims → create `User` with role mapping |
|
||||
| `get_user` | cdef | `(self) -> User` | Lazy login + return user |
|
||||
| `request` | cdef | `(self, str method, str url, object payload, bint is_stream)` | Authenticated HTTP request with auto-retry on 401/403 |
|
||||
| `list_files` | cdef | `(self, str folder, str search_file)` | GET `/resources/list/{folder}` with search param |
|
||||
| `check_resource` | cdef | `(self)` | POST `/resources/check` with hardware fingerprint |
|
||||
| `load_bytes` | cdef | `(self, str filename, str folder) -> bytes` | Download + decrypt resource using per-user+hw key |
|
||||
| `upload_file` | cdef | `(self, str filename, bytes resource, str folder)` | POST multipart upload to `/resources/{folder}` |
|
||||
| `upload_file` | cdef | `(self, str filename, bytes resource, str folder)` | POST multipart upload to `/resources/{folder}`; raises on HTTP error |
|
||||
| `load_big_file_cdn` | cdef | `(self, str folder, str big_part) -> bytes` | Download large file part from CDN |
|
||||
| `load_big_small_resource` | cpdef | `(self, str resource_name, str folder) -> bytes` | Reassemble resource from small (API) + big (CDN/local) parts |
|
||||
| `upload_big_small_resource` | cpdef | `(self, bytes resource, str resource_name, str folder)` | Split-encrypt and upload small part to API, big part to CDN |
|
||||
| `upload_to_cdn` | cpdef | `(self, str bucket, str filename, bytes file_bytes)` | Direct CDN upload |
|
||||
| `download_from_cdn` | cpdef | `(self, str bucket, str filename) -> bytes` | Direct CDN download |
|
||||
| `upload_big_small_resource` | cpdef | `(self, bytes resource, str resource_name, str folder)` | Split-encrypt; CDN upload must succeed or raises; then small part via `upload_file` |
|
||||
|
||||
## Internal Logic
|
||||
|
||||
@@ -58,8 +52,8 @@ Central API client that orchestrates authentication, encrypted resource download
|
||||
### Big/Small Resource Split (upload)
|
||||
1. Encrypts entire resource with shared resource key
|
||||
2. Splits: small part = `min(SMALL_SIZE_KB * 1024, 30% of encrypted)`, big part = remainder
|
||||
3. Uploads big part to CDN + saves local copy
|
||||
4. Uploads small part to API via multipart POST
|
||||
3. Calls `cdn_manager.upload` for the big part; raises if upload fails
|
||||
4. Writes big part to local cache, then uploads small part to API via `upload_file` (non-2xx responses propagate)
|
||||
|
||||
### JWT Role Mapping
|
||||
Maps `role` claim string to `RoleEnum`: ApiAdmin, Admin, ResourceUploader, Validator, Operator, or NONE (default).
|
||||
@@ -89,7 +83,7 @@ The CDN config file is itself downloaded encrypted from the API on first credent
|
||||
|
||||
## External Integrations
|
||||
|
||||
- **Azaion Resource API**: `/login`, `/resources/get/{folder}`, `/resources/{folder}` (upload), `/resources/list/{folder}`, `/resources/check`
|
||||
- **Azaion Resource API**: `/login`, `/resources/get/{folder}`, `/resources/{folder}` (upload)
|
||||
- **S3 CDN**: via `CDNManager` for large file parts
|
||||
|
||||
## Security
|
||||
|
||||
Reference in New Issue
Block a user