json放行

This commit is contained in:
tianmo committed 2026-09-11 14:02:48 +08:00
1 parent 99d85a9e6d
commit ba0f48c543
6 files changed
+52 -15

No files matched your search

+29 -8
View File
@@ -175,6 +175,13 @@
#overlay .box { max-width: 520px; padding: 20px; }
#overlay .title { font-size: 16px; margin-bottom: 8px; color: var(--error); }
#overlay .msg { color: var(--text-dim); white-space: pre-wrap; word-break: break-all; }
#overlay.text-preview { align-items: stretch; justify-content: stretch; text-align: left; }
#overlay.text-preview .box { width: 100%; max-width: none; padding: 24px; overflow: auto; }
#overlay.text-preview .title { color: var(--text); font-size: 13px; font-weight: 600; }
#overlay.text-preview .msg {
font: 12px/1.6 "SFMono-Regular", Consolas, "Liberation Mono", monospace;
color: var(--text-dim); white-space: pre; word-break: normal;
}
#overlay.hidden { display: none; }
#loading { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 4; background: var(--bg); }
#loading.hidden { display: none; }
@@ -350,6 +357,16 @@
document.getElementById('errorMsg').textContent = msg;
}
function showTextPreview(title, text) {
running = false;
toolbarEl.style.display = 'none';
timelineBarEl.style.display = 'none';
animationPanel.style.display = 'none';
statusEl.style.display = 'none';
overlay.classList.add('text-preview');
showError(title, text);
}
function setStatus(msg, holdMs = 0) {
statusEl.textContent = msg;
statusHoldUntil = holdMs === Infinity ? Infinity : (holdMs > 0 ? performance.now() + holdMs : 0);
@@ -936,9 +953,6 @@
if (!utils.extOf(path.basename(filePath))) {
// Registering txt/bytes is required by Eagle's extension dispatch.
// Ordinary text remains readable and never starts Spine discovery.
document.getElementById('toolbar').style.display = 'none';
document.getElementById('timelineBar').style.display = 'none';
document.getElementById('animationPanel').style.display = 'none';
let message = '此文件不是 .atlas.txt 或 .skel.bytes 格式的 Spine 资源。';
if (/\.txt$/i.test(filePath)) {
const fd = fs.openSync(filePath, 'r');
@@ -949,16 +963,23 @@
if (fs.fstatSync(fd).size > count) message += '\n\n(仅显示前 256 KB)';
} finally { fs.closeSync(fd); }
}
showError(path.basename(filePath), message);
const box = overlay.querySelector('.box');
box.style.cssText = 'max-width:none;width:100%;height:100%;overflow:auto;text-align:left';
document.getElementById('errorTitle').style.color = 'var(--text)';
showTextPreview(path.basename(filePath), message);
return;
}
// Eagle 只能按 .json 扩展名把文件交给格式扩展。查看器必须再次检查内容,
// 防止普通 JSON 被拿去匹配库中其他 Spine 骨骼资源。
if (utils.extOf(path.basename(filePath)) === '.json' && utils.classifySkeletonJson(filePath) !== 'spine') {
showError('普通 JSON 文件', '该文件不包含 Spine 导出的 skeleton.spine 版本字段,因此不会作为 Spine 骨骼数据加载。');
const maxPreviewBytes = 1024 * 1024;
const stat = fs.statSync(filePath);
const fd = fs.openSync(filePath, 'r');
const buffer = Buffer.alloc(Math.min(stat.size, maxPreviewBytes));
let count = 0;
try { count = fs.readSync(fd, buffer, 0, buffer.length, 0); } finally { fs.closeSync(fd); }
let text = buffer.subarray(0, count).toString('utf8');
if (stat.size <= maxPreviewBytes) {
try { text = JSON.stringify(JSON.parse(text), null, 2); } catch (e) { /* 保留 JSONC/原始文本 */ }
} else text += '\n\n(文件较大,仅显示前 1 MB)';
showTextPreview(path.basename(filePath), text);
return;
}
const assets = utils.discoverAssets(filePath);