diff --git a/app/Filament/Resources/Torrent/TorrentDenyReasonResource.php b/app/Filament/Resources/Torrent/TorrentDenyReasonResource.php new file mode 100644 index 00000000..560addef --- /dev/null +++ b/app/Filament/Resources/Torrent/TorrentDenyReasonResource.php @@ -0,0 +1,73 @@ +schema([ + Forms\Components\TextInput::make('name')->required()->label(__('label.name')), + Forms\Components\TextInput::make('priority')->integer()->label(__('label.priority'))->default(0), + ])->columns(1); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + Tables\Columns\TextColumn::make('id'), + Tables\Columns\TextColumn::make('name')->label(__('label.name')), + Tables\Columns\TextColumn::make('priority')->label(__('label.priority'))->sortable(), + Tables\Columns\TextColumn::make('created_at')->label(__('label.created_at')), + ]) + ->defaultSort('priority', 'desc') + ->filters([ + // + ]) + ->actions([ + Tables\Actions\EditAction::make(), + Tables\Actions\DeleteAction::make(), + ]) + ->bulkActions([ + Tables\Actions\DeleteBulkAction::make(), + ]); + } + + public static function getPages(): array + { + return [ + 'index' => Pages\ManageTorrentDenyReasons::route('/'), + ]; + } +} diff --git a/app/Filament/Resources/Torrent/TorrentDenyReasonResource/Pages/ManageTorrentDenyReasons.php b/app/Filament/Resources/Torrent/TorrentDenyReasonResource/Pages/ManageTorrentDenyReasons.php new file mode 100644 index 00000000..ce9d2af4 --- /dev/null +++ b/app/Filament/Resources/Torrent/TorrentDenyReasonResource/Pages/ManageTorrentDenyReasons.php @@ -0,0 +1,21 @@ +success($result); } + + public function approvalPage(Request $request) + { + $request->validate(['torrent_id' => 'required']); + $torrentId = $request->torrent_id; + $torrent = Torrent::query()->findOrFail($torrentId, Torrent::$commentFields); + $denyReasons = TorrentDenyReason::query()->orderBy('priority', 'desc')->get(); + return view('torrent/approval', compact('torrent', 'denyReasons')); + } + + public function approvalLogs(Request $request) + { + $request->validate(['torrent_id' => 'required']); + $torrentId = $request->torrent_id; + $actionTypes = [ + TorrentOperationLog::ACTION_TYPE_APPROVAL_NONE, + TorrentOperationLog::ACTION_TYPE_APPROVAL_ALLOW, + TorrentOperationLog::ACTION_TYPE_APPROVAL_DENY, + ]; + $records = TorrentOperationLog::query() + ->with(['user']) + ->where('torrent_id', $torrentId) + ->whereIn('action_type', $actionTypes) + ->orderBy('id', 'desc') + ->paginate($request->limit); + + $resource = TorrentOperationLogResource::collection($records); + + return $this->success($resource); + } + + public function approval(Request $request) + { + $request->validate([ + 'torrent_id' => 'required', + 'approval_status' => 'required', + ]); + $params = $request->all(); + $this->repository->approval(Auth::user(), $params); + return $this->success($params); + } } diff --git a/app/Http/Resources/TorrentOperationLogResource.php b/app/Http/Resources/TorrentOperationLogResource.php new file mode 100644 index 00000000..6efd2e07 --- /dev/null +++ b/app/Http/Resources/TorrentOperationLogResource.php @@ -0,0 +1,27 @@ + $this->id, + 'action_type' => $this->action_type, + 'action_type_text' => $this->actionTypeText, + 'uid' => $this->uid, + 'username' => $this->user->username, + 'comment' => $this->comment, + 'created_at' => format_datetime($this->created_at) + ]; + } +} diff --git a/app/Models/TorrentDenyReason.php b/app/Models/TorrentDenyReason.php new file mode 100644 index 00000000..94ac0151 --- /dev/null +++ b/app/Models/TorrentDenyReason.php @@ -0,0 +1,15 @@ + ['text' => 'Approval deny'], ]; + public function getActionTypeTextAttribute() + { + return nexus_trans("torrent.operation_log.{$this->action_type}.type_text"); + } + public function user() { return $this->belongsTo(User::class, 'uid')->select(User::$commonFields); diff --git a/database/migrations/2022_08_16_042239_create_torrent_deny_reasons_table.php b/database/migrations/2022_08_16_042239_create_torrent_deny_reasons_table.php new file mode 100644 index 00000000..067655e5 --- /dev/null +++ b/database/migrations/2022_08_16_042239_create_torrent_deny_reasons_table.php @@ -0,0 +1,34 @@ +id(); + $table->string('name'); + $table->integer('hits')->default(0); + $table->integer('priority')->default(0); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('torrent_deny_reasons'); + } +}; diff --git a/include/globalfunctions.php b/include/globalfunctions.php index 2e9d7840..8fb65bdf 100644 --- a/include/globalfunctions.php +++ b/include/globalfunctions.php @@ -516,13 +516,30 @@ function api(...$args) $data = $data['data']; } } - return [ - 'ret' => (int)$ret, - 'msg' => (string)$msg, + $time = (float)number_format(microtime(true) - nexus()->getStartTimestamp(), 3); + $count = null; + $resultKey = 'ret'; + $msgKey = 'msg'; + $format = $_REQUEST['__format'] ?? ''; + if ($format == 'layui-table') { + $resultKey = 'code'; + $count = $data['meta']['total'] ?? 0; + if (isset($data['data'])) { + $data = $data['data']; + } + } + $results = [ + $resultKey => (int)$ret, + $msgKey => (string)$msg, 'data' => $data, - 'time' => (float)number_format(microtime(true) - nexus()->getStartTimestamp(), 3), + 'time' => $time, 'rid' => nexus()->getRequestId(), ]; + if ($format == 'layui-table') { + $results['count'] = $count; + } + + return $results; } function success(...$args) diff --git a/public/details.php b/public/details.php index 528c2060..2c6d04de 100644 --- a/public/details.php +++ b/public/details.php @@ -162,45 +162,16 @@ if (!$row) { '%s %s', $row['id'], $approvalIcon, $lang_details['action_approval'] ); + $title = nexus_trans('torrent.approval.modal_title'); $js = << 'ISP', 'menu' => 'Custom menu', 'username_change_log' => 'Username change log', + 'torrent_deny_reason' => 'Deny Reasons', ], 'resources' => [ 'agent_allow' => [ diff --git a/resources/lang/en/label.php b/resources/lang/en/label.php index 26bca9ea..679c01df 100644 --- a/resources/lang/en/label.php +++ b/resources/lang/en/label.php @@ -29,6 +29,7 @@ return [ 'deadline' => 'Deadline', 'permanent' => 'Permanent', 'operator' => 'Operator', + 'action' => 'Action', 'setting' => [ 'nav_text' => 'Setting', 'backup' => [ diff --git a/resources/lang/en/torrent.php b/resources/lang/en/torrent.php index 05af92b8..3c52d255 100644 --- a/resources/lang/en/torrent.php +++ b/resources/lang/en/torrent.php @@ -46,32 +46,33 @@ return [ 'claim_disabled' => 'Claim is disabled', 'operation_log' => [ \App\Models\TorrentOperationLog::ACTION_TYPE_APPROVAL_DENY => [ - 'type_text' => 'Banned', - 'notify_subject' => 'Torrent was banned', - 'notify_msg' => 'Your torrent:[url=:detail_url]:torrent_name[/url] was banned by :operator, Reason: :reason', + 'type_text' => 'Allowed', + 'notify_subject' => 'Torrent was allowed', + 'notify_msg' => 'Your torrent:[url=:detail_url]:torrent_name[/url] was allowed by :operator, Reason: :reason', ], \App\Models\TorrentOperationLog::ACTION_TYPE_APPROVAL_ALLOW => [ - 'type_text' => 'Cancel banned', - 'notify_subject' => 'Torrent was unbanned', - 'notify_msg' => 'Your torrent: [url=:detail_url]:torrent_name[/url] unbanned by :operator', + 'type_text' => 'Denied', + 'notify_subject' => 'Torrent was denied', + 'notify_msg' => 'Your torrent: [url=:detail_url]:torrent_name[/url] denied by :operator', ], \App\Models\TorrentOperationLog::ACTION_TYPE_APPROVAL_NONE => [ - 'type_text' => 'Cancel banned', - 'notify_subject' => 'Torrent was unbanned', - 'notify_msg' => 'Your torrent: [url=:detail_url]:torrent_name[/url] unbanned by :operator', + 'type_text' => 'Not reviewed', + 'notify_subject' => 'Torrent was mark as not reviewed', + 'notify_msg' => 'Your torrent: [url=:detail_url]:torrent_name[/url] was mark as not reviewed by :operator', ] ], - 'owner_update_torrent_subject' => 'Banned torrent have been updated', - 'owner_update_torrent_msg' => 'Torrent:[url=:detail_url]:torrent_name[/url] has been updated by the owner, you can check if it meets the requirements and cancel the ban', + 'owner_update_torrent_subject' => 'Denied torrent have been updated', + 'owner_update_torrent_msg' => 'Torrent:[url=:detail_url]:torrent_name[/url] has been updated by the owner, you can check if it meets the requirements and allow', 'approval' => [ 'modal_title' => 'Torrent approval', 'status_label' => 'Approval status', 'comment_label' => 'Comment(optional)', 'status_text' => [ \App\Models\Torrent::APPROVAL_STATUS_NONE => 'Not reviewed', - \App\Models\Torrent::APPROVAL_STATUS_ALLOW => 'Approved', - \App\Models\Torrent::APPROVAL_STATUS_DENY => 'Not approved', + \App\Models\Torrent::APPROVAL_STATUS_ALLOW => 'Allowed', + \App\Models\Torrent::APPROVAL_STATUS_DENY => 'Denied', ], 'deny_comment_show' => 'Denied, reason: :reason', + 'logs_label' => 'Approval logs' ], ]; diff --git a/resources/lang/zh_CN/admin.php b/resources/lang/zh_CN/admin.php index ca97a356..e7b0a741 100644 --- a/resources/lang/zh_CN/admin.php +++ b/resources/lang/zh_CN/admin.php @@ -23,6 +23,7 @@ return [ 'isp' => 'ISP', 'menu' => '自定义菜单', 'username_change_log' => '改名记录', + 'torrent_deny_reason' => '拒绝原因', ], 'resources' => [ 'agent_allow' => [ diff --git a/resources/lang/zh_CN/label.php b/resources/lang/zh_CN/label.php index 33dfadf5..806262d6 100644 --- a/resources/lang/zh_CN/label.php +++ b/resources/lang/zh_CN/label.php @@ -29,6 +29,7 @@ return [ 'deadline' => '截止时间', 'permanent' => '永久有效', 'operator' => '操作者', + 'action' => '操作', 'setting' => [ 'nav_text' => '设置', 'backup' => [ diff --git a/resources/lang/zh_CN/torrent.php b/resources/lang/zh_CN/torrent.php index 52091cce..96ff4895 100644 --- a/resources/lang/zh_CN/torrent.php +++ b/resources/lang/zh_CN/torrent.php @@ -46,23 +46,23 @@ return [ 'claim_disabled' => '认领未启用', 'operation_log' => [ \App\Models\TorrentOperationLog::ACTION_TYPE_APPROVAL_DENY => [ - 'type_text' => '禁止', - 'notify_subject' => '种子被禁止', - 'notify_msg' => '你的种子:[url=:detail_url]:torrent_name[/url] 被 :operator 禁止,原因::reason', + 'type_text' => '审核拒绝', + 'notify_subject' => '种子审核拒绝', + 'notify_msg' => '你的种子:[url=:detail_url]:torrent_name[/url] 被 :operator 审核拒绝,原因::reason', ], \App\Models\TorrentOperationLog::ACTION_TYPE_APPROVAL_ALLOW => [ - 'type_text' => '取消禁止', - 'notify_subject' => '种子取消禁止', - 'notify_msg' => '你的种子:[url=:detail_url]:torrent_name[/url] 被 :operator 取消禁止', + 'type_text' => '审核通过', + 'notify_subject' => '种子审核通过', + 'notify_msg' => '你的种子:[url=:detail_url]:torrent_name[/url] 被 :operator 审核通过', ], \App\Models\TorrentOperationLog::ACTION_TYPE_APPROVAL_NONE => [ - 'type_text' => '取消禁止', - 'notify_subject' => '种子取消禁止', - 'notify_msg' => '你的种子:[url=:detail_url]:torrent_name[/url] 被 :operator 取消禁止', + 'type_text' => '标记未审核', + 'notify_subject' => '种子标记未审核', + 'notify_msg' => '你的种子:[url=:detail_url]:torrent_name[/url] 被 :operator 标记未审核', ] ], - 'owner_update_torrent_subject' => '被禁种子已更新', - 'owner_update_torrent_msg' => '种子:[url=:detail_url]:torrent_name[/url] 已被作者更新,可以检查是否符合要求并取消禁止', + 'owner_update_torrent_subject' => '审核拒绝种子已更新', + 'owner_update_torrent_msg' => '种子:[url=:detail_url]:torrent_name[/url] 已被作者更新,可以检查是否符合要求并审核通过', 'approval' => [ 'modal_title' => '种子审核', 'status_label' => '审核状态', @@ -73,5 +73,6 @@ return [ \App\Models\Torrent::APPROVAL_STATUS_DENY => '拒绝', ], 'deny_comment_show' => '审核不通过,原因::reason', + 'logs_label' => '审核记录', ], ]; diff --git a/resources/lang/zh_TW/admin.php b/resources/lang/zh_TW/admin.php index 95abb3dc..5b2741c7 100644 --- a/resources/lang/zh_TW/admin.php +++ b/resources/lang/zh_TW/admin.php @@ -23,6 +23,7 @@ return [ 'isp' => 'ISP', 'menu' => '自定義菜單', 'username_change_log' => '改名記錄', + 'torrent_deny_reason' => '拒絕原因', ], 'resources' => [ 'agent_allow' => [ diff --git a/resources/lang/zh_TW/label.php b/resources/lang/zh_TW/label.php index 8cc8bc56..1fa105db 100644 --- a/resources/lang/zh_TW/label.php +++ b/resources/lang/zh_TW/label.php @@ -29,6 +29,7 @@ return [ 'deadline' => '截止時間', 'permanent' => '永久有效', 'operator' => '操作者', + 'action' => '操作', 'setting' => [ 'nav_text' => '設置', 'backup' => [ diff --git a/resources/lang/zh_TW/torrent.php b/resources/lang/zh_TW/torrent.php index d3ddd076..23246c22 100644 --- a/resources/lang/zh_TW/torrent.php +++ b/resources/lang/zh_TW/torrent.php @@ -46,23 +46,23 @@ return [ 'claim_disabled' => '認領未啟用', 'operation_log' => [ \App\Models\TorrentOperationLog::ACTION_TYPE_APPROVAL_DENY => [ - 'type_text' => '禁止', - 'notify_subject' => '種子被禁止', - 'notify_msg' => '你的種子:[url=:detail_url]:torrent_name[/url] 被 :operator 禁止,原因::reason', + 'type_text' => '審核拒絕', + 'notify_subject' => '種子審核拒絕', + 'notify_msg' => '妳的種子:[url=:detail_url]:torrent_name[/url] 被 :operator 審核拒絕,原因::reason', ], \App\Models\TorrentOperationLog::ACTION_TYPE_APPROVAL_ALLOW => [ - 'type_text' => '取消禁止', - 'notify_subject' => '種子取消禁止', - 'notify_msg' => '你的種子:[url=:detail_url]:torrent_name[/url] 被 :operator 取消禁止', + 'type_text' => '審核通過', + 'notify_subject' => '種子審核通過', + 'notify_msg' => '妳的種子:[url=:detail_url]:torrent_name[/url] 被 :operator 審核通過', ], \App\Models\TorrentOperationLog::ACTION_TYPE_APPROVAL_NONE => [ - 'type_text' => '取消禁止', - 'notify_subject' => '種子取消禁止', - 'notify_msg' => '你的種子:[url=:detail_url]:torrent_name[/url] 被 :operator 取消禁止', + 'type_text' => '標記未審核', + 'notify_subject' => '種子標記未審核', + 'notify_msg' => '妳的種子:[url=:detail_url]:torrent_name[/url] 被 :operator 標記未審核', ] ], - 'owner_update_torrent_subject' => '被禁種子已更新', - 'owner_update_torrent_msg' => '種子:[url=:detail_url]:torrent_name[/url] 已被作者更新,可以檢查是否符合要求並取消禁止', + 'owner_update_torrent_subject' => '審核拒絕種子已更新', + 'owner_update_torrent_msg' => '種子:[url=:detail_url]:torrent_name[/url] 已被作者更新,可以檢查是否符合要求併審核通過', 'approval' => [ 'modal_title' => '種子審核', 'status_label' => '審核狀態', @@ -73,5 +73,6 @@ return [ \App\Models\Torrent::APPROVAL_STATUS_DENY => '拒絕', ], 'deny_comment_show' => '審核不通過,原因::reason', + 'logs_label' => '審核記錄' ], ]; diff --git a/resources/views/layui-page.blade.php b/resources/views/layui-page.blade.php new file mode 100644 index 00000000..07785945 --- /dev/null +++ b/resources/views/layui-page.blade.php @@ -0,0 +1,14 @@ + + + + + + @stack('css') + + + @stack('scripts') + + +@yield('content') + + diff --git a/resources/views/torrent/approval.blade.php b/resources/views/torrent/approval.blade.php new file mode 100644 index 00000000..41b01637 --- /dev/null +++ b/resources/views/torrent/approval.blade.php @@ -0,0 +1,107 @@ +@extends('layui-page') + +@push('css') + +@endpush +@section('content') +
+
+ @csrf + +
+ +
+ @foreach (\App\Models\Torrent::listApprovalStatus(true) as $status => $text) + approval_status) checked @endif> + @endforeach +
+
+
+ +
+ +
+
+
+
+ + +
+
+
+
+ @foreach($denyReasons as $reason) + {{ $reason->name }} + @endforeach +
+
+
{{ __('torrent.approval.logs_label') }}
+
+ +@endsection diff --git a/routes/web.php b/routes/web.php index e39c59f5..ba8033ce 100644 --- a/routes/web.php +++ b/routes/web.php @@ -17,6 +17,12 @@ Route::get('/', function () { return redirect('index.php'); }); +Route::group(['prefix' => 'web', 'middleware' => ['auth.nexus:nexus', 'locale']], function () { + Route::get('torrent-approval-page', [\App\Http\Controllers\TorrentController::class, 'approvalPage']); + Route::get('torrent-approval-logs', [\App\Http\Controllers\TorrentController::class, 'approvalLogs']); + Route::post('torrent-approval', [\App\Http\Controllers\TorrentController::class, 'approval']); +}); + if (!isRunningInConsole()) { $passkeyLoginUri = get_setting('security.login_secret'); if (!empty($passkeyLoginUri) && get_setting('security.login_type') == 'passkey') {