시놀로지 원격 로그 뷰어 추가

This commit is contained in:
seo
2026-07-25 19:52:38 +09:00
parent 3aff2748e8
commit 756464643c
5 changed files with 254 additions and 5 deletions
+118
View File
@@ -60,6 +60,9 @@
dmesgToggle: $('#dmesgToggle'),
dmesgOutput: $('#dmesgOutput'),
dmesgMeta: $('#dmesgMeta'),
synologyLogToggle: $('#synologyLogToggle'),
synologyLogOutput: $('#synologyLogOutput'),
synologyLogMeta: $('#synologyLogMeta'),
processDetails: $('#processDetails'),
diagnosticDetails: $('#diagnosticDetails'),
};
@@ -79,6 +82,10 @@
dmesgOpen: false,
dmesgTimer: null,
dmesgLatestKey: null,
synologyLogOpen: false,
synologyLogTimer: null,
synologyLogLatestKey: null,
synologyLogScrollHoldUntil: 0,
ws: null,
wsConnected: false,
wsFallbackTimer: null,
@@ -281,6 +288,9 @@
fanUpdateFailed: 'fan update failed',
dmesgUnavailable: 'dmesg log is not available yet.',
dmesgRefreshFailed: 'dmesg refresh failed',
synologyLog: 'Synology Log',
synologyLogUnavailable: 'Synology log is not available yet.',
synologyLogRefreshFailed: 'Synology log refresh failed',
rebootPrompt: 'Type reboot below to continue.',
rebootPhrase: 'reboot',
rebootTitle: 'System Reboot',
@@ -473,6 +483,9 @@
fanUpdateFailed: '팬 갱신 실패',
dmesgUnavailable: 'dmesg 로그를 아직 사용할 수 없습니다.',
dmesgRefreshFailed: 'dmesg 갱신 실패',
synologyLog: '시놀로지 로그',
synologyLogUnavailable: '시놀로지 로그를 아직 사용할 수 없습니다.',
synologyLogRefreshFailed: '시놀로지 로그 갱신 실패',
rebootPrompt: '재부팅을 계속하려면 아래에 재부팅을 입력하세요.',
rebootPhrase: '재부팅',
rebootTitle: '시스템 재부팅',
@@ -527,6 +540,9 @@
if (els.dmesgToggle) {
els.dmesgToggle.textContent = state.dmesgOpen ? t('hide') : t('show');
}
if (els.synologyLogToggle) {
els.synologyLogToggle.textContent = state.synologyLogOpen ? t('hide') : t('show');
}
}
function initPreferences() {
@@ -1163,6 +1179,10 @@
stopDmesgFallback();
sendWs({ type: 'dmesg', open: true });
}
if (state.synologyLogOpen) {
stopSynologyLogFallback();
sendWs({ type: 'synology_log', open: true });
}
});
state.ws.addEventListener('message', event => {
@@ -1184,6 +1204,11 @@
return;
}
if (message?.type === 'synology_log') {
renderSynologyLog(message.data || {});
return;
}
if (message?.type === 'error') {
console.error(message.message || 'websocket error');
}
@@ -1195,6 +1220,9 @@
if (state.dmesgOpen) {
startDmesgFallback();
}
if (state.synologyLogOpen) {
startSynologyLogFallback();
}
const delay = state.wsReconnectDelay;
state.wsReconnectDelay = Math.min(15000, state.wsReconnectDelay * 1.7);
state.wsReconnectTimer = setTimeout(connectControlSocket, delay);
@@ -2554,6 +2582,84 @@
}
}
function scrollSynologyLogToTop() {
if (!els.synologyLogOutput) return;
if (els.synologyLogOutput.hidden) return;
if (Date.now() < state.synologyLogScrollHoldUntil) return;
els.synologyLogOutput.scrollTop = 0;
}
function renderSynologyLog(data) {
if (!els.synologyLogOutput || !els.synologyLogMeta) return;
if (Date.now() < state.synologyLogScrollHoldUntil) return;
const scrollTop = els.synologyLogOutput.scrollTop;
if (!data?.available) {
els.synologyLogOutput.textContent = data?.message || t('synologyLogUnavailable');
els.synologyLogMeta.textContent = '/var/log/remote/synology/chaegeon.log unavailable';
return;
}
const lines = data.lines || [];
const latestKey = `${data.line_count || 0}\n${lines[0] || ''}`;
const hasNewLine = state.synologyLogLatestKey !== null && latestKey !== state.synologyLogLatestKey;
els.synologyLogOutput.textContent = lines.join('\n');
els.synologyLogMeta.textContent = `${data.path || '/var/log/remote/synology/chaegeon.log'} · ${data.line_count || 0} lines · updated ${data.updated_at || '-'}`;
state.synologyLogLatestKey = latestKey;
els.synologyLogOutput.scrollTop = Date.now() < state.synologyLogScrollHoldUntil ? scrollTop : 0;
if (hasNewLine) {
requestAnimationFrame(scrollSynologyLogToTop);
}
}
async function refreshSynologyLog() {
if (!state.synologyLogOpen) return;
try {
renderSynologyLog(await api('synology_log'));
} catch (e) {
console.error(e);
if (els.synologyLogOutput) {
els.synologyLogOutput.textContent = e.message || t('synologyLogRefreshFailed');
}
}
}
function stopSynologyLogFallback() {
clearInterval(state.synologyLogTimer);
state.synologyLogTimer = null;
}
function startSynologyLogFallback() {
if (state.synologyLogTimer) return;
refreshSynologyLog();
state.synologyLogTimer = setInterval(refreshSynologyLog, 1000);
}
function setSynologyLogOpen(open) {
state.synologyLogOpen = open;
if (els.synologyLogOutput) {
els.synologyLogOutput.hidden = !open;
}
if (els.synologyLogToggle) {
els.synologyLogToggle.textContent = open ? t('hide') : t('show');
}
stopSynologyLogFallback();
if (open) {
if (!sendWs({ type: 'synology_log', open: true })) {
startSynologyLogFallback();
}
} else {
sendWs({ type: 'synology_log', open: false });
}
}
async function refreshStatus() {
if (state.loading) return;
state.loading = true;
@@ -2697,6 +2803,15 @@
els.dmesgToggle?.addEventListener('click', () => {
setDmesgOpen(!state.dmesgOpen);
});
els.synologyLogToggle?.addEventListener('click', () => {
setSynologyLogOpen(!state.synologyLogOpen);
});
const holdSynologyLogScroll = () => {
state.synologyLogScrollHoldUntil = Date.now() + 4000;
};
['scroll', 'wheel', 'touchstart', 'touchmove', 'pointerdown'].forEach(eventName => {
els.synologyLogOutput?.addEventListener(eventName, holdSynologyLogScroll, { passive: true });
});
const holdCustomServiceScroll = () => {
state.customServiceScrollHoldUntil = Date.now() + 4000;
};
@@ -2776,6 +2891,9 @@
if (state.dmesgOpen && !sendWs({ type: 'dmesg', open: true })) {
refreshDmesg();
}
if (state.synologyLogOpen && !sendWs({ type: 'synology_log', open: true })) {
refreshSynologyLog();
}
}
});
document.addEventListener('keydown', event => {