Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
140 changes: 140 additions & 0 deletions DOCUMENTATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
# Bapao Communication System - Documentation Summary

## 📚 Complete Documentation Generated

I've created comprehensive documentation for all public APIs, functions, and components in the Bapao communication system. Here's what has been documented:

### 📁 Documentation Structure

```
docs/
├── index.md # Main documentation index and navigation
├── README.md # Project overview and quick start
├── app_protocol_api.md # Application protocol API documentation
├── transport_protocol_api.md # Transport protocol API documentation
├── api_reference.md # Complete API reference with signatures
├── configuration.md # Setup and configuration guide
├── examples.md # Code examples and usage patterns
└── main_application.md # Main application documentation
```

### 🔍 What's Documented

#### Public APIs and Components

1. **Application Protocol (`bapao_app_protocal`)**
- `AppListener<T>` struct and all methods
- Route registration and request handling
- Type parameters and constraints
- Complete usage examples

2. **Transport Protocol (`bapao_trans_protocal`)**
- `BtpListener` struct and all methods
- `TransUnit` request/response handling
- All data types and enums
- Gitee integration functions
- Utility functions

3. **Data Structures**
- `TransHead` - Request/response metadata
- `ReqContent` - Request structure
- `ResContentType` - Response types
- `TransUnitType` - Data transmission types
- `ContentGroupByState` - State grouping

4. **Gitee Integration**
- `get_content()` - Fetch requests from repository
- `put_content()` - Send responses to repository
- `create_file()` - Upload binary files
- `group_by_state()` - Process request states
- HTTP utilities and error handling

#### Inline Code Documentation

- Added comprehensive doc comments to all public structs and functions
- Included parameter descriptions and return types
- Added usage examples for each function
- Documented error conditions and behavior
- Added module-level documentation

#### Examples and Patterns

- **Basic Setup**: Minimal application examples
- **Screenshot Service**: Complete screenshot capture implementation
- **File Transfer**: Binary file handling patterns
- **JSON API**: RESTful-style API service examples
- **Error Handling**: Robust error handling patterns
- **Security**: Secure file access and validation
- **Performance**: Optimization techniques and best practices

#### Configuration and Setup

- Complete configuration file documentation
- Gitee repository setup instructions
- Security best practices
- Environment-specific configurations
- Troubleshooting guide

### 🚀 Key Features Documented

1. **Request/Response Cycle**: Complete flow from external client to internal processing
2. **File Transfer**: Binary file upload and download capabilities
3. **State Management**: Request state tracking (Pending/Done/Expired)
4. **Error Handling**: Comprehensive error handling and recovery
5. **Security**: Authentication, access control, and security considerations
6. **Performance**: Optimization techniques and resource management

### 💡 Usage Examples

The documentation includes working examples for:

- Basic application setup
- Multi-endpoint applications
- Cross-platform screenshot capture
- File transfer services
- JSON API services
- Error handling patterns
- Testing and debugging
- Production deployment

### 🔧 Development Support

- **API Reference**: Complete function signatures with parameters and return types
- **Type Documentation**: All structs, enums, and type aliases explained
- **Build Instructions**: Development and production build processes
- **Testing Examples**: Unit and integration test patterns
- **Deployment Guides**: Systemd, Docker, and cross-platform deployment

### 📖 Navigation

All documentation is cross-linked and includes:

- Table of contents in each document
- Quick navigation index
- Code examples with line numbers
- Cross-references between related concepts
- Troubleshooting guides with solutions

### ✅ Documentation Quality

Each documented item includes:

- **Purpose**: What the function/component does
- **Parameters**: Detailed parameter descriptions
- **Returns**: Return type and value descriptions
- **Examples**: Working code examples
- **Error Handling**: Possible errors and how to handle them
- **Behavior**: Side effects and important behavior notes
- **Performance**: Optimization tips where relevant

## 🎯 Next Steps

The documentation is now complete and ready for use. Developers can:

1. **Start with `docs/index.md`** for navigation and overview
2. **Follow `docs/configuration.md`** to set up the system
3. **Use `docs/examples.md`** for implementation guidance
4. **Reference `docs/api_reference.md`** for detailed API information
5. **Check inline documentation** in the source code for implementation details

All public APIs, functions, and components are now comprehensively documented with examples and usage instructions.
63 changes: 58 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,65 @@
# 基于 Gitee 的内外网通信系统

### config
A Gitee-based internal-external network communication system that enables secure communication between networks through Gitee repositories.

## 📚 Documentation

**Complete documentation is available in the `docs/` directory:**

