@
15m44j img.json 新格式 + 懒重载 + 修 API 挂起/删图不让提交
用户定调: img.json 格式调整(嵌套 api.baseurl/key + 图像/附件支持.最大图片数量/.最大大小/.后缀格式),
代码读新格式; img.json 懒重载(每次新建工单时增量读); 先取消假定未更改推仓库; 删图后能正常提交。
根因 3 个:
1. API 挂起: 生产 img.json 还是旧格式(baseurl/key 顶层), loadImgJson 按旧路径读 → 但
easyUploadFile 用新格式路径 api.baseurl 拿不到 → curl 挂起 60s。
2. 删图不让提交: removeTicketImg 用 files.splice 删了数组但 ticketState.files 引用没同步
(旧代码 splice 后没重新赋值), 提交时 ticketState.files 还残留已删元素。
3. 硬编码 3/2048K/png|jpg: 前端 uploadTicketImage 写死, 后端 uploadTicketFiles 也写死,
与 img.json 配置不同步。
修 5 处:
1. img.json 本地改新格式(api.baseurl/api.key + 图像/附件支持嵌套), 取消假定未更改, 入库。
2. lsky.php loadImgJson(): 改读新格式 api.baseurl/key + 图像/附件支持.附件支持/.最大图片数量/
.最大大小/.后缀格式, 兼容旧格式(顶层 baseurl/key + 图像/附件支持布尔); 每次调用重新读文件
(懒重载, 不缓存); 返回统一结构含 max_images/max_size_mb/allowed_exts/attach_enabled。
3. api/ticket.php: 新增 ticketMaxImages() 读 loadImgJson().max_images; uploadTicketFiles 开头
调 loadImgJson 懒重载, 按 attach_enabled 决定是否接文件, 按 max_images/max_size_mb/
allowed_exts 校验; 真实格式(getimagesize)必须在 img.json 允许后缀里。
4. 新增 api/img_cfg.php: 前端 fetch 端点, 返回 {max_images, max_size_mb, allowed_exts,
attach_enabled} (无 token 校验, 配置非敏感), 每次请求重新读 img.json。
5. player.php: 新增 loadTicketImgCfg() fetch img_cfg.php, uploadTicketImage 前懒重载;
校验改 ticketImgCfg.max_images/max_size_mb/allowed_exts(不再硬编码 3/2048K);
removeTicketImg 修 splice 后重新赋值 ticketState.files(同步清数组引用), 删占位符,
提示"已移除 图片N(剩 M 张可提交)"。
部署清单: img.json(新格式) + lsky.php + api/ticket.php + player.php + api/img_cfg.php(新)。
生产 FTP 推 img.json 新格式(baseurl/key 改 api. 嵌套) + opcache_invalidate.php。
This commit is contained in:
@@ -30,21 +30,68 @@ if (!defined('LSKY_ALLOWED_HOST_PREFIX')) {
|
||||
* - type = GitHub → 走 GitHub issue(本期不实现,返回 easy=false)
|
||||
* 文件缺失/解析失败 → 全空(调用方按"未配置"兜底 LSKY_ALLOWED_HOST_PREFIX)。
|
||||
*/
|
||||
/**
|
||||
* 加载 img.json(15m44j 改读新格式 + 每次调用重新读文件=懒重载, 不缓存)。
|
||||
*
|
||||
* 新格式(用户 2026-11-24 定调):
|
||||
* api.baseurl / api.key — EasyImages2.0 图床地址+密钥
|
||||
* 图像/附件支持.附件支持 — 总开关(false 时整段禁用图片上传)
|
||||
* 图像/附件支持.最大图片数量 — 单工单最多几张(默认 3)
|
||||
* 图像/附件支持.最大大小 — 单张大小上限, 单位 MB(默认 2)
|
||||
* 图像/附件支持.后缀格式 — 允许的后缀数组(默认 ["jpg","jpeg","png"])
|
||||
* 模式.type — 留空=图床, GitHub=issue(本期不做)
|
||||
*
|
||||
* 返回结构(统一):
|
||||
* ['type','baseurl','key','easy',
|
||||
* 'attach_enabled','max_images','max_size_mb','allowed_exts']
|
||||
* 文件缺失/解析失败 → 全默认值(调用方按"未配置"兜底)。
|
||||
*/
|
||||
function loadImgJson() {
|
||||
$cfg = ['type' => '', 'baseurl' => '', 'key' => ''];
|
||||
// 默认值(文件缺失/解析失败时用)
|
||||
$cfg = [
|
||||
'type' => '',
|
||||
'baseurl' => '',
|
||||
'key' => '',
|
||||
'easy' => false,
|
||||
'attach_enabled' => true,
|
||||
'max_images' => 3,
|
||||
'max_size_mb' => 2,
|
||||
'allowed_exts' => ['jpg', 'jpeg', 'png'],
|
||||
];
|
||||
$file = __DIR__ . '/img.json';
|
||||
if (is_readable($file)) {
|
||||
$j = json_decode((string)@file_get_contents($file), true);
|
||||
if (is_array($j)) {
|
||||
// 模式.type: 留空=走图床, GitHub=走 issue(本期不做, 仍回退图床)
|
||||
$t = isset($j['模式']['type']) ? trim((string)$j['模式']['type']) : '';
|
||||
$cfg['type'] = $t;
|
||||
$cfg['baseurl'] = isset($j['baseurl']) ? trim((string)$j['baseurl']) : '';
|
||||
$cfg['key'] = isset($j['key']) ? trim((string)$j['key']) : '';
|
||||
}
|
||||
if (!is_readable($file)) return $cfg;
|
||||
$j = json_decode((string)@file_get_contents($file), true);
|
||||
if (!is_array($j)) return $cfg;
|
||||
|
||||
// 模式.type
|
||||
$cfg['type'] = isset($j['模式']['type']) ? trim((string)$j['模式']['type']) : '';
|
||||
|
||||
// api.baseurl / api.key(新格式:嵌套在 api 对象下;兼容旧格式:顶层 baseurl/key)
|
||||
if (isset($j['api']) && is_array($j['api'])) {
|
||||
$cfg['baseurl'] = isset($j['api']['baseurl']) ? trim((string)$j['api']['baseurl']) : '';
|
||||
$cfg['key'] = isset($j['api']['key']) ? trim((string)$j['api']['key']) : '';
|
||||
} else {
|
||||
// 兼容旧格式(生产 img.json 还没同步时)
|
||||
$cfg['baseurl'] = isset($j['baseurl']) ? trim((string)$j['baseurl']) : '';
|
||||
$cfg['key'] = isset($j['key']) ? trim((string)$j['key']) : '';
|
||||
}
|
||||
// easy = 走 EasyImages2.0(type 非 GitHub 且有 baseurl+key)
|
||||
$cfg['easy'] = ($cfg['type'] !== 'GitHub' && $cfg['baseurl'] !== '' && $cfg['key'] !== '');
|
||||
|
||||
// 图像/附件支持 嵌套对象(新格式);兼容旧格式:顶层布尔
|
||||
$attach = $j['图像/附件支持'] ?? null;
|
||||
if (is_array($attach)) {
|
||||
$cfg['attach_enabled'] = !empty($attach['附件支持']);
|
||||
$cfg['max_images'] = isset($attach['最大图片数量']) && is_numeric($attach['最大图片数量']) ? (int)$attach['最大图片数量'] : 3;
|
||||
$cfg['max_size_mb'] = isset($attach['最大大小']) && is_numeric($attach['最大大小']) ? (int)$attach['最大大小'] : 2;
|
||||
if (isset($attach['后缀格式']) && is_array($attach['后缀格式'])) {
|
||||
$cfg['allowed_exts'] = array_map(function($e) { return strtolower(trim((string)$e)); }, $attach['后缀格式']);
|
||||
}
|
||||
} elseif (is_bool($attach)) {
|
||||
// 旧格式:顶层布尔(true/false)
|
||||
$cfg['attach_enabled'] = $attach;
|
||||
}
|
||||
|
||||
// easy = 走 EasyImages2.0(type 非 GitHub 且有 baseurl+key 且附件支持开)
|
||||
$cfg['easy'] = ($cfg['type'] !== 'GitHub' && $cfg['baseurl'] !== '' && $cfg['key'] !== '' && $cfg['attach_enabled']);
|
||||
return $cfg;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user