@lark-apaas/coding-preset-vite-react 1.0.15 → 1.0.16-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/overlay/vite-client.js +76 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lark-apaas/coding-preset-vite-react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.16-beta.0",
|
|
4
4
|
"description": "Vite 8 preset for miaoda-coding vite-react (jsPage) templates — pure frontend, no fullstack baggage",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
@@ -500,6 +500,77 @@ if (!window.__VITE_ERROR_OVERLAY_INITIALIZED__) {
|
|
|
500
500
|
}
|
|
501
501
|
}
|
|
502
502
|
|
|
503
|
+
// ===== AI 素材图失败原因探测 =====
|
|
504
|
+
// AI 素材图是异步生成的,加载失败时需要知道生成失败的原因。
|
|
505
|
+
// 本脚本与图片同源,补一次 fetch 即可取回;妙搭主站跨域拿不到。
|
|
506
|
+
var MIAODA_VE_SUFFIX = '_ve_miaoda';
|
|
507
|
+
var GEN_PROBE_TIMEOUT_MS = 3000;
|
|
508
|
+
var GEN_PROBE_MAX_BODY = 2048;
|
|
509
|
+
var GEN_FAILED_CODE = 'k_img_ec_000064'; // 生图失败专属码;URL 写错、无权限是别的码,不能混
|
|
510
|
+
var genProbeCache = Object.create(null); // url -> 响应体,同一张图不重复探测
|
|
511
|
+
|
|
512
|
+
function reportResourceError(tag, url) {
|
|
513
|
+
logError(['Resource load failed', tag, url], 'runtimeError');
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
// 取 tos file id 代替完整 URL:URL 近 230 字符会把 reason 挤出截断边界
|
|
517
|
+
function shortImageRef(url) {
|
|
518
|
+
var noQuery = String(url).split('?')[0];
|
|
519
|
+
var decoded = noQuery;
|
|
520
|
+
try { decoded = decodeURIComponent(noQuery); } catch (e) {}
|
|
521
|
+
return decoded.split('/').pop() || noQuery;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// 确认是生成失败则返回原因,否则返回 null
|
|
525
|
+
function parseGenFailure(body) {
|
|
526
|
+
if (!body || body.indexOf(GEN_FAILED_CODE) === -1) return null;
|
|
527
|
+
try {
|
|
528
|
+
var data = JSON.parse(body);
|
|
529
|
+
return data.error_msg || data.reason || body;
|
|
530
|
+
} catch (e) {
|
|
531
|
+
return body;
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
function reportGenAssetResult(tag, url, body) {
|
|
536
|
+
var reason = parseGenFailure(body);
|
|
537
|
+
// 确认不了就原样上报,交回原有逻辑
|
|
538
|
+
if (reason === null) {
|
|
539
|
+
reportResourceError(tag, url);
|
|
540
|
+
return;
|
|
541
|
+
}
|
|
542
|
+
logError(
|
|
543
|
+
['Resource load failed, fail reason: ' + reason + ' , image: ' + shortImageRef(url), tag, url],
|
|
544
|
+
'runtimeError'
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
function reportGenAssetError(tag, url) {
|
|
549
|
+
if (Object.prototype.hasOwnProperty.call(genProbeCache, url)) {
|
|
550
|
+
reportGenAssetResult(tag, url, genProbeCache[url]);
|
|
551
|
+
return;
|
|
552
|
+
}
|
|
553
|
+
genProbeCache[url] = ''; // 占位,避免并发重复探测
|
|
554
|
+
|
|
555
|
+
var done = false;
|
|
556
|
+
function finish(body) {
|
|
557
|
+
if (done) return;
|
|
558
|
+
done = true;
|
|
559
|
+
genProbeCache[url] = body || '';
|
|
560
|
+
reportGenAssetResult(tag, url, body);
|
|
561
|
+
}
|
|
562
|
+
// 超时兜底,别让探测卡住导致这条错误上报不出去
|
|
563
|
+
setTimeout(function () { finish(''); }, GEN_PROBE_TIMEOUT_MS);
|
|
564
|
+
try {
|
|
565
|
+
fetch(url, { cache: 'no-store' })
|
|
566
|
+
.then(function (res) { return res.text(); })
|
|
567
|
+
.then(function (body) { finish(String(body || '').slice(0, GEN_PROBE_MAX_BODY)); })
|
|
568
|
+
.catch(function () { finish(''); });
|
|
569
|
+
} catch (e) {
|
|
570
|
+
finish('');
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
503
574
|
// ===== Global Error Listeners =====
|
|
504
575
|
function setupGlobalErrorListeners() {
|
|
505
576
|
// capture 阶段才能拿到资源 404(IMG/SCRIPT/LINK 的 error 不冒泡)
|
|
@@ -521,7 +592,11 @@ if (!window.__VITE_ERROR_OVERLAY_INITIALIZED__) {
|
|
|
521
592
|
// 避免用户"页面日志"面板被这类无害 404 淹没
|
|
522
593
|
if (/\/favicon\.(ico|png|svg)|\/apple-touch-icon|\/manifest\.json|\/robots\.txt/.test(url)) return;
|
|
523
594
|
// 资源 404 只上报到页面日志,不 render overlay(避免整页遮盖用户预览)
|
|
524
|
-
|
|
595
|
+
if (url.indexOf(MIAODA_VE_SUFFIX) !== -1) {
|
|
596
|
+
reportGenAssetError(tag.toLowerCase(), url);
|
|
597
|
+
} else {
|
|
598
|
+
reportResourceError(tag.toLowerCase(), url);
|
|
599
|
+
}
|
|
525
600
|
}
|
|
526
601
|
}
|
|
527
602
|
}, true);
|