修复问题

This commit is contained in:
fengge 2026-04-18 22:52:38 +08:00
parent b1de3f9ba3
commit 5715981b53
1 changed files with 21 additions and 17 deletions

View File

@ -264,9 +264,9 @@
document.getElementById('current-time').innerText = new Date().toLocaleString(); document.getElementById('current-time').innerText = new Date().toLocaleString();
function checkApp() { function checkApp() {
const tag = document.getElementById('inject-status'); var tag = document.getElementById('inject-status');
const versionSpan = document.getElementById('app-version'); var versionSpan = document.getElementById('app-version');
const envSpan = document.getElementById('env-type'); var envSpan = document.getElementById('env-type');
if (window.android) { if (window.android) {
tag.innerText = "已连接至 App 原生接口"; tag.innerText = "已连接至 App 原生接口";
@ -539,29 +539,33 @@
container.insertBefore(item, container.firstChild); container.insertBefore(item, container.firstChild);
} }
async function pttRequest(path, method = 'GET', query = {}, body = null) { function pttRequest(path, method, query, body) {
let url = PTT_BASE + path; if (!method) method = 'GET';
const qParams = new URLSearchParams(query).toString(); if (!query) query = {};
var url = PTT_BASE + path;
var qParams = new URLSearchParams(query).toString();
if (qParams) url += "?" + qParams; if (qParams) url += "?" + qParams;
const options = { var options = {
method: method, method: method,
headers: { 'Content-Type': 'application/json' } headers: { 'Content-Type': 'application/json' }
}; };
if (body) options.body = JSON.stringify(body); if (body) options.body = JSON.stringify(body);
try { try {
const response = await fetch(url, options); fetch(url, options).then(function(response) {
if (path === '/record/play') { if (path === '/record/play') {
showPttResult("流式播放接口已调用,请查看网络请求或直接点击预览链接"); showPttResult("流式播放接口已调用");
return; return;
} }
const data = await response.json(); return response.json();
showPttResult(data); }).then(function(data) {
return data; if (data) showPttResult(data);
}).catch(function(e) {
showPttResult("请求失败: " + e.message);
});
} catch (e) { } catch (e) {
showPttResult("请求失败: " + e.message); showPttResult("fetch异常: " + e.message);
console.error(e);
} }
} }