File size: 4,449 Bytes
f313fa0
 
 
 
 
ff50748
61fcdc2
5101a73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
---
title: DocVault App
emoji: πŸ“
colorFrom: blue
colorTo: purple
sdk: docker
pinned: false
---

# DocVault - Offline-First Document Storage System

Complete offline-first document storage system built with **Python Flask** and local filesystem storage. No cloud dependencies, fully self-contained, and ready for future Hugging Face integration.

## 🎯 Features

### Core Features
- βœ… **Create Files and Folders** - Including nested directory structures
- βœ… **Delete Items** - Individual files/folders or bulk deletion
- βœ… **Upload Files** - Support for 50+ file types
- βœ… **List Contents** - Browse file/folder hierarchy with metadata
- βœ… **Rename Items** - Rename files and folders
- βœ… **Security** - Path traversal prevention, input validation
- βœ… **Logging** - Comprehensive logging with rotation
- βœ… **File Metadata** - Size, creation time, modification time
- βœ… **Multi-User** - Support for multiple users via user IDs

### Storage
- Local filesystem storage in `data/{user_id}/` structure
- Automatic marker files (`.gitkeep`) for HF integration compatibility
- Prevents duplicate filenames with auto-numbering
- Maintains clean directory structure

## πŸ“ Project Structure

```
.
β”œβ”€β”€ server/
β”‚   β”œβ”€β”€ app.py              # Flask application
β”‚   β”œβ”€β”€ config.py           # Configuration settings
β”‚   β”œβ”€β”€ requirements.txt    # Python dependencies
β”‚   β”œβ”€β”€ routes/
β”‚   β”‚   └── api.py          # API endpoints
β”‚   β”œβ”€β”€ storage/
β”‚   β”‚   └── manager.py      # Storage operations
β”‚   └── utils/
β”‚       β”œβ”€β”€ logger.py       # Logging setup
β”‚       └── validators.py   # Path validation & security
β”œβ”€β”€ data/                   # Storage directory (auto-created)
β”œβ”€β”€ logs/                   # Log files (auto-created)
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_docvault.py   # Unit tests
β”‚   └── test_api.sh        # API test script
β”œβ”€β”€ index.html              # Frontend UI
β”œβ”€β”€ app.js                  # Frontend app logic
β”œβ”€β”€ styles.css              # Frontend styles
└── README.md               # This file
```

## πŸš€ Getting Started

### Prerequisites
- Python 3.8+
- pip or conda

### Installation

1. **Clone the repository**
   ```bash
   git clone <your-repo-url>
   cd DocVault
   ```

2. **Install dependencies**
   ```bash
   pip install -r server/requirements.txt
   ```

3. **Run the application**
   ```bash
   python server/app.py
   ```

4. **Access the app**
   - Open browser to `http://localhost:5000`

## πŸ“ API Endpoints

### File Operations
- `POST /api/create` - Create file or folder
- `DELETE /api/delete` - Delete file or folder
- `PUT /api/rename` - Rename item
- `POST /api/upload` - Upload file
- `GET /api/list/<path>` - List directory contents

### Request Examples

**Create File:**
```bash
curl -X POST http://localhost:5000/api/create \
  -H "Content-Type: application/json" \
  -d '{"user_id":"default_user","item_type":"file","name":"test.txt","path":"/"}'
```

**Upload File:**
```bash
curl -X POST http://localhost:5000/api/upload \
  -F "user_id=default_user" \
  -F "file=@localfile.txt" \
  -F "path=/"
```

**List Contents:**
```bash
curl http://localhost:5000/api/list/default_user/
```

## πŸ§ͺ Testing

Run the test suite:
```bash
python -m pytest tests/test_docvault.py -v
```

Or use the included API test script:
```bash
bash tests/test_api.sh
```

## πŸ”’ Security Features

- **Path Traversal Prevention** - Validates all paths to prevent directory escape attacks
- **Input Validation** - Sanitizes filenames and paths
- **User Isolation** - Each user has their own data directory
- **Error Handling** - Comprehensive error messages without exposing system details

## πŸ“Š Logging

- Logs stored in `logs/` directory
- Automatic log rotation (10 MB per file, 10 files kept)
- Levels: DEBUG, INFO, WARNING, ERROR, CRITICAL

## 🚒 Deployment

### Docker
```bash
docker build -t docvault .
docker run -p 5000:5000 docvault
```

### Hugging Face Spaces
This app is ready for deployment on Hugging Face Spaces as a static frontend application.

## πŸ“¦ Dependencies

- Flask 2.3.2
- Werkzeug 2.3.6
- Python 3.8+

See `server/requirements.txt` for full list.

## πŸ“„ License

MIT License

## 🀝 Contributing

Contributions welcome! Please feel free to submit a Pull Request.

## πŸ“§ Support

For issues or questions, please open an Issue on GitHub.