This commit is contained in:
2026-03-13 15:47:04 +07:00
parent 5369df7148
commit f045c2faef

View File

@@ -572,92 +572,43 @@ function fileserver_download_handler(
### Sending Flow ### Sending Flow
``` ```mermaid
┌─────────────────────────────────────────────────────────────────┐ flowchart TD
│ 1. User calls smartsend(subject, data) A[User calls smartsend(subject, data)] --> B[Serialize payload according to payload_type]
└─────────────────────────────────────────────────────────────────┘ B --> C[Calculate serialized size]
C --> D{Size < Threshold?}
D -->|Yes| E[Direct Transport: Base64 encode]
┌─────────────────────────────────────────────────────────────────┐ D -->|No| F[Link Transport: Upload to file server]
│ 2. For each payload: │ E --> G[Build envelope with metadata]
- Serialize data according to payload_type │ F --> G
- Calculate serialized size │ G --> H[Convert to JSON string]
└─────────────────────────────────────────────────────────────────┘ H --> I[Publish to NATS subject]
I --> J[Return envelope and JSON string]
├─ Size < Threshold ────────────────►┐
│ │ style A fill:#f9f9f9,stroke:#333
▼ ▼ style D fill:#e0e7ff,stroke:#3b82f6
┌─────────────────────────────────────────────────────────────────┐ │ style I fill:#e0e7ff,stroke:#3b82f6
│ 3. Direct Transport: │ │
│ - Encode as Base64 │ │
│ - Include in payload.data │ │
└─────────────────────────────────────────────────────────────────┘ │
│ │
▼ │
┌─────────────────────────────────────────────────────────────────┐ │
│ 4. Build envelope with metadata │ │
│ - correlation_id, msg_id, timestamp │ │
│ - sender/receiver info │ │
│ - payloads array │ │
└─────────────────────────────────────────────────────────────────┘ │
│ │
▼ │
┌─────────────────────────────────────────────────────────────────┐ │
│ 5. Convert envelope to JSON string │ │
│ 6. Publish to NATS subject │ │
└─────────────────────────────────────────────────────────────────┘ │
┌─────────────────────────────────────────────────────────────────┐ │
│ 7. Return envelope and JSON string to caller │ │
└─────────────────────────────────────────────────────────────────┘ │
``` ```
### Receiving Flow ### Receiving Flow
``` ```mermaid
┌─────────────────────────────────────────────────────────────────┐ flowchart TD
│ 1. NATS message arrives A[NATS message arrives] --> B[Parse JSON envelope]
└─────────────────────────────────────────────────────────────────┘ B --> C[Process each payload]
C --> D{Check transport type}
D -->|direct| E[Extract Base64 data]
┌─────────────────────────────────────────────────────────────────┐ D -->|link| F[Extract URL from data]
│ 2. Parse JSON envelope │ E --> G[Decode Base64]
└─────────────────────────────────────────────────────────────────┘ F --> H[Fetch with exponential backoff]
G --> I[Deserialize based on payload_type]
H --> I
┌─────────────────────────────────────────────────────────────────┐ I --> J[Build payloads array]
│ 3. For each payload: │ J --> K[Return envelope with processed payloads]
- Check transport type │
└─────────────────────────────────────────────────────────────────┘ style A fill:#f9f9f9,stroke:#333
style D fill:#e0e7ff,stroke:#3b82f6
├─ transport == "direct" ──────────►┐ style K fill:#e0e7ff,stroke:#3b82f6
│ │
▼ ▼
┌─────────────────────────────────────────────────────────────────┐ │
│ 4. Direct Transport: │ │
│ - Extract Base64 data │ │
│ - Decode Base64 │ │
│ - Deserialize based on payload_type │ │
└─────────────────────────────────────────────────────────────────┘ │
│ │
▼ │
┌─────────────────────────────────────────────────────────────────┐ │
│ 5. Link Transport: │ │
│ - Extract URL from data │ │
│ - Fetch with exponential backoff │ │
│ - Deserialize based on payload_type │ │
└─────────────────────────────────────────────────────────────────┘ │
│ │
▼ │
┌─────────────────────────────────────────────────────────────────┐ │
│ 6. Replace payloads array with deserialized tuples │ │
│ - [(dataname, data, type), ...] │ │
└─────────────────────────────────────────────────────────────────┘ │
┌─────────────────────────────────────────────────────────────────┐
│ 7. Return envelope with processed payloads │
└─────────────────────────────────────────────────────────────────┘
``` ```
--- ---