127 lines
1.8 KiB
Markdown
127 lines
1.8 KiB
Markdown
# backend
|
|
|
|
## Install
|
|
|
|
```bash
|
|
bun install
|
|
```
|
|
|
|
## Environment
|
|
|
|
Create a `.env` file:
|
|
|
|
```bash
|
|
cp .env.example .env
|
|
```
|
|
|
|
Set:
|
|
|
|
```bash
|
|
DATABASE_URL=postgres://username:password@localhost:5432/database_name
|
|
JWT_SECRET=replace_with_a_long_random_secret
|
|
JWT_EXPIRES_IN=7d
|
|
PORT=3000
|
|
MINIO_ENDPOINT=localhost
|
|
MINIO_PORT=9000
|
|
MINIO_USE_SSL=false
|
|
MINIO_ACCESS_KEY=minioadmin
|
|
MINIO_SECRET_KEY=minioadmin
|
|
MINIO_BUCKET=videos
|
|
MINIO_REGION=us-east-1
|
|
MINIO_PRESIGNED_EXPIRY_SECONDS=600
|
|
```
|
|
|
|
## Run app
|
|
|
|
```bash
|
|
bun run dev
|
|
```
|
|
|
|
## Drizzle ORM
|
|
|
|
Generate migrations:
|
|
|
|
```bash
|
|
bun run db:generate
|
|
```
|
|
|
|
Apply migrations:
|
|
|
|
```bash
|
|
bun run db:migrate
|
|
```
|
|
|
|
Open Drizzle Studio:
|
|
|
|
```bash
|
|
bun run db:studio
|
|
```
|
|
|
|
## Auth API
|
|
|
|
Register:
|
|
|
|
```bash
|
|
POST /auth/register
|
|
{
|
|
"email": "user@example.com",
|
|
"password": "password123",
|
|
"name": "User Name"
|
|
}
|
|
```
|
|
|
|
Login:
|
|
|
|
```bash
|
|
POST /auth/login
|
|
{
|
|
"email": "user@example.com",
|
|
"password": "password123"
|
|
}
|
|
```
|
|
|
|
Get current user:
|
|
|
|
```bash
|
|
GET /auth/me
|
|
Authorization: Bearer <token>
|
|
```
|
|
|
|
## Video API (Dummy MinIO S3 Integration)
|
|
|
|
All routes require a JWT Bearer token.
|
|
|
|
Create a presigned upload URL:
|
|
|
|
```bash
|
|
POST /videos/upload-url
|
|
Authorization: Bearer <token>
|
|
{
|
|
"fileName": "sample.mp4",
|
|
"prefix": "raw"
|
|
}
|
|
```
|
|
|
|
Get a presigned download URL:
|
|
|
|
```bash
|
|
GET /videos/download-url?objectKey=raw/<user-id>/<timestamp>-sample.mp4
|
|
Authorization: Bearer <token>
|
|
```
|
|
|
|
List video objects:
|
|
|
|
```bash
|
|
GET /videos?prefix=raw&limit=20
|
|
Authorization: Bearer <token>
|
|
```
|
|
|
|
Delete a video object:
|
|
|
|
```bash
|
|
DELETE /videos?objectKey=raw/<user-id>/<timestamp>-sample.mp4
|
|
Authorization: Bearer <token>
|
|
```
|
|
|
|
**Self-hosted MinIO note** Make sure the backend can reach your MinIO endpoint (network, TLS, credentials) and mirror any bucket changes you make outside of the app in `MINIO_BUCKET`, otherwise uploads/downloads fail.
|