Skip to content

Conversation

InterN0te
Copy link
Contributor

Summary

This introduces a reusable system for serving images publicly without authentication, useful for external notification services like Gotify, Discord, or Telegram.

Features

  • ✅ Token-based public image access via /api/v1/publicimage endpoint
  • ✅ No authentication required for accessing images with valid tokens
  • ✅ Configurable expiration time (default: 24 hours, max: 31 days)
  • ✅ Persistent storage in /config/public_images/ (survives restarts)
  • ✅ Automatic cleanup of expired images (periodic + on startup)
  • ✅ Validates file existence even if token not in memory (handles restarts)

Configuration Options

```yaml
webserver:
public_base_url: "https://viseron.example.com"
public_url_expiry_hours: 48 # default: 24, max: 744 (31 days)
```

Technical Details

  • Images stored with UUID token as filename
  • Tokens stored in memory with expiration timestamp
  • After restart, API falls back to disk lookup if token not in memory
  • Hourly cleanup task removes expired tokens and files
  • Startup cleanup removes orphaned files older than max expiry
  • Supports JPG and PNG formats

Use Cases

This system can be used by any notification component that needs to share images externally:

  • Gotify notifications
  • Discord webhooks
  • Telegram bots
  • Email notifications
  • Custom integrations

Testing

After merge, other components can use this system by:

  1. Saving image to `/config/public_images/{token}.jpg`
  2. Creating a `PublicImageToken` with expiration
  3. Storing it in `vis.data[PUBLIC_IMAGE_TOKENS]`
  4. Generating URL: `{public_base_url}/api/v1/publicimage?token={token}`

Breaking Changes

None - this is a new feature with no impact on existing functionality.

This introduces a reusable system for serving images publicly without authentication, useful for external notification services like Gotify, Discord, or Telegram.

Features:
- Token-based public image access via /api/v1/publicimage endpoint
- No authentication required for accessing images with valid tokens
- Configurable expiration time (default: 24 hours, max: 31 days)
- Persistent storage in /config/public_images/ (survives restarts)
- Automatic cleanup of expired images (periodic + on startup)
- Validates file existence even if token not in memory (handles restarts)

Configuration options:
- public_base_url: External URL for Viseron (e.g., https://viseron.example.com)
- public_url_expiry_hours: How long public URLs remain valid (default: 24)

Technical details:
- Images stored with UUID token as filename
- Tokens stored in memory with expiration timestamp
- After restart, API falls back to disk lookup if token not in memory
- Hourly cleanup task removes expired tokens and files
- Startup cleanup removes orphaned files older than max expiry
- Supports JPG and PNG formats

Example usage:
```yaml
webserver:
  public_base_url: "https://viseron.example.com"
  public_url_expiry_hours: 48
```
Copy link

netlify bot commented Oct 13, 2025

Deploy Preview for viseron canceled.

Name Link
🔨 Latest commit 6adeb82
🔍 Latest deploy log https://app.netlify.com/projects/viseron/deploys/68ed4fce072f5a000892fd12

- Remove unused datetime import in publicimage.py
- Fix type annotation for _cleanup_task (asyncio.Task | None)
- Simplify cleanup task cancellation to avoid unreachable code
- Break long log messages to stay within 88 character limit
- Use %s formatting instead of f-strings for long messages
- Shorten comments while preserving meaning
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant