Spaces:
Running
Running
Commit ·
04d405f
0
Parent(s):
first commit
Browse files123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191# Archive Extractor
A production-ready web application for uploading, extracting, and managing compressed file archives (ZIP and RAR). Features a modern dark-themed UI with drag-and-drop upload, tree view file explorer, and secure file handling.

## Features
- 📦 **Multi-format Support**: Extract ZIP and RAR archives- 🔄 **Nested Archive Handling**: Automatically extracts archives within archives- 🌲 **Interactive File Tree**: Collapsible tree view with file type icons- ⬇️ **Flexible Downloads**: Download individual files or entire folders as ZIP- 🎨 **Modern UI**: Dark theme with glassmorphism effects and animations- 📱 **Responsive Design**: Works on desktop and mobile devices- 🔒 **Security First**: Path traversal prevention, magic bytes validation, rate limiting
## Prerequisites
- Node.js v18 or higher- npm or yarn
## Installation
1. **Clone or download the project**
2. **Install dependencies** ```bash npm install ```
3. **Configure environment** (optional) ```bash cp .env.example .env # Edit .env to customize settings ```
4. **Start the server** ```bash npm start ```
5. **Open in browser** ``` http://localhost:3000 ```
## Development
Run with auto-reload on file changes:```bashnpm run dev```
## Configuration
All settings are configurable via environment variables:
| Variable | Default | Description ||----------|---------|-------------|| `PORT` | 3000 | Server port || `MAX_FILE_SIZE` | 104857600 | Max upload size in bytes (100MB) || `MAX_EXTRACTED_FILE_SIZE` | 52428800 | Max extracted file size (50MB) || `SESSION_TIMEOUT` | 3600000 | Auto-cleanup timeout in ms (1 hour) || `RATE_LIMIT_WINDOW` | 3600000 | Rate limit window in ms (1 hour) || `RATE_LIMIT_MAX` | 10 | Max uploads per window per IP |
## API Endpoints
### Upload Archive```httpPOST /api/uploadContent-Type: multipart/form-data
file: <archive file>```
**Response (200)**:```json{ "success": true, "sessionId": "uuid-v4", "filename": "archive.zip", "stats": { "totalFiles": 42, "totalSize": 1048576 }}```
### Get File Tree```httpGET /api/files/:sessionId```
**Response (200)**:```json{ "success": true, "sessionId": "uuid-v4", "tree": { "name": "root", "type": "folder", "path": "/", "children": [...] }}```
### Download File```httpGET /api/download/:sessionId/file?path=/path/to/file.txt```
### Download Folder as ZIP```httpGET /api/download/:sessionId/folder?path=/path/to/folder```
### Delete Session```httpDELETE /api/session/:sessionId```
## Error Responses
All errors return a consistent format:```json{ "error": true, "message": "Human-readable description", "code": "ERROR_CODE"}```
| Code | HTTP Status | Description ||------|-------------|-------------|| `INVALID_FILE_TYPE` | 400 | Unsupported file extension || `INVALID_MAGIC_BYTES` | 400 | File content doesn't match extension || `FILE_TOO_LARGE` | 400 | File exceeds size limit || `INVALID_PATH` | 400 | Path contains traversal or is absolute || `SESSION_NOT_FOUND` | 404 | Session expired or doesn't exist || `FILE_NOT_FOUND` | 404 | Requested file doesn't exist || `PASSWORD_PROTECTED` | 422 | Archive requires a password || `CORRUPTED_ARCHIVE` | 422 | Archive is damaged || `RATE_LIMIT_EXCEEDED` | 429 | Too many requests || `INTERNAL_ERROR` | 500 | Server error |
## Security Features
- **Magic Bytes Validation**: Verifies file content matches extension- **Path Traversal Prevention**: Blocks `..` and absolute paths- **Filename Sanitization**: Removes special characters- **Rate Limiting**: 10 uploads per IP per hour- **Helmet Integration**: HTTP security headers- **Zip Bomb Protection**: 50MB limit per extracted file- **Isolated Sessions**: Each upload gets a unique UUID directory- **Automatic Cleanup**: Sessions expire after 1 hour
## Project Structure
```/project-root├── server/│ ├── index.js # Express app entry point│ ├── routes/│ │ └── api.js # API route definitions│ ├── controllers/│ │ └── archiveController.js # Request handlers│ ├── services/│ │ └── extractionService.js # ZIP/RAR extraction logic│ ├── middleware/│ │ └── security.js # Validation & security│ └── utils/│ └── fileTree.js # Tree generation utility├── public/│ ├── index.html # Main HTML page│ ├── styles.css # CSS styling│ └── app.js # Frontend JavaScript├── uploads/ # Temporary upload storage├── extracted/ # Session extraction folders├── package.json├── .env.example└── README.md```
## License
MIT License - Feel free to use in your projects!# extract-serverREADME.mdAdded+191