seria/public/download.php

38 lines
1.1 KiB
PHP
Raw Normal View History

2022-07-03 23:44:11 +00:00
<?php
require_once __DIR__ . '/../seria.php';
$dTorrentId = (string)filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT);
header('Content-Type: text/plain; charset=us-ascii');
try {
$dTorrentInfo = SeriaTorrent::byId($pdo, $dTorrentId);
} catch(SeriaTorrentNotFoundException $ex) {
http_response_code(404);
die('Download not found.');
}
$dCanDownload = $dTorrentInfo->canDownload($sUserInfo);
if($dCanDownload !== '') {
http_response_code(403);
switch($dCanDownload) {
case 'inactive':
die('This download is inactive.');
case 'private':
die('You must be logged in for this download.');
case 'pending':
die('This download is pending approval.');
default:
die($dCanDownload);
}
}
$trackerUrl = SERIA_ANNOUNCE_URL_ANON;
if($sUserInfo->isLoggedIn())
$trackerUrl = sprintf(SERIA_ANNOUNCE_URL, $sUserInfo->getPassKey($pdo));
header('Content-Type: application/x-bittorrent');
header('Content-Disposition: inline; filename="' . htmlspecialchars($dTorrentInfo->getName()) . '.torrent"');
echo $dTorrentInfo->encode($trackerUrl);