38751-vm/app/Controllers/ApkController.php
Flatlogic Bot 4f61082b27 Aslam vbru
2026-02-24 22:45:41 +00:00

53 lines
1.4 KiB
PHP

<?php
namespace App\Controllers;
use App\Core\Controller;
use App\Services\ApkService;
class ApkController extends Controller {
protected $apkService;
public function __construct() {
$this->apkService = new ApkService();
}
public function detail($params) {
$apk = $this->apkService->getBySlug($params['slug']);
if (!$apk) {
header("HTTP/1.0 404 Not Found");
echo "APK Not Found";
return;
}
return $this->view('apk_detail', [
'apk' => $apk,
'title' => $apk['title'] . ' v' . $apk['version'] . ' APK Download'
]);
}
public function download($params) {
$apk = $this->apkService->getBySlug($params['slug']);
if (!$apk) {
header("HTTP/1.0 404 Not Found");
echo "APK Not Found";
return;
}
// Increment download counter
$this->apkService->incrementDownload($apk['id']);
// Get the download URL
$downloadUrl = $apk['download_url'];
// If URL is empty or #, redirect back to detail with a message
if (empty($downloadUrl) || $downloadUrl === '#') {
$this->redirect('/apk/' . $apk['slug'] . '?error=no_url');
return;
}
// Redirect to the actual download link (External URL)
$this->redirect($downloadUrl);
}
}