mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-25 12:37:23 +08:00
merge 1.9
This commit is contained in:
@@ -42,11 +42,16 @@ class UserResource extends JsonResource
|
|||||||
'bonus_human' => number_format($this->seedbonus, 1),
|
'bonus_human' => number_format($this->seedbonus, 1),
|
||||||
'seed_points' => floatval($this->seed_points),
|
'seed_points' => floatval($this->seed_points),
|
||||||
'seed_points_human' => number_format($this->seed_points, 1),
|
'seed_points_human' => number_format($this->seed_points, 1),
|
||||||
|
'seed_points_per_hour' => floatval($this->seed_points_per_hour),
|
||||||
|
'seed_points_per_hour_human' => number_format($this->seed_points_per_hour, 1),
|
||||||
|
'seed_bonus_per_hour' => floatval($this->seed_bonus_per_hour),
|
||||||
|
'seed_bonus_per_hour_human' => number_format($this->seed_bonus_per_hour, 1),
|
||||||
'seedtime' => $this->seedtime,
|
'seedtime' => $this->seedtime,
|
||||||
'seedtime_text' => mkprettytime($this->seedtime),
|
'seedtime_text' => mkprettytime($this->seedtime),
|
||||||
'leechtime' => $this->leechtime,
|
'leechtime' => $this->leechtime,
|
||||||
'leechtime_text' => mkprettytime($this->leechtime),
|
'leechtime_text' => mkprettytime($this->leechtime),
|
||||||
'share_ratio' => get_ratio($this->id),
|
'share_ratio' => get_ratio($this->id),
|
||||||
|
'seeding_leeching_data' => $this->whenHas('seeding_leeching_data'),
|
||||||
'inviter' => new UserResource($this->whenLoaded('inviter')),
|
'inviter' => new UserResource($this->whenLoaded('inviter')),
|
||||||
'valid_medals' => MedalResource::collection($this->whenLoaded('valid_medals')),
|
'valid_medals' => MedalResource::collection($this->whenLoaded('valid_medals')),
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class CalculateUserSeedBonus implements ShouldQueue
|
|||||||
$logFile = getLogFile("seed-bonus-points");
|
$logFile = getLogFile("seed-bonus-points");
|
||||||
do_log("$logPrefix, [GET_UID_REAL], count: " . count($results) . ", logFile: $logFile");
|
do_log("$logPrefix, [GET_UID_REAL], count: " . count($results) . ", logFile: $logFile");
|
||||||
$fd = fopen($logFile, 'a');
|
$fd = fopen($logFile, 'a');
|
||||||
$seedPointsUpdates = $seedPointsPerHourUpdates = $seedBonusUpdates = [];
|
$seedPointsUpdates = $seedPointsPerHourUpdates = $seedBonusPerHourUpdates = $seedBonusUpdates = [];
|
||||||
$seedingTorrentCountUpdates = $seedingTorrentSizeUpdates = [];
|
$seedingTorrentCountUpdates = $seedingTorrentSizeUpdates = [];
|
||||||
$logStr = "";
|
$logStr = "";
|
||||||
$bonusLogInsert = [];
|
$bonusLogInsert = [];
|
||||||
@@ -159,6 +159,7 @@ class CalculateUserSeedBonus implements ShouldQueue
|
|||||||
// NexusDB::statement($sql);
|
// NexusDB::statement($sql);
|
||||||
$seedPointsUpdates[] = sprintf("when %d then ifnull(seed_points, 0) + %f", $uid, $seed_points);
|
$seedPointsUpdates[] = sprintf("when %d then ifnull(seed_points, 0) + %f", $uid, $seed_points);
|
||||||
$seedPointsPerHourUpdates[] = sprintf("when %d then %f", $uid, $seedBonusResult['seed_points']);
|
$seedPointsPerHourUpdates[] = sprintf("when %d then %f", $uid, $seedBonusResult['seed_points']);
|
||||||
|
$seedBonusPerHourUpdates[] = sprintf("when %d then %f", $uid, $seedBonusResult['seed_bonus']);
|
||||||
$seedingTorrentCountUpdates[] = sprintf("when %d then %f", $uid, $seedBonusResult['torrent_peer_count']);
|
$seedingTorrentCountUpdates[] = sprintf("when %d then %f", $uid, $seedBonusResult['torrent_peer_count']);
|
||||||
$seedingTorrentSizeUpdates[] = sprintf("when %d then %f", $uid, $seedBonusResult['size']);
|
$seedingTorrentSizeUpdates[] = sprintf("when %d then %f", $uid, $seedBonusResult['size']);
|
||||||
$seedBonusUpdates[] = sprintf("when %d then seedbonus + %f", $uid, $all_bonus);
|
$seedBonusUpdates[] = sprintf("when %d then seedbonus + %f", $uid, $all_bonus);
|
||||||
@@ -177,8 +178,8 @@ class CalculateUserSeedBonus implements ShouldQueue
|
|||||||
}
|
}
|
||||||
$nowStr = now()->toDateTimeString();
|
$nowStr = now()->toDateTimeString();
|
||||||
$sql = sprintf(
|
$sql = sprintf(
|
||||||
"update users set seed_points = case id %s end, seed_points_per_hour = case id %s end, seedbonus = case id %s end, seeding_torrent_count = case id %s end, seeding_torrent_size = case id %s end, seed_points_updated_at = '%s' where id in (%s)",
|
"update users set seed_points = case id %s end, seed_points_per_hour = case id %s end, seed_bonus_per_hour = case id %s end, seedbonus = case id %s end, seeding_torrent_count = case id %s end, seeding_torrent_size = case id %s end, seed_points_updated_at = '%s' where id in (%s)",
|
||||||
implode(" ", $seedPointsUpdates), implode(" ", $seedPointsPerHourUpdates), implode(" ", $seedBonusUpdates), implode(" ", $seedingTorrentCountUpdates), implode(" ", $seedingTorrentSizeUpdates), $nowStr, $idStr
|
implode(" ", $seedPointsUpdates), implode(" ", $seedPointsPerHourUpdates), implode(" ", $seedBonusPerHourUpdates), implode(" ", $seedBonusUpdates), implode(" ", $seedingTorrentCountUpdates), implode(" ", $seedingTorrentSizeUpdates), $nowStr, $idStr
|
||||||
);
|
);
|
||||||
$result = NexusDB::statement($sql);
|
$result = NexusDB::statement($sql);
|
||||||
if ($delIdRedisKey) {
|
if ($delIdRedisKey) {
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ use Nexus\Database\NexusDB;
|
|||||||
|
|
||||||
class UserRepository extends BaseRepository
|
class UserRepository extends BaseRepository
|
||||||
{
|
{
|
||||||
|
private static array $allowIncludes = ['inviter', 'valid_medals'];
|
||||||
|
private static array $allowIncludeFields = ['seeding_leeching_data'];
|
||||||
|
private static array $allowIncludeCounts = [];
|
||||||
public function getList(array $params)
|
public function getList(array $params)
|
||||||
{
|
{
|
||||||
$query = User::query();
|
$query = User::query();
|
||||||
@@ -66,28 +69,34 @@ class UserRepository extends BaseRepository
|
|||||||
{
|
{
|
||||||
//query this info default
|
//query this info default
|
||||||
$query = User::query()->with([]);
|
$query = User::query()->with([]);
|
||||||
$allowIncludes = ['inviter', 'valid_medals'];
|
|
||||||
$allowIncludeCounts = [];
|
|
||||||
$allowIncludeFields = [];
|
|
||||||
$apiQueryBuilder = ApiQueryBuilder::for(UserResource::NAME, $query)
|
$apiQueryBuilder = ApiQueryBuilder::for(UserResource::NAME, $query)
|
||||||
->allowIncludes($allowIncludes)
|
->allowIncludes(self::$allowIncludes)
|
||||||
->allowIncludeCounts($allowIncludeCounts)
|
->allowIncludeCounts(self::$allowIncludeCounts)
|
||||||
->allowIncludeFields($allowIncludeFields)
|
->allowIncludeFields(self::$allowIncludeFields)
|
||||||
;
|
;
|
||||||
$query = $apiQueryBuilder->build();
|
$query = $apiQueryBuilder->build();
|
||||||
$user = $query->findOrFail($id);
|
$user = $query->findOrFail($id);
|
||||||
Gate::authorize('view', $user);
|
Gate::authorize('view', $user);
|
||||||
return $this->appendIncludeFields($apiQueryBuilder, $currentUser, $user);
|
$userList = $this->appendIncludeFields($apiQueryBuilder, $currentUser, [$user]);
|
||||||
|
return $userList[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
private function appendIncludeFields(ApiQueryBuilder $apiQueryBuilder, Authenticatable $currentUser, User $user): User
|
private function appendIncludeFields(ApiQueryBuilder $apiQueryBuilder, Authenticatable $currentUser, $userList)
|
||||||
{
|
{
|
||||||
// $id = $torrent->id;
|
$idArr = [];
|
||||||
// if ($apiQueryBuilder->hasIncludeField('has_bookmarked')) {
|
foreach ($userList as $user) {
|
||||||
// $torrent->has_bookmarked = (int)$user->bookmarks()->where('torrentid', $id)->exists();;
|
$idArr[] = $user->id;
|
||||||
// }
|
}
|
||||||
|
if ($hasFieldSeedingData = $apiQueryBuilder->hasIncludeField('seeding_leeching_data')) {
|
||||||
return $user;
|
$seedingData = $this->listUserSeedingLeechingData($idArr);
|
||||||
|
}
|
||||||
|
foreach ($userList as $user) {
|
||||||
|
$id = $user->id;
|
||||||
|
if ($hasFieldSeedingData && isset($seedingData[$id])) {
|
||||||
|
$user->seeding_leeching_data = $seedingData[$id];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $userList;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -259,7 +268,7 @@ class UserRepository extends BaseRepository
|
|||||||
|
|
||||||
private function setEnableLatelyCache(int $userId): void
|
private function setEnableLatelyCache(int $userId): void
|
||||||
{
|
{
|
||||||
NexusDB::cache_put(User::getUserEnableLatelyCacheKey($userId), now()->toDateTimeString());
|
NexusDB::cache_put(User::getUserEnableLatelyCacheKey($userId), now()->toDateTimeString(), 86400);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getInviteInfo($id)
|
public function getInviteInfo($id)
|
||||||
@@ -814,4 +823,38 @@ class UserRepository extends BaseRepository
|
|||||||
return $loginLog;
|
return $loginLog;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get user seeding/leeching count and size
|
||||||
|
*
|
||||||
|
* @see calculate_seed_bonus()
|
||||||
|
* @param array $userIdArr
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
private function listUserSeedingLeechingData(array $userIdArr)
|
||||||
|
{
|
||||||
|
$minSize = get_setting('bonus.min_size', 0);
|
||||||
|
$idStr = implode(",", $userIdArr);
|
||||||
|
$sql = "select peers.userid, peers.seeder, torrents.size from torrents LEFT JOIN peers ON peers.torrent = torrents.id WHERE peers.userid in ($idStr) and torrents.size > $minSize group by peers.torrent, peers.peer_id, peers.userid, peers.seeder";
|
||||||
|
$data = NexusDB::select($sql);
|
||||||
|
$result = [];
|
||||||
|
foreach ($data as $row) {
|
||||||
|
if (!isset($result[$row['userid']])) {
|
||||||
|
$result[$row['userid']] = [
|
||||||
|
'seeding_count' => 0,
|
||||||
|
'seeding_size' => 0,
|
||||||
|
'leeching_count' => 0,
|
||||||
|
'leeching_size' => 0,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
if ($row['seeder'] == 'yes') {
|
||||||
|
$result[$row['userid']]['seeding_count'] += 1;
|
||||||
|
$result[$row['userid']]['seeding_size'] += $row['size'];
|
||||||
|
} else {
|
||||||
|
$result[$row['userid']]['leeching_count'] += 1;
|
||||||
|
$result[$row['userid']]['leeching_size'] += $row['size'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->decimal('seed_bonus_per_hour', 20, 1)->default(0)->after('seed_points_per_hour');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('seed_bonus_per_hour');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
+1
-1
@@ -341,7 +341,7 @@ function docleanup($forceAll = 0, $printProgress = false) {
|
|||||||
|
|
||||||
//rest seed_points_per_hour
|
//rest seed_points_per_hour
|
||||||
$seedPointsUpdatedAtMin = $carbonNow->subSeconds(2*intval($autoclean_interval_one))->toDateTimeString();
|
$seedPointsUpdatedAtMin = $carbonNow->subSeconds(2*intval($autoclean_interval_one))->toDateTimeString();
|
||||||
sql_query("update users set seed_points_per_hour = 0 where seed_points_updated_at < " . sqlesc($seedPointsUpdatedAtMin));
|
sql_query("update users set seed_points_per_hour = 0, seed_bonus_per_hour = 0, seeding_torrent_count = 0, seeding_torrent_size = 0 where seed_points_updated_at < " . sqlesc($seedPointsUpdatedAtMin));
|
||||||
|
|
||||||
\App\Repositories\CleanupRepository::runBatchJobCalculateUserSeedBonus($requestId);
|
\App\Repositories\CleanupRepository::runBatchJobCalculateUserSeedBonus($requestId);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.11');
|
defined('VERSION_NUMBER') || define('VERSION_NUMBER', '1.9.13');
|
||||||
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-11-02');
|
defined('RELEASE_DATE') || define('RELEASE_DATE', '2025-12-28');
|
||||||
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
defined('IN_TRACKER') || define('IN_TRACKER', false);
|
||||||
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
defined('PROJECTNAME') || define("PROJECTNAME","NexusPHP");
|
||||||
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
defined('NEXUSPHPURL') || define("NEXUSPHPURL","https://nexusphp.org");
|
||||||
|
|||||||
@@ -3906,10 +3906,12 @@ foreach ($rows as $row)
|
|||||||
|
|
||||||
if (user_can('torrentmanage'))
|
if (user_can('torrentmanage'))
|
||||||
{
|
{
|
||||||
|
$actions = [];
|
||||||
if (user_can('torrent-delete')) {
|
if (user_can('torrent-delete')) {
|
||||||
print("<td class=\"rowfollow\"><a href=\"".htmlspecialchars("fastdelete.php?id=".$row['id'])."\"><img class=\"staff_delete\" src=\"pic/trans.gif\" alt=\"D\" title=\"".$lang_functions['text_delete']."\" /></a>");
|
$actions[] = "<a href=\"".htmlspecialchars("fastdelete.php?id=".$row['id'])."\"><img class=\"staff_delete\" src=\"pic/trans.gif\" alt=\"D\" title=\"".$lang_functions['text_delete']."\" /></a>";
|
||||||
}
|
}
|
||||||
print("<br /><a href=\"edit.php?returnto=" . rawurlencode($_SERVER["REQUEST_URI"]) . "&id=" . $row["id"] . "\"><img class=\"staff_edit\" src=\"pic/trans.gif\" alt=\"E\" title=\"".$lang_functions['text_edit']."\" /></a></td>\n");
|
$actions[] = "<a href=\"edit.php?returnto=" . rawurlencode($_SERVER["REQUEST_URI"]) . "&id=" . $row["id"] . "\"><img class=\"staff_edit\" src=\"pic/trans.gif\" alt=\"E\" title=\"".$lang_functions['text_edit']."\" /></a>";
|
||||||
|
echo sprintf("<td class=\"rowfollow\">%s</td>", implode("<br />", $actions));
|
||||||
}
|
}
|
||||||
print("</tr>\n");
|
print("</tr>\n");
|
||||||
$counter++;
|
$counter++;
|
||||||
|
|||||||
@@ -1668,6 +1668,14 @@ JS;
|
|||||||
\Nexus\Nexus::js($js, 'footer', false);
|
\Nexus\Nexus::js($js, 'footer', false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function nexus_escape($data): array|string
|
||||||
|
{
|
||||||
|
if (is_array($data)) {
|
||||||
|
return array_map('nexus_escape', $data);
|
||||||
|
}
|
||||||
|
return htmlspecialchars($data, ENT_QUOTES, 'UTF-8');
|
||||||
|
}
|
||||||
|
|
||||||
function is_fpm_mode(): bool
|
function is_fpm_mode(): bool
|
||||||
{
|
{
|
||||||
return php_sapi_name() === 'fpm-fcgi';
|
return php_sapi_name() === 'fpm-fcgi';
|
||||||
|
|||||||
@@ -84,14 +84,15 @@ class PTGen
|
|||||||
|
|
||||||
public function generate(string $url, bool $withoutCache = false): array
|
public function generate(string $url, bool $withoutCache = false): array
|
||||||
{
|
{
|
||||||
$parsed = $this->parse($url);
|
// $parsed = $this->parse($url);
|
||||||
$targetUrl = trim($this->apiPoint, '/');
|
$targetUrl = trim($this->apiPoint, '/');
|
||||||
if (Str::contains($targetUrl, '?')) {
|
if (Str::contains($targetUrl, '?')) {
|
||||||
$targetUrl .= "&";
|
$targetUrl .= "&";
|
||||||
} else {
|
} else {
|
||||||
$targetUrl .= "?";
|
$targetUrl .= "?";
|
||||||
}
|
}
|
||||||
$targetUrl .= sprintf('site=%s&sid=%s&url=%s', $parsed['site'] , $parsed['id'], urlencode($parsed['url']));
|
// $targetUrl .= sprintf('site=%s&sid=%s&url=%s', $parsed['site'] , $parsed['id'], urlencode($parsed['url']));
|
||||||
|
$targetUrl .= "url=" . urlencode($url);
|
||||||
return $this->request($targetUrl, $withoutCache);
|
return $this->request($targetUrl, $withoutCache);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -177,7 +178,7 @@ HTML;
|
|||||||
}
|
}
|
||||||
do_log("$logPrefix, going to send request...");
|
do_log("$logPrefix, going to send request...");
|
||||||
$http = new Client();
|
$http = new Client();
|
||||||
$response = $http->get($url, ['timeout' => 10]);
|
$response = $http->post($url, ['timeout' => 10]);
|
||||||
$statusCode = $response->getStatusCode();
|
$statusCode = $response->getStatusCode();
|
||||||
if ($statusCode != 200) {
|
if ($statusCode != 200) {
|
||||||
$msg = "api point response http status code: $statusCode";
|
$msg = "api point response http status code: $statusCode";
|
||||||
|
|||||||
+1
-2
@@ -29,7 +29,6 @@ $row = mysql_fetch_array($res);
|
|||||||
if (user_can('torrentmanage') || $CURUSER["id"] == $row["owner"])
|
if (user_can('torrentmanage') || $CURUSER["id"] == $row["owner"])
|
||||||
$owned = 1;
|
$owned = 1;
|
||||||
else $owned = 0;
|
else $owned = 0;
|
||||||
|
|
||||||
$settingMain = get_setting('main');
|
$settingMain = get_setting('main');
|
||||||
if (!$row) {
|
if (!$row) {
|
||||||
stderr($lang_details['std_error'], $lang_details['std_no_torrent_id']);
|
stderr($lang_details['std_error'], $lang_details['std_no_torrent_id']);
|
||||||
@@ -308,7 +307,7 @@ JS;
|
|||||||
|
|
||||||
//technical info
|
//technical info
|
||||||
if ($settingMain['enable_technical_info'] == 'yes') {
|
if ($settingMain['enable_technical_info'] == 'yes') {
|
||||||
$technicalData = $row['technical_info'] ?? '';
|
$technicalData = nexus_escape($row['technical_info'] ?? '');
|
||||||
|
|
||||||
// 判断是否为BDINFO格式
|
// 判断是否为BDINFO格式
|
||||||
$isBdInfo = false;
|
$isBdInfo = false;
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ if(!empty($_POST['conusr'])) {
|
|||||||
// sql_query("UPDATE users SET status = 'confirmed', editsecret = '' WHERE id IN (" . implode(", ", $_POST['conusr']) . ") AND status='pending'");
|
// sql_query("UPDATE users SET status = 'confirmed', editsecret = '' WHERE id IN (" . implode(", ", $_POST['conusr']) . ") AND status='pending'");
|
||||||
$userList = \App\Models\User::query()->whereIn('id', $_POST['conusr'])
|
$userList = \App\Models\User::query()->whereIn('id', $_POST['conusr'])
|
||||||
->where('status', 'pending')
|
->where('status', 'pending')
|
||||||
|
->where('invited_by', $id)
|
||||||
->get(\App\Models\User::$commonFields)
|
->get(\App\Models\User::$commonFields)
|
||||||
;
|
;
|
||||||
if ($userList->isNotEmpty()) {
|
if ($userList->isNotEmpty()) {
|
||||||
@@ -21,6 +22,9 @@ if(!empty($_POST['conusr'])) {
|
|||||||
fire_event(\App\Enums\ModelEventEnum::USER_UPDATED, $user);
|
fire_event(\App\Enums\ModelEventEnum::USER_UPDATED, $user);
|
||||||
}
|
}
|
||||||
\App\Models\User::query()->whereIn('id', $uidArr)->update(['status' => 'confirmed', 'editsecret' => '']);
|
\App\Models\User::query()->whereIn('id', $uidArr)->update(['status' => 'confirmed', 'editsecret' => '']);
|
||||||
|
} else {
|
||||||
|
stderr($lang_takeconfirm['std_sorry'],$lang_takeconfirm['std_no_buddy_to_confirm'].
|
||||||
|
"<a class=altlink href=invite.php?id={$CURUSER['id']}>".$lang_takeconfirm['std_here_to_go_back'],false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
stderr($lang_takeconfirm['std_sorry'],$lang_takeconfirm['std_no_buddy_to_confirm'].
|
stderr($lang_takeconfirm['std_sorry'],$lang_takeconfirm['std_no_buddy_to_confirm'].
|
||||||
|
|||||||
Reference in New Issue
Block a user