mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-14 20:40:49 +08:00
continue
This commit is contained in:
73
app/Http/Controllers/BookmarkController.php
Normal file
73
app/Http/Controllers/BookmarkController.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Resources\TorrentResource;
|
||||
use App\Models\Torrent;
|
||||
use App\Repositories\BookmarkRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class BookmarkController extends Controller
|
||||
{
|
||||
private $repository;
|
||||
|
||||
public function __construct(BookmarkRepository $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'torrent_id' => 'required|integer',
|
||||
]);
|
||||
$result = $this->repository->add(Auth::user(), $request->torrent_id);
|
||||
return $this->success($result->toArray(), nexus_trans('bookmark.actions.store_success'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
$result = $this->repository->remove(Auth::user(), $id);
|
||||
return $this->success($result, nexus_trans('bookmark.actions.delete_success'));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use App\Http\Resources\TorrentResource;
|
||||
use App\Models\Torrent;
|
||||
use App\Repositories\TorrentRepository;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class TorrentController extends Controller
|
||||
{
|
||||
@@ -52,10 +53,13 @@ class TorrentController extends Controller
|
||||
|
||||
$result = Torrent::query()->with($with)->withCount(['peers', 'thank_users'])->visible()->findOrFail($id);
|
||||
|
||||
$isBookmarked = Auth::user()->bookmarks()->where('torrentid', $id)->exists();
|
||||
|
||||
$resource = new TorrentResource($result);
|
||||
$resource->additional([
|
||||
'page_title' => nexus_trans('torrent.show.page_title'),
|
||||
'field_labels' => Torrent::getFieldLabels(),
|
||||
'is_bookmarked' => (int)$isBookmarked,
|
||||
]);
|
||||
|
||||
return $this->success($resource);
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\UnauthorizedException;
|
||||
|
||||
class Platform
|
||||
{
|
||||
|
||||
11
app/Models/Bookmark.php
Normal file
11
app/Models/Bookmark.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
|
||||
class Bookmark extends NexusModel
|
||||
{
|
||||
protected $table = 'bookmarks';
|
||||
|
||||
protected $fillable = ['userid', 'torrentid'];
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class Exam extends NexusModel
|
||||
self::INDEX_UPLOADED => ['name' => 'Uploaded', 'unit' => 'GB', 'source_user_field' => 'uploaded'],
|
||||
self::INDEX_SEED_TIME_AVERAGE => ['name' => 'Seed time average', 'unit' => 'Hour', 'source_user_field' => 'seedtime'],
|
||||
self::INDEX_DOWNLOADED => ['name' => 'Downloaded', 'unit' => 'GB', 'source_user_field' => 'downloaded'],
|
||||
self::INDEX_SEED_BONUS => ['name' => 'Seed bonus', 'unit' => '', 'source_user_field' => 'seedbonus'],
|
||||
self::INDEX_SEED_BONUS => ['name' => 'Seed bonus', 'unit' => '', 'source_user_field' => 'seed_points'],
|
||||
];
|
||||
|
||||
const FILTER_USER_CLASS = 'classes';
|
||||
|
||||
@@ -86,7 +86,7 @@ class Torrent extends NexusModel
|
||||
|
||||
public static function getFieldLabels(): array
|
||||
{
|
||||
$fields = ['comments', 'times_completed', 'peers_count', 'thank_users_count', 'numfiles'];
|
||||
$fields = ['comments', 'times_completed', 'peers_count', 'thank_users_count', 'numfiles', 'bookmark_yes', 'bookmark_no'];
|
||||
$result = [];
|
||||
foreach($fields as $field) {
|
||||
$result[$field] = nexus_trans("torrent.show.{$field}_label");
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
namespace App\Models;
|
||||
|
||||
use App\Http\Middleware\Locale;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
@@ -41,15 +42,15 @@ class User extends Authenticatable
|
||||
|
||||
public static $classes = [
|
||||
self::CLASS_PEASANT => ['text' => 'Peasant'],
|
||||
self::CLASS_USER => ['text' => 'User'],
|
||||
self::CLASS_POWER_USER => ['text' => 'Power User'],
|
||||
self::CLASS_ELITE_USER => ['text' => 'Elite User'],
|
||||
self::CLASS_CRAZY_USER => ['text' => 'Crazy User'],
|
||||
self::CLASS_INSANE_USER => ['text' => 'Insane User'],
|
||||
self::CLASS_VETERAN_USER => ['text' => 'Veteran User'],
|
||||
self::CLASS_EXTREME_USER => ['text' => 'Extreme User'],
|
||||
self::CLASS_ULTIMATE_USER => ['text' => 'Ultimate User'],
|
||||
self::CLASS_NEXUS_MASTER => ['text' => 'Nexus Master'],
|
||||
self::CLASS_USER => ['text' => 'User', 'min_seed_points' => 0],
|
||||
self::CLASS_POWER_USER => ['text' => 'Power User', 'min_seed_points' => 40000],
|
||||
self::CLASS_ELITE_USER => ['text' => 'Elite User', 'min_seed_points' => 80000],
|
||||
self::CLASS_CRAZY_USER => ['text' => 'Crazy User', 'min_seed_points' => 150000],
|
||||
self::CLASS_INSANE_USER => ['text' => 'Insane User', 'min_seed_points' => 250000],
|
||||
self::CLASS_VETERAN_USER => ['text' => 'Veteran User', 'min_seed_points' => 400000],
|
||||
self::CLASS_EXTREME_USER => ['text' => 'Extreme User', 'min_seed_points' => 600000],
|
||||
self::CLASS_ULTIMATE_USER => ['text' => 'Ultimate User', 'min_seed_points' => 800000],
|
||||
self::CLASS_NEXUS_MASTER => ['text' => 'Nexus Master', 'min_seed_points' => 1000000],
|
||||
self::CLASS_VIP => ['text' => 'Vip'],
|
||||
self::CLASS_RETIREE => ['text' => 'Retiree'],
|
||||
self::CLASS_UPLOADER => ['text' => 'Uploader'],
|
||||
@@ -161,6 +162,20 @@ class User extends Authenticatable
|
||||
return 'en';
|
||||
}
|
||||
|
||||
public static function getMinSeedPoints($class)
|
||||
{
|
||||
$setting = Setting::get("account.{$class}_min_seed_points");
|
||||
if (is_numeric($setting)) {
|
||||
return $setting;
|
||||
}
|
||||
return self::$classes[$class]['min_seed_points'] ?? false;
|
||||
}
|
||||
|
||||
public function scopeNormal(Builder $query): Builder
|
||||
{
|
||||
return $query->where('status', self::STATUS_CONFIRMED)->where('enabled', self::ENABLED_YES);
|
||||
}
|
||||
|
||||
|
||||
public function exams()
|
||||
{
|
||||
@@ -215,6 +230,11 @@ class User extends Authenticatable
|
||||
return $this->hasMany(Torrent::class, 'owner');
|
||||
}
|
||||
|
||||
public function bookmarks(): \Illuminate\Database\Eloquent\Relations\HasMany
|
||||
{
|
||||
return $this->hasMany(Bookmark::class, 'userid');
|
||||
}
|
||||
|
||||
|
||||
public function peers_torrents()
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
33
app/Repositories/BookmarkRepository.php
Normal file
33
app/Repositories/BookmarkRepository.php
Normal 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;
|
||||
}
|
||||
}
|
||||
@@ -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