Spaces:
Running

docker / extractor /README.md
bacteriaqh's picture
Deploy 5313b66 từ GitHub Actions
e913295 verified
|
Raw History Blame
5.25 kB
metadata
title: File Share
emoji: 📤
colorFrom: indigo
colorTo: purple
sdk: docker
app_port: 7860
pinned: false
license: mit

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.

Node.js Express.js License

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

    npm install
    
  3. Configure environment (optional)

    cp .env.example .env
    # Edit .env to customize settings
    
  4. Start the server

    npm start
    
  5. Open in browser

    http://localhost:3000
    

Development

Run with auto-reload on file changes:

npm 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

POST /api/upload
Content-Type: multipart/form-data

file: <archive file>

Response (200):

{
  "success": true,
  "sessionId": "uuid-v4",
  "filename": "archive.zip",
  "stats": {
    "totalFiles": 42,
    "totalSize": 1048576
  }
}

Get File Tree

GET /api/files/:sessionId

Response (200):

{
  "success": true,
  "sessionId": "uuid-v4",
  "tree": {
    "name": "root",
    "type": "folder",
    "path": "/",
    "children": [...]
  }
}

Download File

GET /api/download/:sessionId/file?path=/path/to/file.txt

Download Folder as ZIP

GET /api/download/:sessionId/folder?path=/path/to/folder

Delete Session

DELETE /api/session/:sessionId

Error Responses

All errors return a consistent format:

{
  "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-server