| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- <?php
- namespace App\Module\Cleanup\AdminControllers\Actions;
- use App\Module\Cleanup\Services\CleanupService;
- use Dcat\Admin\Grid\RowAction;
- use Dcat\Admin\Actions\Response;
- use Illuminate\Http\Request;
- /**
- * 下载备份Action
- *
- * 用于下载备份文件
- */
- class DownloadBackupAction extends RowAction
- {
- /**
- * 按钮标题
- */
- protected $title = '下载备份';
- /**
- * 处理请求
- */
- public function handle(Request $request)
- {
- try {
- $backupId = $this->getKey();
-
- // 调用服务生成下载链接
- $result = CleanupService::generateBackupDownloadUrl($backupId);
-
- if (!$result['success']) {
- return $this->response()
- ->error('生成下载链接失败:' . $result['message']);
- }
-
- $data = $result['data'];
-
- return $this->response()
- ->success('下载链接已生成')
- ->detail("
- 备份名称:{$data['backup_name']}<br>
- 文件大小:{$data['file_size']}<br>
- 过期时间:{$data['expires_at']}<br>
- <br>
- <a href='{$data['download_url']}' class='btn btn-primary' target='_blank'>
- <i class='fa fa-download'></i> 立即下载
- </a>
- ");
-
- } catch (\Exception $e) {
- return $this->response()
- ->error('下载失败:' . $e->getMessage());
- }
- }
- /**
- * 确认对话框
- */
- public function confirm()
- {
- return [
- '确认下载备份?',
- '将生成临时下载链接,请及时下载。'
- ];
- }
- /**
- * 权限检查
- */
- public function allowed()
- {
- $row = $this->row;
- return $row->backup_status == 2; // 只有已完成的备份可以下载
- }
- }
|