Skip to content

Commit c4b9e47

Browse files
committed
docs: update README with enhanced features, authentication details, and improved structure; add database configuration and web dashboard routes
1 parent 764cd32 commit c4b9e47

File tree

1 file changed

+123
-35
lines changed

1 file changed

+123
-35
lines changed

README.md

Lines changed: 123 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
A high-performance CDN API service for image optimization, file management, and asset delivery built with Express.js and TypeScript.
1111

12-
[Features](#features)[Installation](#installation)[API Documentation](#api-documentation)[Contributing](#contributing)
12+
[Features](#features)[Installation](#installation)[API Documentation](#api-documentation)[Development](#development)
1313

1414
</div>
1515

@@ -43,9 +43,11 @@ CDN API is a production-ready content delivery network service that provides int
4343
- **Database**: Drizzle ORM with SQLite (Better-SQLite3)
4444
- **Authentication**: JWT-based with bcrypt password hashing
4545
- **Image Processing**: Sharp (high-performance image optimization)
46+
- **Document Preview**: Puppeteer for PDF generation and document previews
47+
- **TIFF Support**: TIFF.js for TIFF image handling
4648
- **File Handling**: Multer, fs-extra
4749
- **Security**: Express Rate Limiting, CORS, Session Management
48-
- **Frontend**: EJS templating with Tailwind CSS
50+
- **Frontend**: EJS templating with Tailwind CSS 4.x
4951
- **Development**: TypeScript, ts-node with hot reload
5052

5153
---
@@ -100,10 +102,17 @@ CDN API is a production-ready content delivery network service that provides int
100102
- **Performance Metrics**: Response time and throughput monitoring
101103

102104
### 🎨 Web Dashboard
103-
- **File Browser**: Visual interface for browsing and managing files
104-
- **Quick Access**: Starred files and recent items
105+
- **Authentication**: Login page with JWT-based authentication
106+
- **Dashboard**: Overview of storage usage and recent activity
107+
- **File Browser**: Visual interface for browsing and managing files with breadcrumb navigation
108+
- **My Files**: Organize and manage files in folders
109+
- **Quick Access**: Starred files and recent items for fast retrieval
110+
- **Upload Interface**: User-friendly file upload with progress tracking
111+
- **Upload History**: Track all upload activities with user information
112+
- **Shared Files**: Manage and view shared resources
113+
- **User Management**: Admin interface for managing user accounts
105114
- **Search**: Powerful filename search capabilities
106-
- **Responsive Design**: Mobile-friendly interface
115+
- **Responsive Design**: Mobile-friendly interface with modern UI
107116

108117
---
109118

@@ -131,8 +140,8 @@ Before installing, ensure you have the following:
131140

132141
```bash
133142
# Clone the repository
134-
git clone https://github.com/pphatdev/cdn.api.pphat.stackdev.cloud.git
135-
cd cdn.api.pphat.stackdev.cloud
143+
git clone <repository-url>
144+
cd assets.stackdev.cloud
136145

137146
# Install dependencies
138147
npm install
@@ -156,8 +165,8 @@ npm run dev
156165
#### 1. Clone and Install
157166

158167
```bash
159-
git clone https://github.com/pphatdev/cdn.api.pphat.stackdev.cloud.git
160-
cd cdn.api.pphat.stackdev.cloud
168+
git clone <repository-url>
169+
cd assets.stackdev.cloud
161170
npm install
162171
```
163172

@@ -230,6 +239,20 @@ The server will be available at `http://localhost:3000` (or your configured port
230239
"patterns": [ // Regex patterns for origins
231240
"^https?://.*\\.stackdev\\.cloud$"
232241
]
242+
},
243+
"database": {
244+
"dbPath": "src/data/app.db", // SQLite database path
245+
"autoRunMigrations": true, // Run migrations on startup
246+
"autoRunSeeds": false // Run seeds on startup
247+
},
248+
"auth": {
249+
"jwtSecret": "your-super-secret-jwt-key-min-32-characters-long",
250+
"jwtExpiresIn": "1h", // Access token expiration
251+
"refreshTokenExpiresIn": "7d", // Refresh token expiration
252+
"bcryptRounds": 12, // Password hashing rounds
253+
"maxLoginAttempts": 5, // Failed login limit
254+
"lockoutDuration": 15, // Account lockout minutes
255+
"maxSessionsPerUser": 5 // Max concurrent sessions
233256
}
234257
}
235258
```
@@ -244,16 +267,29 @@ The server will be available at `http://localhost:3000` (or your configured port
244267
| `directories` | array | Storage directory patterns | `["./storage/**/**"]` |
245268
| `allow.origins` | array | Exact CORS origins | `[]` |
246269
| `allow.patterns` | array | Regex patterns for CORS | `[]` |
270+
| `database.dbPath` | string | SQLite database file path | "src/data/app.db" |
271+
| `database.autoRunMigrations` | boolean | Auto-run migrations on startup | true |
272+
| `database.autoRunSeeds` | boolean | Auto-run seeds on startup | false |
273+
| `auth.jwtSecret` | string | JWT secret key (min 32 chars) | Required |
274+
| `auth.jwtExpiresIn` | string | Access token TTL | "1h" |
275+
| `auth.refreshTokenExpiresIn` | string | Refresh token TTL | "7d" |
276+
| `auth.bcryptRounds` | number | Password hashing strength | 12 |
277+
| `auth.maxLoginAttempts` | number | Failed login threshold | 5 |
278+
| `auth.lockoutDuration` | number | Lockout duration (minutes) | 15 |
279+
| `auth.maxSessionsPerUser` | number | Max concurrent sessions per user | 5 |
247280

