Don't update download counter if attachment not exists (#1345)

* Don't update download counter if attachment not exists

* Update CHANGELOG.md

* Update CHANGELOG.md

* Updated
This commit is contained in:
Roman Kelesidis 2024-01-27 10:33:02 +07:00 committed by GitHub
commit 8b78253ddc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 381 additions and 25 deletions

View file

@ -20,6 +20,7 @@
- Fixed auth(): empty $f_access [\#1329](https://github.com/torrentpier/torrentpier/pull/1329) ([belomaxorka](https://github.com/belomaxorka))
- Fixed HTTP 500 while cron running in server-side [\#1321](https://github.com/torrentpier/torrentpier/pull/1321) ([belomaxorka](https://github.com/belomaxorka))
- Sending debug errors to us 🌚 via Telegram bot [\#1323](https://github.com/torrentpier/torrentpier/pull/1323) ([belomaxorka](https://github.com/belomaxorka))
- Don't update downloads counter if attachment not exists [\#1345](https://github.com/torrentpier/torrentpier/pull/1345) ([belomaxorka](https://github.com/belomaxorka))
- Minor improvements [\#1306](https://github.com/torrentpier/torrentpier/pull/1306), [\#1307](https://github.com/torrentpier/torrentpier/pull/1307), [\#1308](https://github.com/torrentpier/torrentpier/pull/1308), [\#1315](https://github.com/torrentpier/torrentpier/pull/1315), [\#1328](https://github.com/torrentpier/torrentpier/pull/1328), [\#1338](https://github.com/torrentpier/torrentpier/pull/1338) ([belomaxorka](https://github.com/belomaxorka))
- Some bugfixes [\#1326](https://github.com/torrentpier/torrentpier/pull/1326) ([belomaxorka](https://github.com/belomaxorka))
- Updated deps [\#1304](https://github.com/torrentpier/torrentpier/pull/1304), [\#1305](https://github.com/torrentpier/torrentpier/pull/1305) ([belomaxorka](https://github.com/belomaxorka))

View file

@ -214,11 +214,11 @@ if ($lp_info) {
// Check hybrid status
if (!empty($row['info_hash']) && !empty($row['info_hash_v2'])) {
$stat_protocol = match($bb_cfg['tracker']['hybrid_stat_protocol']) {
1 => $row['info_hash'],
2 => substr($row['info_hash_v2'], 0, 20),
default => $row['info_hash']
};
$stat_protocol = match ($bb_cfg['tracker']['hybrid_stat_protocol']) {
1 => $row['info_hash'],
2 => substr($row['info_hash_v2'], 0, 20),
default => $row['info_hash']
};
if ($info_hash !== $stat_protocol) {
$hybrid_unrecord = true; // This allows us to announce only for one info-hash
}

377
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "3e19fe76f513cea154195f8eb132bfa0",
"content-hash": "0d3ba700ad5fce7abfc08815599a39b3",
"packages": [
{
"name": "arokettu/bencode",
@ -136,6 +136,140 @@
},
"time": "2023-08-28T12:32:54+00:00"
},
{
"name": "arokettu/system-clock",
"version": "2.0.0",
"source": {
"type": "git",
"url": "https://github.com/arokettu/php-system-clock.git",
"reference": "e083272437c573b8b84d38aef3b89a1d07daca6f"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/arokettu/php-system-clock/zipball/e083272437c573b8b84d38aef3b89a1d07daca6f",
"reference": "e083272437c573b8b84d38aef3b89a1d07daca6f",
"shasum": ""
},
"require": {
"php": "^7.0 | ^8.0",
"psr/clock": "^1.0"
},
"conflict": {
"arokettu/clock": "< 1.2 | >=2.0 <2.2"
},
"provide": {
"psr/clock-implementation": "1.0"
},
"require-dev": {
"sandfox.dev/code-standard": "^1.2022.06.29",
"squizlabs/php_codesniffer": "*",
"vimeo/psalm": "^4 | ^5"
},
"type": "library",
"autoload": {
"classmap": [
"SystemClock.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT-0"
],
"authors": [
{
"name": "Anton Smirnov",
"email": "sandfox@sandfox.me",
"homepage": "https://sandfox.me/",
"role": "developer"
}
],
"description": "The smallest PSR-20 implementation",
"homepage": "https://sandfox.dev/php/clock/system-clock.html",
"keywords": [
"clock",
"psr-20",
"smallest"
],
"support": {
"chat": "https://gitter.im/arokettu/community",
"docs": "https://arokettu-clock.readthedocs.io/en/latest/system-clock.html",
"issues": "https://gitlab.com/sandfox/php-system-clock/-/issues",
"source": "https://gitlab.com/sandfox/php-system-clock"
},
"time": "2023-06-02T16:38:36+00:00"
},
{
"name": "arokettu/torrent-file",
"version": "5.2.1",
"source": {
"type": "git",
"url": "https://github.com/arokettu/torrent-file.git",
"reference": "7ad8f420836b849574ae62bef06ddbb0271b1ce6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/arokettu/torrent-file/zipball/7ad8f420836b849574ae62bef06ddbb0271b1ce6",
"reference": "7ad8f420836b849574ae62bef06ddbb0271b1ce6",
"shasum": ""
},
"require": {
"arokettu/bencode": "^2.8 | ^3.1 | ^4.0",
"arokettu/system-clock": "^2.0",
"ext-hash": "*",
"nikic/iter": "^2.2",
"php": "^8.1",
"psr/clock": "^1.0",
"psr/event-dispatcher": "^1.0",
"symfony/filesystem": "^5.4 | ^6.0 | ^7.0",
"symfony/finder": "^5.4 | ^6.0 | ^7.0"
},
"require-dev": {
"arokettu/clock": "^2.4",
"ext-openssl": "*",
"jetbrains/phpstorm-attributes": "^1.0",
"league/event": "^3.0",
"phpunit/phpunit": "^10.5.3",
"psy/psysh": "*",
"sandfox.dev/code-standard": "^1.2023.12.09",
"squizlabs/php_codesniffer": "*",
"vimeo/psalm": "^5.2"
},
"suggest": {
"ext-openssl": "for signature logic"
},
"type": "library",
"autoload": {
"psr-4": {
"Arokettu\\Torrent\\": "src"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Anton Smirnov",
"email": "sandfox@sandfox.me",
"homepage": "https://sandfox.me/",
"role": "developer"
}
],
"description": "A class to work with torrent files",
"homepage": "https://sandfox.dev/php/torrent-file.html",
"keywords": [
"bittorrent",
"torrent",
"torrent-file"
],
"support": {
"chat": "https://gitter.im/arokettu/community",
"docs": "https://torrent-file.readthedocs.io/",
"issues": "https://gitlab.com/sandfox/torrent-file/-/issues",
"source": "https://gitlab.com/sandfox/torrent-file"
},
"time": "2023-12-17T19:59:55+00:00"
},
{
"name": "bugsnag/bugsnag",
"version": "v3.29.1",
@ -254,16 +388,16 @@
},
{
"name": "composer/ca-bundle",
"version": "1.3.7",
"version": "1.4.0",
"source": {
"type": "git",
"url": "https://github.com/composer/ca-bundle.git",
"reference": "76e46335014860eec1aa5a724799a00a2e47cc85"
"reference": "b66d11b7479109ab547f9405b97205640b17d385"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/composer/ca-bundle/zipball/76e46335014860eec1aa5a724799a00a2e47cc85",
"reference": "76e46335014860eec1aa5a724799a00a2e47cc85",
"url": "https://api.github.com/repos/composer/ca-bundle/zipball/b66d11b7479109ab547f9405b97205640b17d385",
"reference": "b66d11b7479109ab547f9405b97205640b17d385",
"shasum": ""
},
"require": {
@ -275,7 +409,7 @@
"phpstan/phpstan": "^0.12.55",
"psr/log": "^1.0",
"symfony/phpunit-bridge": "^4.2 || ^5",
"symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0"
"symfony/process": "^2.5 || ^3.0 || ^4.0 || ^5.0 || ^6.0 || ^7.0"
},
"type": "library",
"extra": {
@ -310,7 +444,7 @@
"support": {
"irc": "irc://irc.freenode.org/composer",
"issues": "https://github.com/composer/ca-bundle/issues",
"source": "https://github.com/composer/ca-bundle/tree/1.3.7"
"source": "https://github.com/composer/ca-bundle/tree/1.4.0"
},
"funding": [
{
@ -326,7 +460,7 @@
"type": "tidelift"
}
],
"time": "2023-08-30T09:31:38+00:00"
"time": "2023-12-18T12:05:55+00:00"
},
{
"name": "doctrine/lexer",
@ -1384,6 +1518,58 @@
],
"time": "2023-10-27T15:32:31+00:00"
},
{
"name": "nikic/iter",
"version": "v2.4.0",
"source": {
"type": "git",
"url": "https://github.com/nikic/iter.git",
"reference": "09cd930fa9ff55747f34c7184532a5a1bd2385b1"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/iter/zipball/09cd930fa9ff55747f34c7184532a5a1bd2385b1",
"reference": "09cd930fa9ff55747f34c7184532a5a1bd2385b1",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"phpstan/phpstan": "^1.4",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
"vimeo/psalm": "^4.18 || ^5.13"
},
"type": "library",
"autoload": {
"files": [
"src/iter.func.php",
"src/iter.php",
"src/iter.rewindable.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"BSD-3-Clause"
],
"authors": [
{
"name": "Nikita Popov",
"email": "nikic@php.net"
}
],
"description": "Iteration primitives using generators",
"keywords": [
"functional",
"generator",
"iterator"
],
"support": {
"issues": "https://github.com/nikic/iter/issues",
"source": "https://github.com/nikic/iter/tree/v2.4.0"
},
"time": "2023-12-10T20:43:19+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.9.2",
@ -1459,6 +1645,54 @@
],
"time": "2023-11-12T21:59:55+00:00"
},
{
"name": "psr/clock",
"version": "1.0.0",
"source": {
"type": "git",
"url": "https://github.com/php-fig/clock.git",
"reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/php-fig/clock/zipball/e41a24703d4560fd0acb709162f73b8adfc3aa0d",
"reference": "e41a24703d4560fd0acb709162f73b8adfc3aa0d",
"shasum": ""
},
"require": {
"php": "^7.0 || ^8.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Psr\\Clock\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "PHP-FIG",
"homepage": "https://www.php-fig.org/"
}
],
"description": "Common interface for reading the clock.",
"homepage": "https://github.com/php-fig/clock",
"keywords": [
"clock",
"now",
"psr",
"psr-20",
"time"
],
"support": {
"issues": "https://github.com/php-fig/clock/issues",
"source": "https://github.com/php-fig/clock/tree/1.0.0"
},
"time": "2022-11-25T14:36:26+00:00"
},
{
"name": "psr/container",
"version": "2.0.2",
@ -2098,6 +2332,133 @@
],
"time": "2023-05-23T14:45:45+00:00"
},
{
"name": "symfony/filesystem",
"version": "v6.4.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/filesystem.git",
"reference": "952a8cb588c3bc6ce76f6023000fb932f16a6e59"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/filesystem/zipball/952a8cb588c3bc6ce76f6023000fb932f16a6e59",
"reference": "952a8cb588c3bc6ce76f6023000fb932f16a6e59",
"shasum": ""
},
"require": {
"php": ">=8.1",
"symfony/polyfill-ctype": "~1.8",
"symfony/polyfill-mbstring": "~1.8"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Filesystem\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides basic utilities for the filesystem",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/filesystem/tree/v6.4.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-07-26T17:27:13+00:00"
},
{
"name": "symfony/finder",
"version": "v6.4.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/finder.git",
"reference": "11d736e97f116ac375a81f96e662911a34cd50ce"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/finder/zipball/11d736e97f116ac375a81f96e662911a34cd50ce",
"reference": "11d736e97f116ac375a81f96e662911a34cd50ce",
"shasum": ""
},
"require": {
"php": ">=8.1"
},
"require-dev": {
"symfony/filesystem": "^6.0|^7.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Finder\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Finds files and directories via an intuitive fluent interface",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/finder/tree/v6.4.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2023-10-31T17:30:12+00:00"
},
{
"name": "symfony/mailer",
"version": "v6.4.2",

13
dl.php
View file

@ -26,14 +26,13 @@ function send_file_to_browser($attachment, $upload_dir)
{
global $bb_cfg, $lang;
$filename = ($upload_dir == '') ? $attachment['physical_filename'] : $upload_dir . '/' . $attachment['physical_filename'];
$filename = $upload_dir . '/' . $attachment['physical_filename'];
$gotit = false;
if (@!file_exists(realpath($filename))) {
bb_die($lang['ERROR_NO_ATTACHMENT'] . '<br /><br />' . htmlCHR($filename));
} else {
if (is_file(realpath($filename))) {
$gotit = true;
} else {
bb_die($lang['ERROR_NO_ATTACHMENT'] . '<br /><br />' . htmlCHR($filename));
}
// Correct the mime type - we force application/octet-stream for all files, except images
@ -62,7 +61,7 @@ function send_file_to_browser($attachment, $upload_dir)
// Now send the File Contents to the Browser
if ($gotit) {
$size = @filesize($filename);
$size = filesize($filename);
if ($size) {
header("Content-length: $size");
}
@ -195,7 +194,7 @@ if (isset($download_mode[$attachment['extension']])) {
}
// Update download count
if (!$thumbnail) {
if (!$thumbnail && is_file(realpath($upload_dir . '/' . $attachment['physical_filename']))) {
$sql = 'UPDATE ' . BB_ATTACHMENTS_DESC . ' SET download_count = download_count + 1 WHERE attach_id = ' . (int)$attachment['attach_id'];
if (!DB()->sql_query($sql)) {

View file

@ -181,11 +181,6 @@ function display_attachments($post_id)
for ($i = 0; $i < $num_attachments; $i++) {
$filename = $upload_dir . '/' . basename($attachments['_' . $post_id][$i]['physical_filename']);
// Checks the file existence
if (!is_file($filename)) {
continue;
}
$upload_image = '';
if ($attach_config['upload_img'] && empty($upload_icons[$attachments['_' . $post_id][$i]['extension']])) {
$upload_image = '<img src="' . $attach_config['upload_img'] . '" alt="" border="0" />';