Files
Sdf1_login/api/img_cfg.php
T
ypsdf1 f94e155208 @
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。
2026-11-24 21:57:56 +08:00

30 lines
1.2 KiB
PHP

<?php
/**
* 15m44j: img.json 配置懒重载端点 — 前端进工单表单前 fetch 一次, 拿到:
* - max_images: 单工单最多几张
* - max_size_mb: 单张大小上限 (MB)
* - allowed_exts: 允许的后缀数组
* - attach_enabled: 附件总开关 (false 时前端禁用"选择图片"按钮)
*
* 无 token 校验 (配置非敏感, 仅限制前端 UX 文案/上限); 真实上传仍走 ticketCreate 鉴权。
* 每次请求重新读 img.json (懒重载, 不缓存), 改配置立即生效。
*/
while (ob_get_level() > 0) { @ob_end_clean(); }
ob_start();
header('Content-Type: application/json; charset=utf-8');
header('X-Content-Type-Options: nosniff');
header('Cache-Control: no-store, no-cache, must-revalidate, max-age=0');
header('Pragma: no-cache');
header('Expires: 0');
require_once __DIR__ . '/../core.php';
require_once __DIR__ . '/../lsky.php';
$cfg = loadImgJson();
success([
'max_images' => max(1, (int)($cfg['max_images'] ?? 3)),
'max_size_mb' => max(1, (int)($cfg['max_size_mb'] ?? 2)),
'allowed_exts' => array_map('strtolower', (array)($cfg['allowed_exts'] ?? ['jpg','jpeg','png'])),
'attach_enabled' => !empty($cfg['attach_enabled']),
], 'ok');