Files
plugins/UpdateAssistant/library/Downloader.php
chorblack e75f275ef4
Some checks failed
定时更新GitHub源插件 / 自动更新GitHub插件 (push) Has been cancelled
Initial commit
2026-03-07 11:19:25 +08:00

40 lines
1.2 KiB
PHP

<?php
/**
* Typecho update assistant.
*
* @package UpdateAssistant
* @author mrgeneral
* @version 1.0.1
* @link https://www.chengxiaobai.cn
*/
class Downloader extends Base
{
protected function down($isDevelop, $archiveName, $workRootPath)
{
$downloadUrl = 'https://github.com/typecho/typecho/archive/master.zip';
$archiveRealPath = rtrim($workRootPath, '/.\\') . DIRECTORY_SEPARATOR . 'archive' . DIRECTORY_SEPARATOR . $archiveName . '.zip';
// cache
if (is_file($archiveRealPath)) {
return true;
}
if (!$isDevelop) {
$content = $this->{$this->handler}('http://typecho.org/version.json');
if (empty($content)
|| null === ($content = json_decode($content, true))
|| empty($content['release'])
|| empty($content['version'])
) {
throw new Exception('Fetch release version failed!');
}
$downloadUrl = sprintf('https://github.com/typecho/typecho/archive/v%s-%s-release.zip', $content['release'], $content['version']);
}
return $this->{$this->handler}($downloadUrl, $archiveRealPath);
}
}