b10ba1dcc2
* First pass at displaying user data in admin * Hide chat blurb on home page if chat is disabled * Hide sidebar chat section if chat is disabled * Block/unblock user interface for https://github.com/owncast/owncast/issues/1096 * Simplify past display name handling * Updates to reflect the api access token change * Update paths * Clean up the new access token page * Fix linter * Update linter workflow action * Cleanup * Fix exception rendering table row * Commit next-env file that seems to be required with next 11 * chat refactor - admin adjustments (#250) * add useragent parser; clean up some html; * some ui changes - use modal instead of popover to confirm block/unblock user - update styles, table styles for consistency - rename some user/chat labels in nav and content * format user info modal a bit * add some sort of mild treatment and delay while processing ban of users * rename button to 'ban' * add some notes * Prettified Code! * fix disableChat toggle for nav bar * Support sorting the disabled user list * Fix linter error around table sorting * No longer restoring messages on unban so change message prompt * Standardize on forbiddenUsername terminology * The linter broke the webhooks page. Fixed it. Linter is probably pissed. * Move chat welcome message to chat config * Other submenus don't have icons so remove these ones Co-authored-by: gingervitis <omqmail@gmail.com> Co-authored-by: gabek <gabek@users.noreply.github.com>
62 lines
1.9 KiB
TypeScript
62 lines
1.9 KiB
TypeScript
import UAParser from 'ua-parser-js';
|
|
|
|
export function formatIPAddress(ipAddress: string): string {
|
|
const ipAddressComponents = ipAddress.split(':');
|
|
|
|
// Wipe out the port component
|
|
ipAddressComponents[ipAddressComponents.length - 1] = '';
|
|
|
|
let ip = ipAddressComponents.join(':');
|
|
ip = ip.slice(0, ip.length - 1);
|
|
if (ip === '[::1]' || ip === '127.0.0.1') {
|
|
return 'Localhost';
|
|
}
|
|
|
|
return ip;
|
|
}
|
|
|
|
// check if obj is {}
|
|
export function isEmptyObject(obj) {
|
|
return !obj || (Object.keys(obj).length === 0 && obj.constructor === Object);
|
|
}
|
|
|
|
export function padLeft(text, pad, size) {
|
|
return String(pad.repeat(size) + text).slice(-size);
|
|
}
|
|
|
|
export function parseSecondsToDurationString(seconds = 0) {
|
|
const finiteSeconds = Number.isFinite(+seconds) ? Math.abs(seconds) : 0;
|
|
|
|
const days = Math.floor(finiteSeconds / 86400);
|
|
const daysString = days > 0 ? `${days} day${days > 1 ? 's' : ''} ` : '';
|
|
|
|
const hours = Math.floor((finiteSeconds / 3600) % 24);
|
|
const hoursString = hours || days ? padLeft(`${hours}:`, '0', 3) : '';
|
|
|
|
const mins = Math.floor((finiteSeconds / 60) % 60);
|
|
const minString = padLeft(`${mins}:`, '0', 3);
|
|
|
|
const secs = Math.floor(finiteSeconds % 60);
|
|
const secsString = padLeft(`${secs}`, '0', 2);
|
|
|
|
return daysString + hoursString + minString + secsString;
|
|
}
|
|
|
|
export function makeAndStringFromArray(arr: string[]): string {
|
|
if (arr.length === 1) return arr[0];
|
|
const firsts = arr.slice(0, arr.length - 1);
|
|
const last = arr[arr.length - 1];
|
|
return `${firsts.join(', ')} and ${last}`;
|
|
}
|
|
|
|
export function formatUAstring(uaString: string) {
|
|
const parser = UAParser(uaString);
|
|
const { device, os, browser } = parser;
|
|
const { major: browserVersion, name } = browser;
|
|
const { version: osVersion, name: osName } = os;
|
|
const { model, type } = device;
|
|
const deviceString = model || type ? ` (${model || type})` : '';
|
|
return `${name} ${browserVersion} on ${osName} ${osVersion}
|
|
${deviceString}`;
|
|
}
|