Convert to go
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
# List App
|
||||
|
||||
A web application for managing and organizing lists of movies, series, and games. The app allows users to add, view, and delete media items, with support for sorting and filtering.
|
||||
A web application for managing and organizing lists of movies, series, and games. The app allows users to add and view media items, with support for sorting and filtering.
|
||||
|
||||
## Features
|
||||
|
||||
- **Media Management**: Add, view, and delete movies, series, and games
|
||||
- **Media Management**: Add and view movies, series, and games
|
||||
- **Sorting Options**: Sort by title, year, or date added
|
||||
- **Image Caching**: Automatically downloads and caches poster images
|
||||
- **Authentication**: Password-protected actions for adding/deleting media
|
||||
- **Authentication**: Password-protected for adding media
|
||||
- **Responsive Design**: Works on mobile and desktop devices
|
||||
- **No client-side JavaScript**: Pages are fully rendered server-side; the only script on the page is Bootstrap's own bundle (for the collapsible nav/dropdown), not anything authored by this app
|
||||
|
||||
## Technologies
|
||||
|
||||
- **Backend**: TypeScript, Express, Bun runtime
|
||||
- **Frontend**: TypeScript, Bootstrap 5
|
||||
- **Backend**: Go, standard library `net/http` and `html/template`, `modernc.org/sqlite` (pure Go, cgo-free)
|
||||
- **Database**: SQLite
|
||||
- **APIs**: OMDB API (movies/series), Twitch IGDB API (games)
|
||||
|
||||
@@ -21,43 +21,39 @@ A web application for managing and organizing lists of movies, series, and games
|
||||
|
||||
```
|
||||
list_app/
|
||||
├── backend/ # Backend server code
|
||||
│ ├── controllers/ # Business logic
|
||||
│ ├── models/ # Database models
|
||||
│ ├── routes/ # API routes
|
||||
│ ├── miscellaneous/ # Utilities and middleware
|
||||
│ └── app.ts # Main server entry
|
||||
├── controllers/ # Business logic (OMDB/IGDB lookups, poster downloads)
|
||||
├── models/ # Database models
|
||||
├── routes/ # Route registration
|
||||
├── web/ # Server-rendered page + HTML form handling
|
||||
│ ├── page.html # Go html/template for the page
|
||||
│ ├── page.go # Grouping/sorting logic, GET / and POST /add handlers
|
||||
│ └── templates.go # go:embed for page.html
|
||||
├── db/ # DB connection and schema
|
||||
├── main.go # Main server entry
|
||||
│
|
||||
├── frontend/ # Frontend code
|
||||
│ ├── list/ # Main list components
|
||||
│ ├── utils/ # Type definitions
|
||||
│ └── elementcreate.tsx # Custom element creation
|
||||
├── public/ # Static assets, embedded into the Go binary
|
||||
│ ├── embed.go # go:embed directive
|
||||
│ ├── logo.ico # Favicon
|
||||
│ └── no_poster.jpg # Fallback poster image
|
||||
│
|
||||
├── public/ # Static files
|
||||
│ ├── index.html # Main HTML file
|
||||
│ ├── logo.ico # Favicon
|
||||
│ └── no_poster.jpg # Fallback poster image
|
||||
│
|
||||
├── package.json # Project dependencies
|
||||
└── README.md # This file
|
||||
├── go.mod # Go module
|
||||
└── README.md # This file
|
||||
```
|
||||
|
||||
## Setup
|
||||
|
||||
1. Install Bun runtime: https://bun.sh/
|
||||
2. Install dependencies:
|
||||
```bash
|
||||
bun install
|
||||
```
|
||||
3. Set up your API keys in the database:
|
||||
1. Install Go: https://go.dev/
|
||||
2. Set up your API keys in the database:
|
||||
- OMDB API key for movies/series
|
||||
- Twitch client ID and secret for games
|
||||
|
||||
## API Endpoints
|
||||
## Routes
|
||||
|
||||
- `GET /api/media/:mediaType` - List all media of a type (movies, series, games)
|
||||
- `POST /api/media/:mediaType` - Add new media (requires password)
|
||||
- `DELETE /api/media/:mediaType` - Delete media (requires password)
|
||||
- `GET /` - Renders the media list page. Query params: `listType` (`movies`, `series`, `games`; defaults to `movies`) and `sortType` (`title`, `year`, `id`; defaults to `title`)
|
||||
- `POST /add` - Plain HTML form submission to add media (`pass`, `code`, plus hidden `listType`/`sortType` to redirect back to the right view). Always redirects back to `/` with `?error=...` set on failure
|
||||
- `GET /api/media/:mediaType` - JSON listing of all media of a type (movies, series, games); not used by the page itself, kept as a small read-only API
|
||||
|
||||
There is no delete endpoint or UI — removing media isn't supported; use `sqlite3 mydb.sqlite` directly if you need to remove an entry.
|
||||
|
||||
## Configuration
|
||||
|
||||
@@ -68,18 +64,18 @@ The application uses SQLite for data storage. The database file `mydb.sqlite` wi
|
||||
- `games` - Stores game information
|
||||
- `userData` - Stores configuration including API keys and password
|
||||
|
||||
The compiled binary is self-contained: `logo.ico` and `no_poster.jpg` are embedded into it via `public/embed.go`, and the page markup lives in a Go `html/template` embedded via `web/templates.go` — so only the binary (plus the SQLite file) needs to be deployed. Poster images are fetched from OMDB/IGDB at runtime and can't be embedded, so they're cached on disk under a `posters/` directory created next to wherever the binary runs, and served at `/poster/...`. Whether a poster has actually downloaded yet is checked server-side on each page render — if it's missing, the fallback image is used directly in the rendered `<img src>`, so no client-side JS is needed for that either.
|
||||
|
||||
## Usage
|
||||
|
||||
1. Navigate to `http://localhost:4080` in your browser
|
||||
2. Use the navigation buttons to switch between movies, series, and games
|
||||
2. Use the navigation links to switch between movies, series, and games
|
||||
3. Use the "Sort" dropdown to change sorting method
|
||||
4. Enter your password and media ID in the form to add new items
|
||||
5. Click "Edit" then use delete buttons to remove items
|
||||
4. Enter your password and media ID in the form and submit to add new items
|
||||
|
||||
## Building
|
||||
|
||||
To build the frontend:
|
||||
To build the binary at `output/app`:
|
||||
```bash
|
||||
./build.sh
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user