Initial Ladill Transfer app — file sharing with QR links.
Scaffolded from the Ladill mini/events extraction pattern: multi-file transfers, retention controls, public landing pages, analytics, and Gitea deploy workflow. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Transfer;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Transfer;
|
||||
use App\Models\TransferDownloadEvent;
|
||||
use App\Services\Billing\BillingClient;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\View\View;
|
||||
use Throwable;
|
||||
|
||||
class OverviewController extends Controller
|
||||
{
|
||||
public function __construct(private BillingClient $billing) {}
|
||||
|
||||
public function index(Request $request): View
|
||||
{
|
||||
$account = ladill_account();
|
||||
|
||||
$transfers = Transfer::query()
|
||||
->where('user_id', $account->id)
|
||||
->where('status', Transfer::STATUS_ACTIVE);
|
||||
|
||||
$activeCount = (clone $transfers)->count();
|
||||
$storageBytes = (int) (clone $transfers)->sum('storage_bytes');
|
||||
|
||||
$transferIds = Transfer::query()
|
||||
->where('user_id', $account->id)
|
||||
->pluck('id');
|
||||
|
||||
$downloads30d = TransferDownloadEvent::query()
|
||||
->whereIn('transfer_id', $transferIds)
|
||||
->where('downloaded_at', '>=', now()->subDays(30))
|
||||
->count();
|
||||
|
||||
$expiringSoon = Transfer::query()
|
||||
->where('user_id', $account->id)
|
||||
->where('status', Transfer::STATUS_ACTIVE)
|
||||
->whereNotNull('expires_at')
|
||||
->whereBetween('expires_at', [now(), now()->addDays(7)])
|
||||
->count();
|
||||
|
||||
$recentTransfers = Transfer::query()
|
||||
->where('user_id', $account->id)
|
||||
->where('status', Transfer::STATUS_ACTIVE)
|
||||
->with('qrCode')
|
||||
->latest()
|
||||
->limit(6)
|
||||
->get();
|
||||
|
||||
$balanceMinor = 0;
|
||||
try {
|
||||
$balanceMinor = $this->billing->balanceMinor($account->public_id);
|
||||
} catch (Throwable $e) {
|
||||
Log::warning('Transfer dashboard could not load wallet balance', [
|
||||
'user' => $account->public_id,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
|
||||
$storageGb = round($storageBytes / (1024 * 1024 * 1024), 2);
|
||||
$monthlyEstimateGhs = round($storageGb * (float) config('transfer.price_per_gb_month', 1.0), 2);
|
||||
|
||||
return view('transfer.dashboard', [
|
||||
'activeCount' => $activeCount,
|
||||
'storageBytes' => $storageBytes,
|
||||
'storageGb' => $storageGb,
|
||||
'downloads30d' => $downloads30d,
|
||||
'expiringSoon' => $expiringSoon,
|
||||
'recentTransfers' => $recentTransfers,
|
||||
'balanceMinor' => $balanceMinor,
|
||||
'monthlyEstimateGhs' => $monthlyEstimateGhs,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user