mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-24 03:57:22 +08:00
backend bonus log exclude seeding default
This commit is contained in:
@@ -15,6 +15,7 @@ use App\Models\User;
|
||||
use App\Repositories\SearchBoxRepository;
|
||||
use App\Repositories\TagRepository;
|
||||
use App\Repositories\TorrentRepository;
|
||||
use Elasticsearch\Endpoints\Search;
|
||||
use Filament\Facades\Filament;
|
||||
use Filament\Forms;
|
||||
use Filament\Pages\Actions\Action;
|
||||
@@ -302,7 +303,7 @@ class TorrentResource extends Resource
|
||||
})
|
||||
->deselectRecordsAfterCompletion();
|
||||
}
|
||||
$actions[] = self::getBulkActionChangeCategory();
|
||||
// $actions[] = self::getBulkActionChangeCategory();
|
||||
|
||||
if (user_can('torrent-delete')) {
|
||||
$actions[] = Tables\Actions\DeleteBulkAction::make('bulk-delete')->using(function (Collection $records) {
|
||||
@@ -357,7 +358,7 @@ class TorrentResource extends Resource
|
||||
->helperText(new HtmlString(__('admin.resources.torrent.bulk_action_change_category_section_help')))
|
||||
->options(function() {
|
||||
$rep = new SearchBoxRepository();
|
||||
$list = $rep->listSections(false);
|
||||
$list = $rep->listSections(SearchBox::listAllSectionId(), false);
|
||||
$result = [];
|
||||
foreach ($list as $section) {
|
||||
$result[$section->id] = $section->displaySectionName;
|
||||
@@ -367,12 +368,12 @@ class TorrentResource extends Resource
|
||||
->reactive()
|
||||
->required()
|
||||
,
|
||||
$searchBoxRep->buildSearchBoxFormSchema(SearchBox::getBrowseSearchBox())
|
||||
$searchBoxRep->buildSearchBoxFormSchema(SearchBox::getBrowseSearchBox(), 'section_info')
|
||||
->hidden(function (Forms\Get $get) {
|
||||
return $get('section_id') != SearchBox::getBrowseMode();
|
||||
})
|
||||
,
|
||||
$searchBoxRep->buildSearchBoxFormSchema(SearchBox::getSpecialSearchBox())
|
||||
$searchBoxRep->buildSearchBoxFormSchema(SearchBox::getSpecialSearchBox(), 'section_info')
|
||||
->hidden(function (Forms\Get $get) {
|
||||
return $get('section_id') != SearchBox::getSpecialMode();
|
||||
})
|
||||
@@ -381,8 +382,9 @@ class TorrentResource extends Resource
|
||||
])
|
||||
->action(function (Collection $records, array $data) {
|
||||
$torrentRep = new TorrentRepository();
|
||||
$newSectionId = $data['section_id'];
|
||||
try {
|
||||
$torrentRep->changeCategory($records, $data['section_id'], $data['category_id']);
|
||||
$torrentRep->changeCategory($records, $newSectionId, $data['section_info']['section'][$newSectionId]);
|
||||
} catch (\Exception $exception) {
|
||||
do_log($exception->getMessage(), 'error');
|
||||
}
|
||||
|
||||
@@ -88,6 +88,16 @@ class BonusLogResource extends Resource
|
||||
->options(BonusLogs::listStaticProps(BonusLogs::$businessTypes, 'bonus-log.business_types', true))
|
||||
->label(__('bonus-log.fields.business_type'))
|
||||
,
|
||||
Tables\Filters\Filter::make('exclude_seeding_bonus')
|
||||
->toggle()
|
||||
->label(__('bonus-log.exclude_seeding_bonus'))
|
||||
->query(function (Builder $query, array $data) {
|
||||
if ($data['isActive']) {
|
||||
$query->whereNotIn("business_type", BonusLogs::$businessTypeBonus);
|
||||
}
|
||||
})
|
||||
->default()
|
||||
,
|
||||
])
|
||||
->actions([
|
||||
// Tables\Actions\EditAction::make(),
|
||||
|
||||
@@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Auth\Permission;
|
||||
use App\Http\Resources\SearchBoxResource;
|
||||
use App\Http\Resources\TorrentResource;
|
||||
use App\Models\SearchBox;
|
||||
use App\Repositories\SearchBoxRepository;
|
||||
use App\Repositories\UploadRepository;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -22,7 +24,7 @@ class UploadController extends Controller
|
||||
|
||||
public function sections(Request $request)
|
||||
{
|
||||
$sections = $this->searchBoxRepository->listSections();
|
||||
$sections = $this->searchBoxRepository->listSections(SearchBox::listAuthorizedSectionId());
|
||||
$resource = SearchBoxResource::collection($sections);
|
||||
return $this->success($resource);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class BookmarkResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'torrent_id' => $this->torrentid,
|
||||
'user_id' => $this->userid,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -96,6 +96,14 @@ class BonusLogs extends NexusModel
|
||||
self::BUSINESS_TYPE_SEEDING_MEDAL_ADDITION => ['text' => 'Seeding medal addition'],
|
||||
];
|
||||
|
||||
public static array $businessTypeBonus = [
|
||||
self::BUSINESS_TYPE_SEEDING_BASIC,
|
||||
self::BUSINESS_TYPE_SEEDING_DONOR_ADDITION,
|
||||
self::BUSINESS_TYPE_SEEDING_OFFICIAL_ADDITION,
|
||||
self::BUSINESS_TYPE_SEEDING_HAREM_ADDITION,
|
||||
self::BUSINESS_TYPE_SEEDING_MEDAL_ADDITION
|
||||
];
|
||||
|
||||
public function getBusinessTypeTextAttribute()
|
||||
{
|
||||
return nexus_trans('bonus-log.business_types.' . $this->business_type);
|
||||
|
||||
@@ -113,6 +113,10 @@ class HitAndRun extends NexusModel
|
||||
do_log(sprintf('[INVALID_CATEGORY], Torrent: %s', $this->torrent_id), 'error');
|
||||
return '---';
|
||||
}
|
||||
if (!$this->snatch) {
|
||||
do_log("hit and run: {$this->id} no snatch", 'warning');
|
||||
return '---';
|
||||
}
|
||||
$seedTimeMinimum = HitAndRun::getConfig('seed_time_minimum', $searchBoxId);
|
||||
$diffInSeconds = 3600 * $seedTimeMinimum - $this->snatch->seedtime;
|
||||
return mkprettytime($diffInSeconds);
|
||||
|
||||
@@ -158,8 +158,8 @@ class SearchBox extends NexusModel
|
||||
}
|
||||
$table = self::$taxonomies[$torrentField]['table'];
|
||||
return NexusDB::table($table)->where(function (Builder $query) use ($searchBox) {
|
||||
return $query->where('mode', $searchBox->id)->orWhere('mode', 0);
|
||||
})->orderBy('sort_index')->orderBy('id')->get();
|
||||
return $query->whereIn('mode', [$searchBox->id, 0]);
|
||||
})->orderBy('sort_index', 'desc')->orderBy('id', 'desc')->get();
|
||||
}
|
||||
|
||||
public static function listModeOptions(): array
|
||||
@@ -301,8 +301,8 @@ class SearchBox extends NexusModel
|
||||
$this->setRelation(
|
||||
$relationName,
|
||||
$modelName::query()->whereIn('mode', [$this->getKey(), 0])
|
||||
->orderBy('sort_index')
|
||||
->orderBy('id')
|
||||
->orderBy('sort_index', 'desc')
|
||||
->orderBy('id', 'desc')
|
||||
->get()
|
||||
);
|
||||
}
|
||||
@@ -367,4 +367,22 @@ class SearchBox extends NexusModel
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function listAuthorizedSectionId(): array
|
||||
{
|
||||
$modeIds = [self::getBrowseMode()];
|
||||
if (self::isSpecialEnabled() && Permission::canViewSpecialSection()) {
|
||||
$modeIds[] = self::getSpecialMode();
|
||||
}
|
||||
return $modeIds;
|
||||
}
|
||||
|
||||
public static function listAllSectionId(): array
|
||||
{
|
||||
$modeIds = [self::getBrowseMode()];
|
||||
if (self::isSpecialEnabled()) {
|
||||
$modeIds[] = self::getSpecialMode();
|
||||
}
|
||||
return $modeIds;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -242,13 +242,9 @@ class SearchBoxRepository extends BaseRepository
|
||||
return Category::query()->whereIn('id', $idArr)->delete();
|
||||
}
|
||||
|
||||
public function listSections($withCategoryAndTags = true)
|
||||
public function listSections($id, $withCategoryAndTags = true)
|
||||
{
|
||||
$modeIds = [SearchBox::getBrowseMode()];
|
||||
if (SearchBox::isSpecialEnabled() && Permission::canUploadToSpecialSection()) {
|
||||
$modeIds[] = SearchBox::getSpecialMode();
|
||||
}
|
||||
$searchBoxList = SearchBox::query()->with($withCategoryAndTags ? ['categories'] : [])->find($modeIds);
|
||||
$searchBoxList = SearchBox::query()->with($withCategoryAndTags ? ['categories'] : [])->find($id);
|
||||
if ($withCategoryAndTags) {
|
||||
foreach ($searchBoxList as $searchBox) {
|
||||
if ($searchBox->showsubcat) {
|
||||
@@ -260,7 +256,7 @@ class SearchBoxRepository extends BaseRepository
|
||||
return $searchBoxList;
|
||||
}
|
||||
|
||||
public function buildSearchBoxFormSchema(SearchBox $searchBox, string $namePrefix = ""): Forms\Components\Section
|
||||
public function buildSearchBoxFormSchema(SearchBox $searchBox, string $namePrefix): Forms\Components\Section
|
||||
{
|
||||
$lang = get_langfolder_cookie();
|
||||
$heading = $searchBox->section_name[$lang] ?? nexus_trans('searchbox.sections.browse');
|
||||
|
||||
@@ -1113,16 +1113,55 @@ HTML;
|
||||
}
|
||||
}
|
||||
|
||||
public function changeCategory(Collection $torrents, int $sectionId, int $categoryId): void
|
||||
public function changeCategory(Collection $torrents, int $sectionId, array $specificSubCategoryAndTags): void
|
||||
{
|
||||
assert_has_permission(Permission::canManageTorrent());
|
||||
$searchBox = SearchBox::query()->findOrFail($sectionId);
|
||||
$category = $searchBox->categories()->findOrFail($categoryId);
|
||||
$torrentIdArr = $torrents->pluck('id')->toArray();
|
||||
if (empty($torrentIdArr)) {
|
||||
do_log("torrents is empty", 'warn');
|
||||
return;
|
||||
}
|
||||
$torrentIdStr = implode(',', $torrentIdArr);
|
||||
do_log("torrentIdStr: $torrentIdStr, sectionId: $sectionId");
|
||||
$searchBoxRep = new SearchBoxRepository();
|
||||
$sections = $searchBoxRep->listSections(SearchBox::listAllSectionId(), true)->keyBy('id');
|
||||
if (!$sections->has($sectionId)) {
|
||||
throw new NexusException(nexus_trans('upload.invalid_section'));
|
||||
}
|
||||
/**
|
||||
* @var $section SearchBox
|
||||
*/
|
||||
$section = $sections->get($sectionId);
|
||||
$validCategoryIdArr = $section->categories->pluck('id')->toArray();
|
||||
if (!empty($specificSubCategoryAndTags['category']) && !in_array($specificSubCategoryAndTags['category'], $validCategoryIdArr)) {
|
||||
throw new NexusException(nexus_trans('upload.invalid_category'));
|
||||
}
|
||||
$baseUpdateQuery = Torrent::query()->whereIn('id', $torrentIdArr);
|
||||
$updateCategoryQuery = $baseUpdateQuery->clone();
|
||||
if (!empty($validCategoryId)) {
|
||||
$updateCategoryQuery->whereNotIn('category', $validCategoryIdArr);
|
||||
}
|
||||
$updateCategoryResult = $updateCategoryQuery->update(['category' => 0]);
|
||||
do_log(sprintf("update category = 0 when category not in: %s, result: %s", implode(', ', $validCategoryIdArr), $updateCategoryResult));
|
||||
|
||||
foreach (SearchBox::$taxonomies as $name => $info) {
|
||||
$relationName = "taxonomy_{$name}";
|
||||
$relation = $section->{$relationName};
|
||||
if (empty($specificSubCategoryAndTags[$name])) {
|
||||
continue;
|
||||
}
|
||||
//有指定,看是否有效
|
||||
if (!$relation) {
|
||||
do_log("searchBox: {$section->id} no relation of $name");
|
||||
throw new NexusException(nexus_trans('upload.not_supported_sub_category_field', ['field' => $name]));
|
||||
}
|
||||
$validIdArr = $relation->pluck('id')->toArray();
|
||||
if (!in_array($specificSubCategoryAndTags[$name], $validIdArr)) {
|
||||
do_log("taxonomy {$name}, specific: {$specificSubCategoryAndTags[$name]} not in validIdArr: " . implode(', ', $validIdArr));
|
||||
throw new NexusException(nexus_trans('upload.not_supported_sub_category_field', ['field' => $name]));
|
||||
}
|
||||
|
||||
}
|
||||
$operatorId = get_user_id();
|
||||
$siteLogArr = [];
|
||||
foreach ($torrents as $torrent) {
|
||||
@@ -1139,7 +1178,7 @@ HTML;
|
||||
foreach ($torrents as $torrent) {
|
||||
fire_event(ModelEventEnum::TORRENT_UPDATED, $torrent);
|
||||
}
|
||||
do_log("success change torrent category to $categoryId, torrent count:" . $torrents->count());
|
||||
do_log("success change to section $sectionId, torrent count:" . $torrents->count());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -440,7 +440,7 @@ class UploadRepository extends BaseRepository
|
||||
private function getSubCategoriesAndTags(Request $request, Category $category): array
|
||||
{
|
||||
$searchBoxRep = new SearchBoxRepository();
|
||||
$sections = $searchBoxRep->listSections()->keyBy('id');
|
||||
$sections = $searchBoxRep->listSections(SearchBox::listAllSectionId())->keyBy('id');
|
||||
if (!$sections->has($category->mode)) {
|
||||
throw new NexusException(nexus_trans('upload.invalid_section'));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user