Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ jobs:
- uses: pnpm/action-setup@v4
name: Install pnpm
with:
version: 9
run_install: false

- name: Install Node.js
Expand Down
88 changes: 88 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Upload Server

A REST API for image uploads built with Fastify, TypeScript, PostgreSQL, and Cloudflare R2.

## Features

- Image upload to Cloudflare R2 (S3-compatible storage)
- Paginated upload listing with sorting
- CSV export of upload records
- OpenAPI docs via Swagger UI at `/docs`

## Tech Stack

- **Runtime:** Node.js with TypeScript
- **Framework:** Fastify
- **Database:** PostgreSQL + Drizzle ORM
- **Storage:** Cloudflare R2 (AWS S3 SDK)
- **Validation:** Zod
- **Testing:** Vitest

## Getting Started

### Prerequisites

- Node.js 22+
- pnpm
- PostgreSQL instance
- Cloudflare R2 bucket

### Setup

1. Install dependencies:
```bash
pnpm install
```

2. Create a `.env` file with the required variables:
```env
PORT=3333
NODE_ENV=development
DATABASE_URL=postgresql://user:password@localhost:5432/dbname

CLOUDFLARE_ACCOUNT_ID=
CLOUDFLARE_ACCESS_KEY_ID=
CLOUDFLARE_SECRET_ACCESS_KEY=
CLOUDFLARE_BUCKET=
CLOUDFLARE_PUBLIC_URL=
```

3. Run database migrations:
```bash
pnpm db:migrate
```

4. Start the development server:
```bash
pnpm dev
```

## API Routes

| Method | Path | Description |
|--------|------|-------------|
| `POST` | `/uploads` | Upload an image file |
| `GET` | `/uploads` | List uploads (paginated) |
| `GET` | `/uploads/export` | Export uploads as CSV |

Full interactive docs available at `http://localhost:3333/docs`.

## Testing

```bash
# Run tests once
pnpm test

# Watch mode
pnpm test:watch
```

Tests require a `.env.test` file with a separate test database URL.

## Database

```bash
pnpm db:generate # Generate migrations
pnpm db:migrate # Apply migrations
pnpm db:studio # Open Drizzle Studio
```