mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-23 19:37:23 +08:00
continue
This commit is contained in:
@@ -16,7 +16,7 @@ class AuthenticateRepository extends BaseRepository
|
||||
if (!$user || md5($user->secret . $password . $user->secret) != $user->passhash) {
|
||||
throw new \InvalidArgumentException('Username or password invalid.');
|
||||
}
|
||||
if (!$user->canAccessAdmin()) {
|
||||
if (IS_PLATFORM_ADMIN && !$user->canAccessAdmin()) {
|
||||
throw new UnauthorizedException('Unauthorized!');
|
||||
}
|
||||
$tokenName = __METHOD__ . __LINE__;
|
||||
|
||||
@@ -6,7 +6,9 @@ use App\Models\HitAndRun;
|
||||
use App\Models\Setting;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Query\Expression;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Nexus\Database\NexusDB;
|
||||
|
||||
class BonusRepository extends BaseRepository
|
||||
@@ -65,4 +67,25 @@ class BonusRepository extends BaseRepository
|
||||
return $result;
|
||||
|
||||
}
|
||||
|
||||
public function initSeedPoints(): int
|
||||
{
|
||||
$size = 10000;
|
||||
$tableName = (new User())->getTable();
|
||||
$result = 0;
|
||||
do {
|
||||
$affectedRows = DB::table($tableName)
|
||||
->whereNull('seed_points')
|
||||
->limit($size)
|
||||
->update([
|
||||
'seed_points' => DB::raw('seed_points = seedbonus')
|
||||
]);
|
||||
$result += $affectedRows;
|
||||
do_log("affectedRows: $affectedRows, query: " . last_query());
|
||||
} while ($affectedRows > 0);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories;
|
||||
|
||||
use App\Exceptions\NexusException;
|
||||
use App\Models\Torrent;
|
||||
use App\Models\User;
|
||||
|
||||
class BookmarkRepository extends BaseRepository
|
||||
{
|
||||
public function add(User $user, $torrentId)
|
||||
{
|
||||
$torrent = Torrent::query()->findOrFail($torrentId);
|
||||
$torrent->checkIsNormal();
|
||||
$exists = $user->bookmarks()->where('torrentid', $torrentId)->exists();
|
||||
if ($exists) {
|
||||
throw new NexusException("torrent: $torrentId already bookmarked.");
|
||||
}
|
||||
$result = $user->bookmarks()->create(['torrentid' => $torrentId]);
|
||||
return $result;
|
||||
}
|
||||
|
||||
public function remove(User $user, $torrentId)
|
||||
{
|
||||
$torrent = Torrent::query()->findOrFail($torrentId);
|
||||
$exists = $user->bookmarks()->where('torrentid', $torrentId)->exists();
|
||||
if (!$exists) {
|
||||
throw new NexusException("torrent: $torrentId has not been bookmarked.");
|
||||
}
|
||||
$result = $user->bookmarks()->where('torrentid', $torrentId)->delete();
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ class TorrentRepository extends BaseRepository
|
||||
->paginate();
|
||||
foreach ($snatches as &$snatch) {
|
||||
$snatch->upload_text = sprintf('%s@%s', mksize($snatch->uploaded), $this->getSnatchUploadSpeed($snatch));
|
||||
$snatch->download_text = sprintf('%s@%s', mksize($snatch->uploaded), $this->getSnatchDownloadSpeed($snatch));
|
||||
$snatch->download_text = sprintf('%s@%s', mksize($snatch->downloaded), $this->getSnatchDownloadSpeed($snatch));
|
||||
$snatch->share_ratio = $this->getShareRatio($snatch);
|
||||
$snatch->seed_time = mkprettytime($snatch->seedtime);
|
||||
$snatch->leech_time = mkprettytime($snatch->leechtime);
|
||||
@@ -379,5 +379,12 @@ class TorrentRepository extends BaseRepository
|
||||
|
||||
}
|
||||
|
||||
public function getStickyStatus($torrent)
|
||||
{
|
||||
if (!$torrent instanceof Torrent) {
|
||||
$torrent = Torrent::query()->findOrFail((int)$torrent, ['id', 'pos_state']);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user