archiven-api

module
v0.0.0-...-c580266 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 31, 2025 License: MIT

README ΒΆ

# πŸ“ Archiven API

A modern digital archive management API with powerful file handling capabilities and flexible deletion strategies.

## ✨ Key Features

### πŸ“‹ File Management
- Upload PDF files (up to 3MB)
- Download files securely
- List archives with pagination
- Fetch archives by multiple IDs

### πŸ—‘οΈ Deletion System
- Soft Delete - Hide files without removing them
- Hard Delete - Permanent removal
- Restore - Recover soft-deleted files
- Auto-cleanup of expired files

### πŸ›‘οΈ Security & Performance
- File validation (type, size, signature)
- Protected download for deleted files
- Comprehensive audit logging
- Memory-efficient processing
- Background cleanup tasks

## πŸš€ Quick Start

### Prerequisites
- Go 1.21+
- MongoDB 5.0+

### Installation

1. Clone the repository
```bash
git clone https://github.com/username/archiven-api.git
cd archiven-api
```

2. Install dependencies
```bash
go mod download
```

3. Configure environment
```bash
cp .env.example .env
```

## πŸ”Œ API Endpoints

### Upload File
```http
POST /archives
Content-Type: multipart/form-data
```
Response:
```json
{
    "success": true,
    "file_id": "665f3b8c6c8d8a1e9b3e1b1a",
    "message": "File uploaded successfully"
}
```

### List Archives
```http
GET /archives?page=1&limit=10&include_deleted=false
```

### Get Archives by IDs
```http
GET /archives/list?ids=id1,id2,id3
```

### Download File
```http
GET /download/:id
```

### Delete Archive
```http
DELETE /archives/:id              # Soft delete
DELETE /archives/:id/permanent    # Hard delete
```

### Restore Archive
```http
POST /archives/:id/restore
```

## βš™οΈ Environment Variables

| Variable | Description | Default |
|----------|-------------|---------|
| SERVER_PORT | Application port | 8080 |
| MONGODB_URI | MongoDB connection string | mongodb://localhost:27017 |
| DB_NAME | Database name | archive_db |
| HOST | Server host | localhost |
| ALLOWED_TYPES | Allowed file types | application/pdf |
| MAX_UPLOAD_SIZE | Max upload size in bytes | 3145728 (3MB) |
| LOG_DIR | Log directory | logs |
| LOG_FILE_FORMAT | Log filename format | 2006-01-02.log |
| LOG_RETENTION_DAYS | Days to keep logs | 7 |
| LOG_LEVEL | Logging level | info |

## πŸ“ Usage Examples

### Upload a PDF file
```bash
curl -X POST -F "file=@document.pdf" http://localhost:8080/archives
```

### Download a file
```bash
curl -OJ http://localhost:8080/download/665f3b8c6c8d8a1e9b3e1b1a
```

### Delete a file
```bash
curl -X DELETE http://localhost:8080/archives/665f3b8c6c8d8a1e9b3e1b1a
```

### Restore a file
```bash
curl -X POST http://localhost:8080/archives/665f3b8c6c8d8a1e9b3e1b1a/restore
```

## πŸ“„ License
MIT License



Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL