diff --git a/app/Console/Commands/TorrentLoadPiecesHash.php b/app/Console/Commands/TorrentLoadPiecesHash.php index 1872c8d9..fa4d2a36 100644 --- a/app/Console/Commands/TorrentLoadPiecesHash.php +++ b/app/Console/Commands/TorrentLoadPiecesHash.php @@ -31,7 +31,7 @@ class TorrentLoadPiecesHash extends Command $begin = time(); $id = $this->option('id'); $rep = new TorrentRepository(); - $this->info("id: $id"); + $this->info("id: $id, going to load pieces hash..."); $total = $rep->loadPiecesHashCache($id); $this->info(sprintf("total: %s, cost time: %s seconds.", $total, time() - $begin)); return Command::SUCCESS; diff --git a/app/Providers/AuthServiceProvider.php b/app/Providers/AuthServiceProvider.php index 1a716d36..048a1ea7 100644 --- a/app/Providers/AuthServiceProvider.php +++ b/app/Providers/AuthServiceProvider.php @@ -64,6 +64,10 @@ class AuthServiceProvider extends ServiceProvider return new NexusWebGuard($app['request'], new NexusWebUserProvider()); }); + Auth::viaRequest('passkey', function (Request $request) { + return User::query()->where('passkey', $request->passkey)->first(); + }); + } private function getUserByCookie($cookie) diff --git a/app/Repositories/CleanupRepository.php b/app/Repositories/CleanupRepository.php index 8a3c3406..6ce3770a 100644 --- a/app/Repositories/CleanupRepository.php +++ b/app/Repositories/CleanupRepository.php @@ -39,7 +39,7 @@ class CleanupRepository extends BaseRepository { $args = [ self::USER_SEED_BONUS_BATCH_KEY, self::USER_SEEDING_LEECHING_TIME_BATCH_KEY, self::TORRENT_SEEDERS_ETC_BATCH_KEY, - $uid, $uid, $torrentId, self::getHashKeySuffix() + $uid, $uid, $torrentId, self::getHashKeySuffix(), self::getCacheKeyLeftTime() ]; $result = $redis->eval(self::getAddRecordLuaScript(), $args, 3); $err = $redis->getLastError(); @@ -82,9 +82,10 @@ class CleanupRepository extends BaseRepository } //update the batch key $newBatch = $batchKey . ":" . self::getHashKeySuffix(); - $redis->set($batchKey, $newBatch, ['ex' => self::KEY_LIFETIME]); + $leftTime = self::getCacheKeyLeftTime(); + $redis->set($batchKey, $newBatch, ['ex' => $leftTime]); $redis->hSetNx($newBatch, -1, 1); - $redis->expire($newBatch, self::KEY_LIFETIME); + $redis->expire($newBatch, $leftTime); $count = 0; @@ -129,7 +130,7 @@ class CleanupRepository extends BaseRepository } /** - * USER_SEED_BONUS, USER_SEEDING_LEECHING_TIME, TORRENT_SEEDERS_ETC, uid, uid, torrentId, timeStr + * USER_SEED_BONUS, USER_SEEDING_LEECHING_TIME, TORRENT_SEEDERS_ETC, uid, uid, torrentId, timeStr, cacheLifeTime * * @return string */ @@ -142,7 +143,7 @@ for k, v in pairs(batchList) do local isBatchKeyNew = false if batchKey == false then batchKey = v .. ":" .. ARGV[4] - redis.call("SET", v, batchKey, "EX", 3600*3) + redis.call("SET", v, batchKey, "EX", ARGV[5]) isBatchKeyNew = true end local hashKey @@ -157,7 +158,7 @@ for k, v in pairs(batchList) do end redis.call("HSETNX", batchKey, hashKey, 1) if isBatchKeyNew then - redis.call("EXPIRE", batchKey, 3600*3) + redis.call("EXPIRE", batchKey, ARGV[5]) end end LUA; @@ -200,4 +201,10 @@ LUA; return floor($base + $offset); } + private static function getCacheKeyLeftTime(): int + { + $value = get_setting("main.autoclean_interval_three"); + return intval($value) + 600; + } + } diff --git a/config/auth.php b/config/auth.php index 265b5be9..0f43040f 100644 --- a/config/auth.php +++ b/config/auth.php @@ -52,6 +52,9 @@ return [ 'nexus-web' => [ 'driver' => 'nexus-web', ], + 'passkey' => [ + 'driver' => 'passkey', + ], ], /* diff --git a/include/constants.php b/include/constants.php index 9240a90b..302aec32 100644 --- a/include/constants.php +++ b/include/constants.php @@ -1,6 +1,6 @@ ['auth:sanctum', 'locale']], function () { Route::resource('messages', \App\Http\Controllers\MessageController::class); Route::get('messages-unread', [\App\Http\Controllers\MessageController::class, 'listUnread']); Route::resource('torrents', \App\Http\Controllers\TorrentController::class); - Route::get("pieces-hash", [\App\Http\Controllers\TorrentController::class, "queryByPiecesHash"])->name("torrent.pieces_hash.query"); Route::resource('comments', \App\Http\Controllers\CommentController::class); Route::resource('peers', \App\Http\Controllers\PeerController::class); Route::resource('files', \App\Http\Controllers\FileController::class); @@ -93,3 +92,8 @@ Route::group(['middleware' => ['auth:sanctum', 'locale']], function () { }); Route::post('login', [\App\Http\Controllers\AuthenticateController::class, 'login']); + + +Route::group(['middleware' => ['auth.nexus:passkey', 'locale']], function () { + Route::get("pieces-hash", [\App\Http\Controllers\TorrentController::class, "queryByPiecesHash"])->name("torrent.pieces_hash.query"); +});