248281
### Storage Structure
249282

250283
The default storage structure:
251284

252285
```
253286
storage/
254-
├── images/ # Optimized images
255-
├── test/ # Test files
256-
└── example/ # Example assets
287+
├── background/ # Background images
288+
│ └── cover/ # Cover images
289+
├── documents/ # Document uploads
290+
├── example/ # Example assets
291+
│ └── site.webmanifest
292+
└── files/ # General file uploads
257293
```
258294

259295
You can customize storage locations in `env.json`.
@@ -335,7 +371,7 @@ To backup the database:
335371

336372
```bash
337373
# Windows
338-
copy src\server\data\app.db src\server\data\app.db.backup
374+
copy src\data\app.db src\data\app.db.backup
339375

340376
# Linux/macOS
341377
cp src/data/app.db src/data/app.db.backup
@@ -367,7 +403,8 @@ npm run css
367403

368404
- **Web Dashboard**: http://localhost:3000/
369405
- **API Base URL**: http://localhost:3000/api/
370-
- **Health Check**: http://localhost:3000/api/ping
406+
- **API Welcome**: http://localhost:3000/api/
407+
- **API Version**: http://localhost:3000/api/version
371408
- **Database Studio**: Run `npm run db:studio` and visit http://localhost:4983/
372409

373410
### Default Admin Credentials
@@ -414,13 +451,41 @@ http://localhost:3000/api
414451

415452
### Authentication
416453

417-
Currently, the API does not require authentication. For production use, implement authentication middleware.
454+
The API supports JWT-based authentication. While many endpoints work without authentication, protected endpoints require a valid JWT token.
455+
456+
#### Getting a Token
457+
458+
```bash
459+
curl -X POST http://localhost:3000/api/auth/login \
460+
-H "Content-Type: application/json" \
461+
-d '{
462+
"username": "admin",
463+
"password": "admin123"
464+
}'
465+
```
466+
467+
#### Using the Token
468+
469+
Include the JWT token in the Authorization header:
470+
471+
```bash
472+
curl http://localhost:3000/api/auth/me \
473+
-H "Authorization: Bearer YOUR_JWT_TOKEN"
474+
```
475+
476+
#### Token Management
477+
478+
- **Access Token**: Valid for 1 hour (configurable)
479+
- **Refresh Token**: Valid for 7 days (configurable)
480+
- Use `/auth/logout` to invalidate current session
481+
- Use `/auth/logout-all` to invalidate all user sessions
418482

419483
### Endpoints Overview
420484

421485
| Category | Endpoint | Method | Description | Auth Required |
422486
|----------|----------|--------|-------------|---------------|
423-
| **Health** | `/ping` | GET | API health check | No |
487+
| **Health** | `/` | GET | API welcome message | No |
488+
| **Health** | `/version` | GET | Get API version info | No |
424489
| **Auth** | `/auth/login` | POST | User login (rate limited) | No |
425490
| **Auth** | `/auth/logout` | POST | Logout current session | Yes |
426491
| **Auth** | `/auth/logout-all` | POST | Logout all sessions | Yes |
@@ -444,12 +509,12 @@ Currently, the API does not require authentication. For production use, implemen
444509
### Detailed API Documentation
445510

446511
For comprehensive API documentation with examples, see:
447-
- [Authentication API](docs/how-to-use/authentication-api.md) - Complete auth guide with JWT
448512
- [Migration Guide](docs/how-to-use/MIGRATION_GUIDE.md) - Database migration system
449513
- [Image Upload Endpoint](docs/how-to-use/image-upload-endpoint.md)
450514
- [File Upload Endpoint](docs/how-to-use/file-upload-endpoint.md)
451515
- [Storage API Endpoint](docs/how-to-use/storage-api-endpoint.md)
452516
- [Get Image Endpoint](docs/how-to-use/get-image-endpoint.md)
517+
- [Get Content Structure](docs/how-to-use/get-content-stracture.md)
453518
- [Move File Endpoint](docs/how-to-use/move-file-endpoint.md)
454519
- [Search Filename](docs/how-to-use/search-filename.md)
455520
- [Rate Limiting](docs/how-to-use/rate-limiting.md)
@@ -461,6 +526,26 @@ Import the Postman collection for testing:
461526
docs/collections/collection.postman_collection.json
462527
```
463528

