Skip to content

Commit

Permalink
Improve UserAgent readability
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Oct 25, 2024
1 parent c13b4c3 commit 57c1437
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"tailwindcss": "3.4.14",
"tslib": "^2.8.0",
"typescript": "^5.6.3",
"ua-parser-js": "^2.0.0-beta.3",
"vite-plugin-mkcert": "^1.17.6",
"vite-plugin-tailwind-purgecss": "0.3.3",
"vitest": "^2.1.3"
Expand Down
9 changes: 9 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 14 additions & 2 deletions src/routes/(authenticated)/settings/sessions/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import { elapsedToString } from '$lib/utils/time';
import { escapeHtml } from '$lib/utils/encoding';
import { getModalStore } from '@skeletonlabs/skeleton';
import { UAParser } from 'ua-parser-js';
const modalStore = getModalStore();
Expand Down Expand Up @@ -47,6 +48,17 @@
}
}
function getReadableName(userAgent: string | null): string {
if (!userAgent) return 'Unknown';
const ua = new UAParser(userAgent);
const browser = ua.getBrowser();
const os = ua.getOS();
return `${browser.name} on ${os.name} ${os.version}`;
}
listSessions();
</script>

Expand All @@ -63,7 +75,7 @@
<table class="table table-hover">
<thead>
<tr>
<th>User-Agent</th>
<th>UserAgent</th>
<th>Created</th>
<th>Last Seen</th>
<th>Expires</th>
Expand All @@ -74,7 +86,7 @@
<tbody>
{#each sessions as row (row.id)}
<tr>
<td>{row.userAgent}</td>
<td title={row.userAgent}>{getReadableName(row.userAgent)}</td>
<td title={row.created.toLocaleString()}>{row.created.toLocaleDateString()}</td>

<!--
Expand Down

0 comments on commit 57c1437

Please sign in to comment.