HEX
Server: Apache
System: Linux server1.ariadata.co 4.18.0-553.120.1.el8_10.x86_64 #1 SMP Mon Apr 20 18:04:27 EDT 2026 x86_64
User: nepi (1051)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system,show_source,popen,proc_open
Upload Files
File: /home/nepi/file.nepi.ir/common/Csv/BaseCsvExportController.php
<?php

namespace Common\Csv;

use Auth;
use Carbon\Carbon;
use Common\Core\BaseController;
use Illuminate\Http\Request;
use Storage;
use Symfony\Component\HttpFoundation\StreamedResponse;

class BaseCsvExportController extends BaseController
{
    public function __construct(protected Request $request)
    {
        $this->middleware('auth');
    }

    public function download(CsvExport $csvExport): StreamedResponse
    {
        if (
            !Auth::user()->hasPermission('admin') &&
            $csvExport->user_id !== Auth::id()
        ) {
            abort(403);
        }

        return Storage::download(
            $csvExport->filePath(),
            $csvExport->download_name,
        );
    }

    protected function exportUsing(BaseCsvExportJob $exportJob)
    {
        $csvExport = CsvExport::where(
            'cache_name',
            $exportJob->cacheName(),
        )->first();

        if (
            $csvExport &&
            $csvExport->created_at->greaterThan(Carbon::now()->addMinutes(-30))
        ) {
            return $this->success([
                'downloadPath' => $csvExport->downloadLink(),
            ]);
        }

        $this->dispatch($exportJob);
        return $this->success(['result' => 'jobQueued']);
    }
}