M4: 插件框架(钩子系统/ZIP安装/市场客户端)+ blog-seo 插件(JSON-LD/OG/llms.txt/Markdown导出)+ 后台插件/主题管理页
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Blog\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\File;
|
||||
|
||||
class MarketplaceClient
|
||||
{
|
||||
/**
|
||||
* 拉取市场包列表。
|
||||
*
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function items(): array
|
||||
{
|
||||
$url = config('market.url');
|
||||
|
||||
if (! $url) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$response = Http::timeout(config('market.timeout', 15))
|
||||
->withToken(config('market.token', ''))
|
||||
->get(rtrim($url, '/').'/items');
|
||||
|
||||
$response->throw();
|
||||
|
||||
return $response->json('items', []);
|
||||
}
|
||||
|
||||
public function download(string $url): string
|
||||
{
|
||||
$response = Http::timeout(60)->get($url);
|
||||
$response->throw();
|
||||
|
||||
$tmp = storage_path('app/tmp/market-'.basename(parse_url($url, PHP_URL_PATH)));
|
||||
File::ensureDirectoryExists(dirname($tmp));
|
||||
File::put($tmp, $response->body());
|
||||
|
||||
return $tmp;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user