clarion-app / download-manager-backend
Describe your package
Requires
- clarion-app/backend: dev-main
- clarion-app/eloquent-multichain-bridge: dev-main
This package is auto-updated.
Last update: 2025-06-22 16:48:52 UTC
README
A Laravel-based backend service for managing downloads in Clarion. This package provides comprehensive torrent management capabilities with support for multiple torrent client implementations.
Overview
The Download Manager Backend is a Clarion app component that enables users to:
- Manage torrent downloads across multiple servers
- Track download status and completion
- Support multiple torrent client types (currently Transmission)
Features
- Multi-Server Support: Manage torrents across multiple torrent servers and client types
- Torrent Lifecycle Management: Add, monitor, and remove torrents with automatic status tracking
- RESTful API: Complete CRUD operations for torrents and torrent servers
- Extensible Client Architecture: Plugin-based system for supporting different torrent clients
- User Association: Link torrents to specific users with authentication support
- Automatic Processing: Background commands for checking torrent status
Architecture
Models
Torrent
Represents individual torrent downloads with the following attributes:
local_node
: Node identifier for distributed trackingserver_id
: Reference to the torrent server handling the downloaduser_id
: Associated user (when authenticated)magnetURI
: Magnet link for the torrenthash_string
: Unique torrent hash identifiername
: Display name (auto-extracted from magnet URI)completed_at
: Timestamp when download completed
TorrentServer
Represents torrent client servers with:
local_node
: Node identifieraddress
: Server connection addresstype
: Client type (e.g., "Transmission")
Controllers
TorrentController
index()
: List all torrentsstore()
: Add new torrent from magnet URIshow()
: Get specific torrent detailsupdate()
: Modify torrent propertiesmarkIncomplete()
: Reset completion statusdestroy()
: Remove torrent
TorrentServerController
- Standard CRUD operations for torrent servers
getClientTypes()
: List supported client types
Torrent Clients
TransmissionClient
Implementation for Transmission torrent client with:
- RPC communication via HTTP
- Session management with X-Transmission-Session-Id headers
- Methods for adding, checking status, and removing torrents
TorrentClientBase
Abstract base class for implementing additional torrent clients
Commands
CheckTorrent (torrent:check
)
Background command that:
- Scans for incomplete torrents
- Checks status with respective torrent clients
- Updates completion timestamps
- Processes torrent lifecycle events
API Endpoints
All endpoints require authentication (auth:api
middleware) and use the configured route prefix.
Torrent Servers
GET /torrent-servers/client-types
- Get supported client typesGET /torrent-servers
- List all serversPOST /torrent-servers
- Create new serverGET /torrent-servers/{id}
- Get server detailsPUT /torrent-servers/{id}
- Update serverDELETE /torrent-servers/{id}
- Remove server
Torrents
GET /torrents
- List all torrentsPOST /torrents
- Add new torrentGET /torrents/{id}
- Get torrent detailsPUT /torrents/{id}
- Update torrentDELETE /torrents/{id}
- Remove torrentPATCH /torrents/{id}/mark-incomplete
- Mark as incomplete
Database Schema
Torrents Table
- id (UUID, primary key) - local_node (string) - server_id (UUID, foreign key) - user_id (UUID, nullable) - magnetURI (text) - hash_string (string, nullable) - name (string, nullable) - completed_at (timestamp, nullable) - created_at/updated_at (timestamps) - deleted_at (soft deletes)
Torrent Servers Table
- id (UUID, primary key) - local_node (string) - address (string) - type (string) - created_at/updated_at (timestamps) - deleted_at (soft deletes)
Usage Examples
Adding a Torrent
POST /api/torrents { "magnetURI": "magnet:?xt=urn:btih:...", "server_id": "uuid-of-server" // optional, uses default if not specified }
Checking Torrent Status
The system automatically processes torrents via the torrent:check
command, which can be run manually or scheduled:
php artisan torrent:check
Adding a New Torrent Server
POST /api/torrent-servers { "address": "192.168.1.100:9091", "type": "Transmission" }
Extending Client Support
To add support for new torrent clients:
- Create a new class extending
TorrentClientBase
- Implement required methods:
add()
,check()
,remove()
- Set the static
$type
property - Place in
src/TorrentClients/
directory
Example:
class QBittorrentClient extends TorrentClientBase { public static $type = "qBittorrent"; public function add($torrent) { /* implementation */ } public function check($hashString) { /* implementation */ } public function remove($hashString) { /* implementation */ } }