| (function() { | |
| 'use strict'; | |
| window.MediaGatewayUtils = { | |
| formatTime(ts) { | |
| const d = new Date(ts * 1000); | |
| return d.toLocaleTimeString('ja-JP', { | |
| timeZone: 'Asia/Tokyo', | |
| hour: '2-digit', | |
| minute: '2-digit', | |
| hour12: false | |
| }); | |
| }, | |
| formatDate(ts) { | |
| const d = new Date(ts * 1000); | |
| return d.toLocaleDateString('ja-JP', { | |
| timeZone: 'Asia/Tokyo', | |
| year: 'numeric', | |
| month: '2-digit', | |
| day: '2-digit' | |
| }).replace(/\//g, '-'); | |
| }, | |
| formatDuration(sec) { | |
| const h = Math.floor(sec / 3600); | |
| const m = Math.floor((sec % 3600) / 60); | |
| return h > 0 ? `${h}小时${m}分钟` : `${m}分钟`; | |
| }, | |
| formatBytes(b) { | |
| if (b === 0) return '0 B'; | |
| const k = 1024; | |
| const sizes = ['B', 'KB', 'MB', 'GB']; | |
| const i = Math.floor(Math.log(b) / Math.log(k)); | |
| return (b / Math.pow(k, i)).toFixed(2) + ' ' + sizes[i]; | |
| }, | |
| getJSTDate(d) { | |
| if (!d) d = new Date(); | |
| const jst = new Date(d.toLocaleString('en-US', { timeZone: 'Asia/Tokyo' })); | |
| return jst.toISOString().split('T')[0]; | |
| }, | |
| showNotification(msg, type = 'info') { | |
| const old = document.querySelector('.notification'); | |
| if (old) old.remove(); | |
| const n = document.createElement('div'); | |
| n.className = `notification notification-${type}`; | |
| n.textContent = msg; | |
| document.body.appendChild(n); | |
| setTimeout(() => n.remove(), 3000); | |
| }, | |
| async checkAPIStatus() { | |
| try { | |
| const start = Date.now(); | |
| const res = await fetch('/health'); | |
| const time = Date.now() - start; | |
| const data = await res.json(); | |
| return { | |
| success: true, | |
| status: data.status, | |
| responseTime: time, | |
| data: data | |
| }; | |
| } catch (e) { | |
| return { | |
| success: false, | |
| error: e.message | |
| }; | |
| } | |
| } | |
| }; | |
| })(); |