- **[📋 Start Here - Documentation Index](./docs/index.md)** - Main navigation and overview
- **[🚀 Quick Start Guide](./docs/README.md)** - Project introduction and setup
- **[⚙️ Configuration Guide](./docs/configuration.md)** - Setup instructions
- **[📖 API Reference](./docs/api_reference.md)** - Complete API documentation
- **[💡 Examples & Patterns](./docs/examples.md)** - Code examples and usage
- **[🔌 Application Protocol](./docs/app_protocol_api.md)** - High-level API docs
- **[🚚 Transport Protocol](./docs/transport_protocol_api.md)** - Low-level transport docs

## Quick Setup

### 1. Configuration

Create `bapao.config.json`:

```json
{
"access_token": "", // gitee access token
"user_name": "xx", // gitee user name
"repo": "xxx", // gitee repo
"file_path": "io" // gitee repo file
"access_token": "your_gitee_access_token",
"user_name": "your_gitee_username",
"repo": "your_repository_name",
"file_path": "io"
}
```

### 2. Build and Run

```bash
cargo build --release
cargo run
```

### 3. Usage Example

```rust
use bapao_app_protocal::{AppListener, TransUnitType};

fn hello() -> TransUnitType {
TransUnitType::String("Hello from Bapao!".to_string())
}

#[tokio::main]
async fn main() {
let mut listener = AppListener::new();
listener.add("/hello", hello);
listener.listen().await;
}
```

## Features

- 🔐 **Secure Communication** through private Gitee repositories
- 📷 **Screenshot Capture** for remote monitoring
- 📁 **File Transfer** support for binary and text data
- 🔄 **Request/Response** structured communication pattern
- ⏰ **Automatic Cleanup** of expired requests (30min timeout)
- 🚀 **Async/Await** throughout for performance

**[📖 See full documentation for detailed guides and examples →](./docs/index.md)**
39 changes: 37 additions & 2 deletions app/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,50 @@
//! # Bapao Screenshot Service Application
//!
//! This application demonstrates the Bapao communication system by providing
//! a screenshot capture service accessible through Gitee repository communication.
//!
//! ## Functionality
//!
//! - Listens for screenshot requests on `/monitor/pic/shot`
//! - Captures screenshots and returns them as binary data
//! - Uses the Bapao application protocol for request handling
//!
//! ## Usage
//!
//! 1. Configure `bapao.config.json` with your Gitee repository details
//! 2. Run the application: `cargo run`
//! 3. Send requests by updating the configured Gitee repository file
//!
//! ## Request Format
//!
//! ```json
//! [{
//! "head": {
//! "id": "screenshot_001",
//! "content_type": null,
//! "state": "Pending",
//! "timestamp": 1704067200000
//! },
//! "body": "/monitor/pic/shot"
//! }]
//! ```

use bapao_app_protocal;
use shot_pic::shot_pic;

mod shot_pic;

// use std::process;

#[tokio::main]
async fn main() {
println!("Starting Bapao Screenshot Service...");

let mut btp_listener = bapao_app_protocal::AppListener::new();

// Register the screenshot endpoint
btp_listener.add("/monitor/pic/shot", shot_pic);

println!("Registered endpoint: /monitor/pic/shot");
println!("Listening for requests...");

btp_listener.listen().await;
}
43 changes: 41 additions & 2 deletions app/src/shot_pic.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
//! Screenshot capture module for the Bapao communication system.
//!
//! This module provides screenshot capture functionality that can be accessed
//! remotely through the Bapao communication protocol.

extern crate image_base64;

use std::fs;

use std::process;

use bapao_app_protocal::TransUnitType;

/// Captures a screenshot and returns it as binary data.
///
/// This function handles screenshot capture requests from external clients.
/// Currently configured to read a static image file, but includes commented
/// code for dynamic screenshot capture using system commands.
///
/// # Returns
///
/// `TransUnitType::File(Vec<u8>)` - Binary image data of the screenshot
///
/// # Examples
///
/// ```rust
/// use bapao_app_protocal::TransUnitType;
/// use shot_pic::shot_pic;
///
/// let screenshot = shot_pic();
/// match screenshot {
/// TransUnitType::File(data) => {
/// println!("Screenshot captured: {} bytes", data.len());
/// },
/// TransUnitType::String(error) => {
/// println!("Screenshot failed: {}", error);
/// }
/// }
/// ```
///
/// # Implementation Notes
///
/// The current implementation reads from a static file path. For production use,
/// uncomment and modify the dynamic capture code to use appropriate screenshot
/// tools for your platform:
///
/// - Linux: `scrot`, `gnome-screenshot`, `import` (ImageMagick)
/// - macOS: `screencapture`
/// - Windows: PowerShell with System.Drawing
pub fn shot_pic() -> TransUnitType {
// if let Ok(mut child) = process::Command::new("fswebcam")
// .args(["-r", "1440*720", "/home/pi/image.jpg"])
Expand Down
Loading
Loading