Files
sachgiaokhoaorg/app/Commands/RefreshCatalog.php
T
sachgiaokhoaorg e6b265db99 Sách Giáo Khoa Việt Nam - sachgiaokhoa.org
CodeIgniter 4 website:
- Catalog 999 SGK (lớp 1-12) từ API, lọc theo lớp/môn/NXB, tìm kiếm
- Trang chủ grouped browse (bậc học -> lớp -> môn, ưu tiên môn quan trọng)
- Chi tiết sách: metadata đầy đủ, cover nghệ thuật /thumb/{W}x{H}/
- Đọc online qua gate captcha + countdown, PDF viewer pdf.js
- Download: captcha + token một lần + auto cache-bust version
- Tự đồng bộ catalog/cover khi API thay đổi (refresh:catalog)
- Legal: DMCA, miễn trừ trách nhiệm, điều khoản, bảo mật, liên hệ
2026-08-23 07:05:49 +00:00

41 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Commands;
use App\Libraries\BookApi;
use App\Libraries\Mongo;
use CodeIgniter\CLI\BaseCommand;
use CodeIgniter\CLI\CLI;
/**
* Force-refresh the book catalog from the upstream API and purge the local
* cover/thumbnail cache so everything is re-fetched lazily from the API.
*
* Run after updating the upstream API:
* php spark refresh:catalog
*/
class RefreshCatalog extends BaseCommand
{
protected $group = 'sachgiaokhoa';
protected $name = 'refresh:catalog';
protected $description = 'Force-refresh catalog from the API and purge cover cache.';
public function run(array $params): void
{
CLI::write('Đang refresh catalog từ API…', 'yellow');
try {
$api = new BookApi();
$books = $api->catalog(true); // force + purge covers/thumbs on change
} catch (\Throwable $e) {
CLI::error('Lỗi: ' . $e->getMessage());
exit(1);
}
$meta = Mongo::col('catalog')->findOne(['_id' => 'meta']);
CLI::write(sprintf('OK: %d đầu sách. mediaVersion=%s', count($books), $meta['mediaVersion'] ?? '?'), 'green');
CLI::write('Cover cache đã được dọn — website sẽ tự tải cover mới khi truy cập.', 'green');
CLI::write('Bump media.version nếu CDN vẫn cache ảnh cũ: thay đổi .env media.version = ' . (string) (((int) env('media.version', 1)) + 1), 'white');
}
}