Skip to content

Commit

Permalink
Merge pull request #4219 from HDInnovations/8.x.x
Browse files Browse the repository at this point in the history
(Release) v8.3.1
  • Loading branch information
HDVinnie authored Oct 11, 2024
2 parents ca36a92 + 2b94479 commit 3514c68
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 110 deletions.
70 changes: 35 additions & 35 deletions app/Http/Controllers/API/TorrentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,8 @@ public function filter(Request $request): TorrentsResource|\Illuminate\Http\Json
$queryString = http_build_query($queryParams);
$cacheKey = $url.'?'.$queryString;

/** @phpstan-ignore argument.templateType (phpstan is unable to resolve type because it's returning a phpstan-ignored line) */
$torrents = cache()->remember($cacheKey, 300, function () use ($request, $isSqlAllowed) {
/** @phpstan-ignore method.unresolvableReturnType (phpstan is unable to resolve type because it's returning a phpstan-ignored line) */
[$torrents, $hasMore] = cache()->remember($cacheKey, 300, function () use ($request, $isSqlAllowed) {
$eagerLoads = fn (Builder $query) => $query
->with(['user:id,username', 'category', 'type', 'resolution', 'distributor', 'region', 'files'])
->select('*')
Expand Down Expand Up @@ -580,6 +580,8 @@ public function filter(Request $request): TorrentsResource|\Illuminate\Http\Json

// See app/Traits/TorrentMeta.php
$this->scopeMeta($torrents);

$hasMore = $torrents->nextCursor() !== null;
} else {
$paginator = Torrent::search(
$request->filled('name') ? $request->string('name')->toString() : '',
Expand All @@ -598,6 +600,8 @@ function (Indexes $meilisearch, string $query, array $options) use ($request, $f
->query($eagerLoads)
->simplePaginateRaw(min($request->input('perPage') ?? $this->perPage, 100));

$hasMore = $paginator->hasMorePages();

/** @phpstan-ignore method.notFound (this method exists at time of writing) */
$results = $paginator->getCollection();
$torrents = collect();
Expand Down Expand Up @@ -654,43 +658,39 @@ function (Indexes $meilisearch, string $query, array $options) use ($request, $f
$torrents = $paginator->setCollection(collect($torrents));
}

return $torrents;
return [$torrents, $hasMore];
});

if ($isSqlAllowed) {
if ($torrents !== null) {
return new TorrentsResource($torrents);
}
} elseif ($torrents->isNotEmpty()) {
$page = $request->integer('page') ?: 1;
$perPage = min(100, $request->integer('perPage') ?: 25);

// Auth keys must not be cached
$torrents->through(function ($torrent) {
$torrent['attributes']['download_link'] = route('torrent.download.rsskey', ['id' => $torrent['id'], 'rsskey' => auth('api')->user()->rsskey]);
$torrent['attributes']['magnet_link'] = config('torrent.magnet') ? 'magnet:?dn='.$torrent['attributes']['name'].'&xt=urn:btih:'.$torrent['attributes']['info_hash'].'&as='.route('torrent.download.rsskey', ['id' => $torrent['id'], 'rsskey' => auth('api')->user()->rsskey]).'&tr='.route('announce', ['passkey' => auth('api')->user()->passkey]).'&xl='.$torrent['attributes']['size'] : null;

return $torrent;
});

return response()->json([
'data' => $torrents->items(),
'links' => [
'first' => $request->fullUrlWithoutQuery(['page' => 1]),
'last' => null,
'prev' => $page === 1 ? null : $request->fullUrlWithQuery(['page' => $page - 1]),
'next' => $request->fullUrlWithQuery(['page' => $page + 1]),
'self' => $request->fullUrl(),
],
'meta' => [
'current_page' => $page,
'per_page' => $perPage,
'from' => ($page - 1) * $perPage + 1,
'to' => ($page - 1) * $perPage + \count($torrents->items()),
]
]);
return new TorrentsResource($torrents);
}

return $this->sendResponse('404', 'No Torrents Found');
$page = $request->integer('page') ?: 1;
$perPage = min(100, $request->integer('perPage') ?: 25);

// Auth keys must not be cached
$torrents->through(function ($torrent) {
$torrent['attributes']['download_link'] = route('torrent.download.rsskey', ['id' => $torrent['id'], 'rsskey' => auth('api')->user()->rsskey]);
$torrent['attributes']['magnet_link'] = config('torrent.magnet') ? 'magnet:?dn='.$torrent['attributes']['name'].'&xt=urn:btih:'.$torrent['attributes']['info_hash'].'&as='.route('torrent.download.rsskey', ['id' => $torrent['id'], 'rsskey' => auth('api')->user()->rsskey]).'&tr='.route('announce', ['passkey' => auth('api')->user()->passkey]).'&xl='.$torrent['attributes']['size'] : null;

return $torrent;
});

return response()->json([
'data' => $torrents->items(),
'links' => [
'first' => $request->fullUrlWithoutQuery(['page' => 1]),
'last' => null,
'prev' => $page === 1 ? null : $request->fullUrlWithQuery(['page' => $page - 1]),
'next' => $hasMore ? $request->fullUrlWithQuery(['page' => $page + 1]) : null,
'self' => $request->fullUrl(),
],
'meta' => [
'current_page' => $page,
'per_page' => $perPage,
'from' => ($page - 1) * $perPage + 1,
'to' => ($page - 1) * $perPage + \count($torrents->items()),
]
]);
}
}
38 changes: 5 additions & 33 deletions app/Http/Controllers/RssController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
use App\Models\User;
use Illuminate\Http\Request;
use Exception;
use Illuminate\Contracts\Database\Eloquent\Builder;
use Meilisearch\Endpoints\Indexes;

/**
Expand Down Expand Up @@ -182,9 +181,10 @@ public function show(int $id, string $rsskey): \Illuminate\Http\Response
dead: (bool) ($search->dead ?? false),
);

$torrents = Torrent::search(
$results = Torrent::search(
$search->search ?? '',
function (Indexes $meilisearch, string $query, array $options) use ($filters) {
$options['limit'] = 50;
$options['sort'] = [
'bumped_at:desc',
];
Expand All @@ -196,37 +196,9 @@ function (Indexes $meilisearch, string $query, array $options) use ($filters) {
return $results;
}
)
->query(
fn (Builder $query) => $query->
select([
'name',
'id',
'category_id',
'type_id',
'resolution_id',
'size',
'created_at',
'seeders',
'leechers',
'times_completed',
'user_id',
'anon',
'imdb',
'tmdb',
'tvdb',
'mal',
'internal',
])
->with([
'user:id,username,rsskey',
'category:id,name,movie_meta,tv_meta',
'type:id,name',
'resolution:id,name'
])
)
->paginate(50);

return $torrents;
->raw();

return $results['hits'] ?? [];
});

return response()->view('rss.show', [
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Staff/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function index(Request $request): \Illuminate\Contracts\View\Factory|\Ill
->selectRaw('sum(seeder = 0 AND active = 1) as leechers')
->selectRaw('sum(seeder = 1 AND active = 1) as seeders')
->first()),
'unsolvedReportsCount' => DB::table('reports')->where('solved', '=', false)->count(),
'unsolvedReportsCount' => DB::table('reports')->whereNull('snoozed_until')->where('solved', '=', false)->count(),
'pendingApplicationsCount' => DB::table('applications')->where('status', '=', 0)->count(),
'certificate' => $certificate,
'uptime' => $systemInformation->uptime(),
Expand Down
17 changes: 17 additions & 0 deletions app/Http/Livewire/UserTorrents.php
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,21 @@ final public function render(): \Illuminate\Contracts\View\Factory|\Illuminate\C
'histories' => $this->history,
]);
}

/**
* Update History Immune.
*/
final public function updateImmune(int $torrentId, bool $immune): void
{
abort_unless(auth()->user()->group->is_modo, 403);

$this->user
->history()
->where('torrent_id', '=', $torrentId)
->update([
'immune' => $immune,
]);

$this->dispatch('success', type: 'success', message: 'Immunity has successfully been updated!');
}
}
4 changes: 2 additions & 2 deletions config/unit3d.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
|
*/

'powered-by' => 'Powered By UNIT3D Community Edition v8.3.0',
'powered-by' => 'Powered By UNIT3D Community Edition v8.3.1',

/*
|--------------------------------------------------------------------------
Expand All @@ -45,7 +45,7 @@
|
*/

'version' => 'v8.3.0',
'version' => 'v8.3.1',

/*
|--------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

declare(strict_types=1);

/**
* NOTICE OF LICENSE.
*
* UNIT3D Community Edition is open-sourced software licensed under the GNU Affero General Public License v3.0
* The details is bundled with this project in the file LICENSE.txt.
*
* @project UNIT3D Community Edition
*
* @author HDVinnie <[email protected]>
* @license https://www.gnu.org/licenses/agpl-3.0.en.html/ GNU Affero General Public License v3.0
*/

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class () extends Migration {
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('torrents', function (Blueprint $table): void {
$table->longText('mediainfo')->nullable()->change();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down(): void
{
Schema::table('torrents', function (Blueprint $table): void {
$table->text('mediainfo')->nullable()->change();
});
}
};
2 changes: 2 additions & 0 deletions lang/es/ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
'note-destroy-success' => '¡Nota del staff eliminada con éxito!',
'opened-by' => 'Abierto por:',
'priority' => 'Prioridad',
'reopen' => 'Reabrir',
'reopen-success' => 'Su solicitud de asistencia se ha reabierto correctamente',
'reset' => 'Restablecer',
'staff-notes' => 'Notas del staff',
'subject' => 'Asunto',
Expand Down
37 changes: 35 additions & 2 deletions resources/views/livewire/user-torrents.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class="user-torrents__status-header"
</thead>
<tbody>
@foreach ($histories as $history)
<tr>
<tr x-data="userHistory" data-history-id="{{ $history->torrent_id }}">
<td>
<a
class="user-torrents__name"
Expand Down Expand Up @@ -664,15 +664,25 @@ class="{{ config('other.font-awesome') }} fa-times text-red"
@endif
</td>
<td class="user-torrents__immune">
@if ($history->immune == 1)
@if ($history->immune)
<i
class="{{ config('other.font-awesome') }} fa-check text-green"
title="Immune"
@if (auth()->user()->group->is_modo)
x-on:click.prevent="updateImmune(false)"
data-b64-deletion-message="{{ base64_encode('Are you sure you want to set this history record to not immune: ' . $history->name . '?') }}"
style="cursor: pointer"
@endif
></i>
@else
<i
class="{{ config('other.font-awesome') }} fa-times text-red"
title="Not immune"
@if (auth()->user()->group->is_modo)
x-on:click.prevent="updateImmune(true)"
data-b64-deletion-message="{{ base64_encode('Are you sure you want to set this history record to immune: ' . $history->name . '?') }}"
style="cursor: pointer"
@endif
></i>
@endif
</td>
Expand Down Expand Up @@ -744,5 +754,28 @@ function ternaryCheckbox() {
},
};
}
document.addEventListener('alpine:init', () => {
Alpine.data('userHistory', () => ({
updateImmune(immune) {
this.confirmAction(() =>
this.$wire.updateImmune(this.$root.dataset.historyId, immune),
);
},
confirmAction(onConfirm) {
Swal.fire({
title: 'Are you sure?',
text: atob(this.$el.dataset.b64DeletionMessage),
icon: 'warning',
showConfirmButton: true,
showCancelButton: true,
}).then((result) => {
if (result.isConfirmed) {
onConfirm();
}
});
},
}));
});
</script>
</div>
17 changes: 17 additions & 0 deletions resources/views/page/staff.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,20 @@ class="user-card"
</section>
@endforeach
@endsection

@section('sidebar')
<section class="panelV2">
<h2 class="panel__heading">{{ __('common.info') }}</h2>
<div class="panel__body">Please contact staff via the helpdesk for account support.</div>
<div class="panel__body">
<p class="form__group form__group--horizontal">
<a
class="form__button form__button--filled form__button--centered"
href="{{ route('tickets.index') }}"
>
Open Helpdesk
</a>
</p>
</div>
</section>
@endsection
12 changes: 11 additions & 1 deletion resources/views/partials/top_nav.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ class="progress-bar"
<li>
<a href="https://polar.sh/HDInnovations">
<i class="fas fa-handshake"></i>
Support UNIT3D Development (polar.sh)
Support UNIT3D Development
</a>
</li>
</ul>
Expand Down Expand Up @@ -394,6 +394,16 @@ class="top-nav--right__icon-link"
title="{{ __('staff.staff-dashboard') }}"
>
<i class="{{ config('other.font-awesome') }} fa-cogs"></i>
@php
$unsolvedReportsCount = DB::table('reports')
->whereNull('snoozed_until')
->where('solved', '=', false)
->count()
@endphp

@if ($unsolvedReportsCount > 0)
<x-animation.notification />
@endif
</a>
</li>
@endif
Expand Down
Loading

0 comments on commit 3514c68

Please sign in to comment.