mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
Fix sessions (#2689)
* add loggedIn key to sessions * show loggedIn timestamp in list * don't double hash active session --------- Co-authored-by: Aiden McClelland <me@drbonez.dev>
This commit is contained in:
@@ -350,13 +350,13 @@ pub async fn list(
|
||||
ListParams { session, .. }: ListParams,
|
||||
) -> Result<SessionList, Error> {
|
||||
let mut sessions = ctx.db.peek().await.into_private().into_sessions().de()?;
|
||||
ctx.ephemeral_sessions.mutate(|s| {
|
||||
ctx.ephemeral_sessions.peek(|s| {
|
||||
sessions
|
||||
.0
|
||||
.extend(s.0.iter().map(|(k, v)| (k.clone(), v.clone())))
|
||||
});
|
||||
Ok(SessionList {
|
||||
current: HashSessionToken::from_token(session).hashed().clone(),
|
||||
current: session,
|
||||
sessions,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -6,4 +6,7 @@ impl<T> SyncMutex<T> {
|
||||
pub fn mutate<F: FnOnce(&mut T) -> U, U>(&self, f: F) -> U {
|
||||
f(&mut *self.0.lock().unwrap())
|
||||
}
|
||||
pub fn peek<F: FnOnce(&T) -> U, U>(&self, f: F) -> U {
|
||||
f(&*self.0.lock().unwrap())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,8 +52,15 @@
|
||||
></ion-icon>
|
||||
<ion-label>
|
||||
<h1>{{ getPlatformName(currentSession.metadata.platforms) }}</h1>
|
||||
<h2>Last Active: {{ currentSession.lastActive| date : 'medium' }}</h2>
|
||||
<p>{{ currentSession.userAgent }}</p>
|
||||
<h2 *ngIf="currentSession.userAgent as agent">{{ agent }}</h2>
|
||||
<p>
|
||||
<b>First Seen</b>
|
||||
: {{ currentSession.loggedIn| date : 'medium' }}
|
||||
</p>
|
||||
<p>
|
||||
<b>Last Active</b>
|
||||
: {{ currentSession.lastActive| date : 'medium' }}
|
||||
</p>
|
||||
</ion-label>
|
||||
</ion-item>
|
||||
|
||||
@@ -78,8 +85,15 @@
|
||||
></ion-icon>
|
||||
<ion-label>
|
||||
<h1>{{ getPlatformName(session.metadata.platforms) }}</h1>
|
||||
<h2>Last Active: {{ session.lastActive | date : 'medium' }}</h2>
|
||||
<p>{{ session.userAgent }}</p>
|
||||
<h2 *ngIf="currentSession.userAgent as agent">{{ agent }}</h2>
|
||||
<p>
|
||||
<b>First Seen</b>
|
||||
: {{ currentSession.loggedIn| date : 'medium' }}
|
||||
</p>
|
||||
<p>
|
||||
<b>Last Active</b>
|
||||
: {{ currentSession.lastActive| date : 'medium' }}
|
||||
</p>
|
||||
</ion-label>
|
||||
<ion-button
|
||||
slot="end"
|
||||
|
||||
@@ -27,17 +27,11 @@ export class SessionsPage {
|
||||
this.currentSession = sessionInfo.sessions[sessionInfo.current]
|
||||
delete sessionInfo.sessions[sessionInfo.current]
|
||||
this.otherSessions = Object.entries(sessionInfo.sessions)
|
||||
.map(([id, session]) => {
|
||||
return {
|
||||
id,
|
||||
...session,
|
||||
}
|
||||
})
|
||||
.sort((a, b) => {
|
||||
return (
|
||||
new Date(b.lastActive).valueOf() - new Date(a.lastActive).valueOf()
|
||||
)
|
||||
})
|
||||
.map(([id, session]) => ({ id, ...session }))
|
||||
.sort(
|
||||
(a, b) =>
|
||||
new Date(b.lastActive).valueOf() - new Date(a.lastActive).valueOf(),
|
||||
)
|
||||
} catch (e: any) {
|
||||
this.errorService.handleError(e)
|
||||
} finally {
|
||||
@@ -108,10 +102,6 @@ export class SessionsPage {
|
||||
return 'Unknown Device'
|
||||
}
|
||||
}
|
||||
|
||||
asIsOrder(a: any, b: any) {
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
interface SessionWithId extends Session {
|
||||
|
||||
@@ -924,6 +924,7 @@ export module Mock {
|
||||
current: 'b7b1a9cef4284f00af9e9dda6e676177',
|
||||
sessions: {
|
||||
'9513226517c54ddd8107d6d7b9d8aed7': {
|
||||
loggedIn: '2021-07-14T20:49:17.774Z',
|
||||
lastActive: '2021-07-14T20:49:17.774Z',
|
||||
userAgent: 'AppleWebKit/{WebKit Rev} (KHTML, like Gecko)',
|
||||
metadata: {
|
||||
@@ -931,6 +932,7 @@ export module Mock {
|
||||
},
|
||||
},
|
||||
b7b1a9cef4284f00af9e9dda6e676177: {
|
||||
loggedIn: '2021-07-14T20:49:17.774Z',
|
||||
lastActive: '2021-06-14T20:49:17.774Z',
|
||||
userAgent:
|
||||
'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0',
|
||||
|
||||
@@ -354,6 +354,7 @@ export interface Metric {
|
||||
}
|
||||
|
||||
export interface Session {
|
||||
loggedIn: string
|
||||
lastActive: string
|
||||
userAgent: string
|
||||
metadata: SessionMetadata
|
||||
|
||||
Reference in New Issue
Block a user