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