This commit is contained in:
xiaomlove
2021-12-14 16:22:03 +08:00
parent 19d7e048df
commit 3fa8fd19c0
29 changed files with 319 additions and 45 deletions
+1 -1
View File
@@ -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__;
+23
View File
@@ -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;
}
}
+33
View File
@@ -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;
}
}
+8 -1
View File
@@ -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']);
}
}
}