Refactor HTML and JavaScript structure; add health-check endpoint
- Removed inline CSS from index.html and linked to external stylesheet. - Moved JavaScript code to a separate app.js file for better organization. - Added a health-check endpoint to the Flask application for monitoring purposes. - Implemented a static file serving route to handle requests for static assets.
This commit is contained in:
1 parent
6a0929ac2e
commit
cca5dd00ae
6 files changed
+953
-1727
No files matched your search
@@ -14,9 +14,12 @@ A Flask web app for browsing and playing TeslaCam (Tesla Dashcam/Sentry) recordi
|
||||
## Project Structure
|
||||
|
||||
```txt
|
||||
tesla-cam-view-1/
|
||||
tesla-cam-view/
|
||||
├── videoplayer.py # Flask app: scanning, routing, video streaming
|
||||
├── requirements.txt # Python dependencies (Flask)
|
||||
├── requirements.txt # Python dependencies
|
||||
├── .env # Local configuration (git-ignored)
|
||||
├── .env.example # Configuration template (committed)
|
||||
├── .gitignore
|
||||
├── templates/
|
||||
│ ├── index.html # Main page: camera tabs, player, clip list
|
||||
│ └── camera_view.html # Single-camera view page
|
||||
@@ -26,7 +29,7 @@ tesla-cam-view-1/
|
||||
## Requirements
|
||||
|
||||
- Python 3.x
|
||||
- Flask, python-dotenv, gunicorn (see `requirements.txt`)
|
||||
- See `requirements.txt`: Flask, python-dotenv, gunicorn
|
||||
|
||||
## Setup
|
||||
|
||||
@@ -46,24 +49,31 @@ tesla-cam-view-1/
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
3. Configure the TeslaCam directory via environment variables. Copy the example
|
||||
file and edit it:
|
||||
3. Configure the app via environment variables. Copy the example file and edit it:
|
||||
|
||||
```bash
|
||||
cp .env.example .env
|
||||
```
|
||||
|
||||
```ini
|
||||
TESLACAM_DIRECTORY=/mnt/TeslaCam
|
||||
FLASK_RUN_HOST=0.0.0.0
|
||||
FLASK_RUN_PORT=5000
|
||||
FLASK_DEBUG=0
|
||||
```
|
||||
|
||||
`TESLACAM_DIRECTORY` should point to the root folder containing your
|
||||
`RecentClips`, `SavedClips`, and `SentryClips` subfolders. Variables set in
|
||||
the real environment take precedence over `.env`.
|
||||
|
||||
## Configuration
|
||||
|
||||
All settings are read from environment variables, with sensible defaults. You
|
||||
can set them in a `.env` file, export them in the shell, or pass them to the
|
||||
process manager.
|
||||
|
||||
| Variable | Default | Description |
|
||||
| -------------------- | --------------- | ----------------------------------------------- |
|
||||
| `TESLACAM_DIRECTORY` | `/mnt/TeslaCam` | Root directory of the TeslaCam USB drive |
|
||||
| `FLASK_RUN_HOST` | `0.0.0.0` | Bind address (local dev server only) |
|
||||
| `FLASK_RUN_PORT` | `5000` | Port (local dev server only) |
|
||||
| `FLASK_DEBUG` | `0` | Enable Flask debug mode (local dev server only) |
|
||||
| `SCAN_CACHE_TTL` | `3600` | Seconds to cache the directory scan. Hit |
|
||||
| | | `/refresh` to force a re-scan. |
|
||||
|
||||
## Usage
|
||||
|
||||
### Local development server
|
||||
@@ -80,15 +90,15 @@ For production, run the app behind a WSGI server such as **gunicorn**. The
|
||||
`app` object in `videoplayer.py` is the WSGI entry point:
|
||||
|
||||
```bash
|
||||
gunicorn -w 4 -b 0.0.0.0:5000 'videoplayer:app'
|
||||
# Two workers are sufficient for this app
|
||||
gunicorn -w 2 -b 0.0.0.0:5000 'videoplayer:app'
|
||||
```
|
||||
|
||||
`TESLACAM_DIRECTORY` is read from the environment (or `.env`), so make sure it
|
||||
is set for the gunicorn process, e.g.:
|
||||
Make sure `TESLACAM_DIRECTORY` is set for the gunicorn process, e.g.:
|
||||
|
||||
```bash
|
||||
export TESLACAM_DIRECTORY=/mnt/TeslaCam
|
||||
gunicorn -w 4 -b 0.0.0.0:5000 'videoplayer:app'
|
||||
gunicorn -w 2 -b 0.0.0.0:5000 'videoplayer:app'
|
||||
```
|
||||
|
||||
For a systemd service or other process manager, set the variable in the unit
|
||||
@@ -121,9 +131,13 @@ file / environment rather than relying on `.env`.
|
||||
## Notes
|
||||
|
||||
- The directory scan is cached in memory for `SCAN_CACHE_TTL` seconds
|
||||
(default 300) to avoid re-walking the tree on every request. Hit
|
||||
(default 3600) to avoid re-walking the tree on every request. Hit
|
||||
`/refresh` to force a re-scan after copying new clips onto the drive.
|
||||
- Under gunicorn with multiple workers, each worker keeps its own cache; a
|
||||
`/refresh` only refreshes the worker that handles the request.
|
||||
- Debug mode is off by default (`FLASK_DEBUG=0`) and is only used by the local
|
||||
dev server. It has no effect when running under a WSGI server like gunicorn.
|
||||
- The TeslaCam directory must be accessible from the machine running the app (e.g., a mounted USB drive or network share).
|
||||
- Filename parsing assumes the standard TeslaCam naming format; files not matching the regex are ignored.
|
||||
- The TeslaCam directory must be accessible from the machine running the app
|
||||
(e.g., a mounted USB drive or network share).
|
||||
- Filename parsing assumes the standard TeslaCam naming format; files not
|
||||
matching the regex are ignored.
|
||||
Reference in new issue
Block a user