mirror of
https://github.com/kiddin9/op-packages.git
synced 2026-08-03 07:59:09 +08:00
39 lines
1.2 KiB
HTML
39 lines
1.2 KiB
HTML
<%
|
|
local api = require('luci.model.cbi.cqustdotnet.api.api')
|
|
-%>
|
|
|
|
<fieldset class="cbi-section">
|
|
<input type="button" class="btn cbi-button cbi-button-remove" onclick="clearLog()" value="<%:Clear logs%>"/>
|
|
<textarea id="log_textarea" class="cbi-input-textarea" data-update="change" readonly></textarea>
|
|
</fieldset>
|
|
|
|
<script type="text/javascript">//<![CDATA[
|
|
const logTextarea = document.getElementById('log_textarea')
|
|
|
|
function clearLog() {
|
|
XHR.get('<%=api.url("clear_log")%>', null, function (x) {
|
|
if (x && x.status === 200) {
|
|
logTextarea.innerHTML = ''
|
|
logTextarea.scrollTop = logTextarea.scrollHeight
|
|
}
|
|
})
|
|
}
|
|
|
|
let logCursor = null
|
|
XHR.poll(5, '<%=api.url("fetch_log")%>', {after: logCursor}, function (http, data) {
|
|
if (!http) return
|
|
if (http.status === 400) {
|
|
// TODO: 日志文件不存在
|
|
return
|
|
}
|
|
if (http.status !== 200) return // 未知错误
|
|
|
|
if (logCursor !== data.cursor) {
|
|
logCursor = data.cursor
|
|
data.fragment.trim().split('\n').forEach(function (line) {
|
|
logTextarea.innerHTML = line + '\n' + logTextarea.innerHTML
|
|
})
|
|
}
|
|
})
|
|
//]]></script>
|