mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: link error command to session detail page
This commit is contained in:
1 parent
2257b4b809
commit
ad08bde4c4
3 files changed
+30
-2
No files matched your search
@@ -22,6 +22,7 @@ export async function errorCommands() {
|
||||
createdAt: createdAt?.toLocaleString(),
|
||||
user: user?.username,
|
||||
quest,
|
||||
session: session._id,
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Session } from '@linux-odyssey/models'
|
||||
import { Command, Session } from '@linux-odyssey/models'
|
||||
|
||||
export function sessionCount() {
|
||||
return Session.find().count()
|
||||
@@ -51,8 +51,9 @@ export async function sessionList() {
|
||||
},
|
||||
])
|
||||
return sessions.map(
|
||||
({ user, quest, status, createdAt, finishedAt, commands }) => {
|
||||
({ _id, user, quest, status, createdAt, finishedAt, commands }) => {
|
||||
return {
|
||||
_id,
|
||||
user: user.username,
|
||||
quest,
|
||||
status,
|
||||
@@ -64,3 +65,27 @@ export async function sessionList() {
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
export async function sessionDetail(id) {
|
||||
const session = await Session.findById(id).populate('user').exec()
|
||||
const commands = (await Command.find({ session: id })).map(
|
||||
({ command, pwd, output, error, createdAt }) => ({
|
||||
command: command?.slice(0, 20),
|
||||
pwd,
|
||||
output: output?.slice(0, 50),
|
||||
error: error?.slice(0, 50),
|
||||
createdAt: createdAt?.toLocaleString(),
|
||||
})
|
||||
)
|
||||
const { _id, user, quest, status, createdAt, finishedAt } = session
|
||||
return {
|
||||
_id,
|
||||
user: user.username,
|
||||
quest,
|
||||
status,
|
||||
createdAt: createdAt?.toLocaleString(),
|
||||
finishedAt: finishedAt?.toLocaleString(),
|
||||
usedTime: finishedAt ? formatTime(finishedAt - createdAt) : '',
|
||||
commands,
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@
|
||||
<th>Command</th>
|
||||
<th>User</th>
|
||||
<th>Quest</th>
|
||||
<th>Session</th>
|
||||
<th>Error</th>
|
||||
<th>Created At</th>
|
||||
</tr>
|
||||
@@ -14,6 +15,7 @@
|
||||
<td>{{command}}</td>
|
||||
<td>{{user}}</td>
|
||||
<td>{{quest}}</td>
|
||||
<td><a href='/sessions/{{session}}'>Detail</a></td>
|
||||
<td>{{error}}</td>
|
||||
<td>{{createdAt}}</td>
|
||||
</tr>
|
||||
|
||||
Reference in new issue
Block a user