Announcer's code re-formatting (#1112)

This commit is contained in:
Cønstantine Kovalensky 2023-11-17 20:40:32 +04:00 committed by GitHub
commit 61ef24539a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 1 deletions

View file

@ -30,11 +30,13 @@ if (isset($_GET['?info_hash']) && !isset($_GET['info_hash'])) {
if (strpos($_SERVER['REQUEST_URI'], 'scrape') !== false) { if (strpos($_SERVER['REQUEST_URI'], 'scrape') !== false) {
msg_die('Please disable SCRAPE!'); msg_die('Please disable SCRAPE!');
} }
if (!isset($_GET[$passkey_key]) || !is_string($_GET[$passkey_key])) { if (!isset($_GET[$passkey_key]) || !is_string($_GET[$passkey_key])) {
msg_die('Please LOG IN and RE-DOWNLOAD this torrent (passkey not found)'); msg_die('Please LOG IN and RE-DOWNLOAD this torrent (passkey not found)');
} }
// Input var names // Input var names
// String // String
$input_vars_str = ['info_hash', 'peer_id', 'event', $passkey_key]; $input_vars_str = ['info_hash', 'peer_id', 'event', $passkey_key];
// Numeric // Numeric
@ -45,10 +47,12 @@ $input_vars_num = ['port', 'uploaded', 'downloaded', 'left', 'numwant', 'compact
foreach ($input_vars_str as $var_name) { foreach ($input_vars_str as $var_name) {
$$var_name = isset($_GET[$var_name]) ? (string)$_GET[$var_name] : null; $$var_name = isset($_GET[$var_name]) ? (string)$_GET[$var_name] : null;
} }
// Numeric // Numeric
foreach ($input_vars_num as $var_name) { foreach ($input_vars_num as $var_name) {
$$var_name = isset($_GET[$var_name]) ? (float)$_GET[$var_name] : null; $$var_name = isset($_GET[$var_name]) ? (float)$_GET[$var_name] : null;
} }
// Passkey // Passkey
$passkey = $$passkey_key ?? null; $passkey = $$passkey_key ?? null;
@ -83,9 +87,11 @@ if (!isset($port) || $port < 0 || $port > 0xFFFF) {
if (!isset($uploaded) || $uploaded < 0) { if (!isset($uploaded) || $uploaded < 0) {
msg_die('Invalid uploaded value: ' . $uploaded); msg_die('Invalid uploaded value: ' . $uploaded);
} }
if (!isset($downloaded) || $downloaded < 0) { if (!isset($downloaded) || $downloaded < 0) {
msg_die('Invalid downloaded value: ' . $downloaded); msg_die('Invalid downloaded value: ' . $downloaded);
} }
if (!isset($left) || $left < 0) { if (!isset($left) || $left < 0) {
msg_die('Invalid left value: ' . $left); msg_die('Invalid left value: ' . $left);
} }
@ -150,6 +156,7 @@ if ($lp_info && (!isset($event) || !$stopped)) {
} }
} }
} }
// Get last peer info from DB // Get last peer info from DB
if (!CACHE('tr_cache')->used && !$lp_info) { if (!CACHE('tr_cache')->used && !$lp_info) {
$lp_info = DB()->fetch_row(" $lp_info = DB()->fetch_row("
@ -339,7 +346,6 @@ if ((!$lp_info || !$peer_info_updated) && !$stopped && empty($hybrid_unrecord))
DB()->query("REPLACE INTO " . BB_BT_TRACKER . " ($columns) VALUES ($values)"); DB()->query("REPLACE INTO " . BB_BT_TRACKER . " ($columns) VALUES ($values)");
} }
// Exit if stopped // Exit if stopped
if ($stopped) { if ($stopped) {
silent_exit('Cache will be reset within 30 seconds'); silent_exit('Cache will be reset within 30 seconds');
@ -443,6 +449,7 @@ if (!$output) {
if (!empty($peers)) { if (!empty($peers)) {
$output['peers'] = $peers; $output['peers'] = $peers;
} }
if (!empty($peers6)) { if (!empty($peers6)) {
$output['peers6'] = $peers6; $output['peers6'] = $peers6;
} }

View file

@ -28,6 +28,7 @@ $info_hash = isset($_GET['info_hash']) ? (string)$_GET['info_hash'] : null;
if (!isset($info_hash)) { if (!isset($info_hash)) {
msg_die('info_hash was not provided'); msg_die('info_hash was not provided');
} }
// Store info hash in hex format // Store info hash in hex format
$info_hash_hex = mb_check_encoding($info_hash, 'UTF8') ? $info_hash : bin2hex($info_hash); $info_hash_hex = mb_check_encoding($info_hash, 'UTF8') ? $info_hash : bin2hex($info_hash);
@ -45,6 +46,7 @@ foreach ($info_hash_array[1] as $hash) {
if (strlen($decoded_hash) !== 20) { if (strlen($decoded_hash) !== 20) {
continue; continue;
} }
if ($scrape_cache = CACHE('tr_cache')->get(SCRAPE_LIST_PREFIX . bin2hex($decoded_hash))) { if ($scrape_cache = CACHE('tr_cache')->get(SCRAPE_LIST_PREFIX . bin2hex($decoded_hash))) {
$torrents['files'][$info_key = array_key_first($scrape_cache)] = $scrape_cache[$info_key]; $torrents['files'][$info_key = array_key_first($scrape_cache)] = $scrape_cache[$info_key];
} else { } else {