529+
### Web Dashboard Routes
530+
531+
The application includes a full-featured web interface accessible via browser:
532+
533+
| Route | Description | Auth Required |
534+
|-------|-------------|---------------|
535+
| `/` | Dashboard overview with storage stats | Yes |
536+
| `/login` | User authentication page | No |
537+
| `/files` | File browser and manager | Yes |
538+
| `/files/*` | Navigate through folder structure | Yes |
539+
| `/starred` | Quick access to starred files | Yes |
540+
| `/recent` | Recently accessed files | Yes |
541+
| `/detail` | Detailed file information | Yes |
542+
| `/share` | Shared files management | Yes |
543+
| `/upload` | File upload interface | Yes |
544+
| `/upload/history` | Upload activity history | Yes |
545+
| `/users` | User management (Admin only) | Yes |
546+
547+
**Note**: Web authentication is handled via JWT tokens stored in browser cookies. Users are automatically redirected to `/login` if not authenticated.
548+
464549
---
465550

466551
## 🛠️ Development
@@ -553,12 +638,26 @@ cdn.api.pphat.stackdev.cloud/
553638
│ │ ├── middlewares/ # Client middlewares
554639
│ │ │ └── auth.ts # Client auth middleware
555640
│ │ ├── routes/ # Client routes
641+
│ │ │ └── web.ts # Web routes
556642
│ │ ├── styles/ # CSS/Tailwind styles
557643
│ │ ├── utils/ # Client utilities
558644
│ │ └── views/ # EJS templates
559645
│ │ ├── components/ # Reusable components
560646
│ │ ├── layouts/ # Layout templates
561647
│ │ └── pages/ # Page templates
648+
│ ├── data/ # Data storage
649+
│ │ ├── app.db # SQLite database
650+
│ │ ├── database.json # Legacy JSON store
651+
│ │ ├── migrations/ # Database migrations
652+
│ │ │ ├── 0000_youthful_ozymandias.sql
653+
│ │ │ ├── 20260213_000000_create_initial_auth_tables_sqlite.ts
654+
│ │ │ ├── 20260214_000000_create_files_uploads_tables_sqlite.ts
655+
│ │ │ ├── meta/ # Drizzle metadata
656+
│ │ │ └── README.md
657+
│ │ ├── schema/ # Database schemas
658+
│ │ │ └── schema.ts # Drizzle ORM schema
659+
│ │ └── seeds/ # Database seeds
660+
│ │ └── 20260213_010000_demo_users_sqlite.ts
562661
│ └── server/ # Backend API
563662
│ ├── controllers/ # API controllers
564663
│ │ ├── auth.controller.ts # Authentication controller
@@ -570,20 +669,11 @@ cdn.api.pphat.stackdev.cloud/
570669
│ │ ├── storage.controller.ts
571670
│ │ ├── upload.controller.ts
572671
│ │ └── users.controller.ts # User management
573-
│ ├── data/ # Data storage
574-
│ │ ├── app.db # SQLite database
575-
│ │ └── database.json # Legacy JSON store
576672
│ ├── middlewares/ # Express middlewares
577673
│ │ ├── auth.ts # JWT auth middleware
578674
│ │ ├── cors.ts
579675
│ │ ├── rate-limit.ts
580676
│ │ └── security.ts # Security headers
581-
│ ├── migrations/ # Database migrations
582-
│ │ ├── 0000_youthful_ozymandias.sql
583-
│ │ ├── 20260213_000000_create_initial_auth_tables_sqlite.ts
584-
│ │ ├── 20260214_000000_create_files_uploads_tables_sqlite.ts
585-
│ │ ├── meta/ # Drizzle metadata
586-
│ │ └── README.md
587677
│ ├── routes/ # API routes
588678
│ │ ├── api.ts # Main API router
589679
│ │ ├── auth.ts # Auth routes
@@ -592,10 +682,6 @@ cdn.api.pphat.stackdev.cloud/
592682
│ │ ├── folder.ts
593683
│ │ ├── image.ts
594684
│ │ └── storage.ts
595-
│ ├── schema/ # Database schemas
596-
│ │ └── schema.ts # Drizzle ORM schema
597-
│ ├── seeds/ # Database seeds
598-
│ │ └── 20260213_010000_demo_users_sqlite.ts
599685
│ ├── types/ # TypeScript types
600686
│ │ └── user.ts # User & auth types
601687
│ └── utils/ # Server utilities
@@ -611,16 +697,18 @@ cdn.api.pphat.stackdev.cloud/
611697
│ ├── response.ts # Response helpers
612698
│ └── storage.ts # Storage statistics
613699
├── storage/ # File storage directory
614-
│ ├── images/ # Optimized images
615-
│ ├── test/ # Test files
616-
│ └── example/ # Example assets
700+
│ ├── background/ # Background images
701+
│ │ └── cover/ # Cover images
702+
│ ├── documents/ # Document files
703+
│ ├── example/ # Example assets
704+
│ └── files/ # General file uploads
617705
├── docs/ # Documentation
618706
│ ├── collections/ # Postman collections
707+
│ │ └── collection.postman_collection.json
619708
│ └── how-to-use/ # Endpoint documentation
620709
├── scripts/ # Build and utility scripts
621710
│ ├── migrate.ts # Migration CLI
622-
│ ├── register.mjs # TS-Node registration
623-
│ └── run-migrate.mjs # Migration runner
711+
│ └── register.mjs # TS-Node registration
624712
├── dist/ # Compiled output (gitignored)
625713
├── drizzle.config.ts # Drizzle ORM config
626714
├── env.json # Configuration (gitignored)

0 commit comments

Comments
 (0)