- gh_api.php 新增 ghImgRepoPush/ghGitAvailable/ghImgRepoPushViaGit/ghImgRepoPushViaContents
读 img.json repo.imgrepo(模式/用户名/仓库地址/key登录密码/分支), 运行时先 ghGitAvailable
有git走 commit+push(PAT拼认证URL), 没git走 Contents API 兜底, raw链接 raw.githubusercontent.com
仓内路径 {玩家名}/{工单号}_{YYYYMMDD}_{清洗标题}/{原文件名}; 删掉 ghReadGitCredential(改读img.json token)
- lsky.php loadImgJson 解析 imgrepo 段 + imgrepo_mode/owner/full/branch/token
- api/ticket.php uploadTicketFiles 分流: imgrepo_mode=gh 存临时文件返回 @ghimgrepo: 占位,
图床模式走图床拿真URL; ticketCreate 推仓后回写 images 拿 raw URL
- api/gh_git_probe.php 新增诊断端点(检测git/imgrepo配置/raw域名可达性)
- img.json 仓库版 imgrepo 段全占位符(真PAT在 .workbuddy 不推git)
74 lines
2.6 KiB
PHP
74 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* 15m44w: 服务端 git 可用性 + imgrepo 仓可达性 探测端点。
|
|
* 用法:GET gh_git_probe.php (无鉴权,仅诊断;返回 git 版本 + imgrepo 配置 + 是否可访问仓)
|
|
* 用于定位"附件 git 推图仓"功能是否能在服务器跑起来(git 二进制/exec 权限/仓可达性)。
|
|
*/
|
|
while (ob_get_level() > 0) { @ob_end_clean(); }
|
|
ob_start();
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Cache-Control: no-store');
|
|
|
|
require_once __DIR__ . '/../core.php';
|
|
require_once __DIR__ . '/../lsky.php';
|
|
require_once __DIR__ . '/../gh_api.php';
|
|
|
|
$cfg = loadImgJson();
|
|
|
|
// 1) git 二进制是否可用
|
|
$gitOk = false;
|
|
$gitVer = '';
|
|
$gitCmd = 'git --version';
|
|
if (function_exists('exec')) {
|
|
$out = [];
|
|
$ret = 0;
|
|
@exec($gitCmd . ' 2>&1', $out, $ret);
|
|
if ($ret === 0 && !empty($out)) {
|
|
$gitOk = true;
|
|
$gitVer = trim(implode(' ', $out));
|
|
}
|
|
} elseif (function_exists('shell_exec')) {
|
|
$out = @shell_exec($gitCmd . ' 2>&1');
|
|
if (is_string($out)) { $gitVer = trim($out); $gitOk = ($gitVer !== ''); }
|
|
}
|
|
|
|
// 2) imgrepo 配置
|
|
$ir = [
|
|
'mode' => $cfg['imgrepo_mode'] ?? '',
|
|
'owner' => $cfg['imgrepo_owner'] ?? '',
|
|
'full' => $cfg['imgrepo_full'] ?? '',
|
|
'branch' => $cfg['imgrepo_branch'] ?? '',
|
|
'token' => (isset($cfg['imgrepo_token']) && $cfg['imgrepo_token'] !== '') ? substr($cfg['imgrepo_token'], 0, 4) . '****' : '',
|
|
];
|
|
|
|
// 3) 仓可达性(带 token GET raw 域名,不实际推)
|
|
$reach = '';
|
|
$reachStatus = 0;
|
|
if ($ir['full'] !== '' && $ir['owner'] !== '') {
|
|
$rawUrl = 'https://raw.githubusercontent.com/' . $ir['full'] . '/' . $ir['branch'];
|
|
if (function_exists('curl_init')) {
|
|
$ch = curl_init();
|
|
curl_setopt($ch, CURLOPT_URL, $rawUrl);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
|
|
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
|
|
curl_exec($ch);
|
|
$reachStatus = (int)curl_getinfo($ch, CURLINFO_RESPONSE_CODE);
|
|
$reach = 'HTTP ' . $reachStatus;
|
|
curl_close($ch);
|
|
}
|
|
}
|
|
|
|
success([
|
|
'git_available' => $gitOk,
|
|
'git_version' => $gitVer,
|
|
'exec_func' => function_exists('exec'),
|
|
'proc_open' => function_exists('proc_open'),
|
|
'imgrepo' => $ir,
|
|
'raw_reach' => $reach,
|
|
'hint' => $gitOk
|
|
? 'git 可用,附件可走 git 推图仓'
|
|
: '⚠ 服务器 git 不可用(未装 git 或 exec 被禁),附件 git 推图仓功能无法运行——需服务器装 git 并放开 PHP exec',
|
|
], 'ok');
|