mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
wip: get active session
This commit is contained in:
1 parent
423548804a
commit
963655c1f7
7 files changed
+69
-12
No files matched your search
@@ -1,6 +1,6 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { FileGraph, FileObject } from '@linux-odyssey/file-graph'
|
import { FileGraph, FileObject } from '@linux-odyssey/file-graph'
|
||||||
import { QuestDetailResponse } from '@linux-odyssey/constants'
|
import { QuestDetailResponse } from '../../../packages/constants/dist/src'
|
||||||
import { createSession, getActiveSession } from '../utils/api'
|
import { createSession, getActiveSession } from '../utils/api'
|
||||||
import Socket from '../utils/socket'
|
import Socket from '../utils/socket'
|
||||||
import SocketTerminal from '../utils/terminal'
|
import SocketTerminal from '../utils/terminal'
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import axios from 'axios'
|
import axios from 'axios'
|
||||||
import { GetSessionsRequest } from '@linux-odyssey/constants'
|
|
||||||
import { Session } from '../types'
|
import { Session } from '../types'
|
||||||
|
|
||||||
const api = axios.create({
|
const api = axios.create({
|
||||||
@@ -16,13 +15,6 @@ export async function createSession(questId: string): Promise<Session> {
|
|||||||
return res.data
|
return res.data
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSessions(
|
|
||||||
request: GetSessionsRequest
|
|
||||||
): Promise<Session[]> {
|
|
||||||
const res = await api.get<Session[]>('/sessions', { params: request })
|
|
||||||
return res.data
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getActiveSession(
|
export async function getActiveSession(
|
||||||
questId: string
|
questId: string
|
||||||
): Promise<Session | null> {
|
): Promise<Session | null> {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import validator from 'validator'
|
import validator from 'validator'
|
||||||
import { isValidUsername } from '@linux-odyssey/utils'
|
import { isValidUsername } from '@linux-odyssey/utils'
|
||||||
import { passwordPolicy } from '@linux-odyssey/constants'
|
import { passwordPolicy } from '../../../packages/constants/dist/src'
|
||||||
import AuthForm from '../components/AuthForm.vue'
|
import AuthForm from '../components/AuthForm.vue'
|
||||||
import DynamicBackground from '../components/DynamicBackground.vue'
|
import DynamicBackground from '../components/DynamicBackground.vue'
|
||||||
import HeaderPart from '../components/header/HeaderPart.vue'
|
import HeaderPart from '../components/header/HeaderPart.vue'
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { z } from 'zod'
|
import { z } from 'zod'
|
||||||
|
|
||||||
export * from './src/quest.js'
|
export * from './quest.js'
|
||||||
|
export * from './session.js'
|
||||||
|
|
||||||
export const passwordPolicy = {
|
export const passwordPolicy = {
|
||||||
minLength: 8,
|
minLength: 8,
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
export interface SessionSummaryResponse {
|
||||||
|
_id: string
|
||||||
|
user: string
|
||||||
|
quest: string
|
||||||
|
status: string
|
||||||
|
createdAt: Date
|
||||||
|
lastActivityAt: Date
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SessionDetailResponse extends SessionSummaryResponse {
|
||||||
|
hints: string[][]
|
||||||
|
tasks: string[][]
|
||||||
|
responses: string[][]
|
||||||
|
graph: any
|
||||||
|
}
|
||||||
@@ -4,7 +4,8 @@
|
|||||||
"composite": true,
|
"composite": true,
|
||||||
"module": "Node16",
|
"module": "Node16",
|
||||||
"moduleResolution": "node16",
|
"moduleResolution": "node16",
|
||||||
"outDir": "./dist"
|
"outDir": "./dist",
|
||||||
|
"rootDir": "src"
|
||||||
},
|
},
|
||||||
"include": ["*.js", "*.ts", "src/**/*.ts"],
|
"include": ["*.js", "*.ts", "src/**/*.ts"],
|
||||||
"exclude": ["node_modules", "dist"]
|
"exclude": ["node_modules", "dist"]
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import { TRPCError } from '@trpc/server'
|
||||||
|
import { Session } from '@linux-odyssey/models'
|
||||||
|
import { z } from 'zod'
|
||||||
|
import { isQuestUnlocked } from '../models/sessionManager.js'
|
||||||
|
import config from '../config.js'
|
||||||
|
import { protectedProcedure, router } from '../trpc.js'
|
||||||
|
|
||||||
|
export const sessionRouter = router({
|
||||||
|
getActiveSession: protectedProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
questId: z.string(),
|
||||||
|
})
|
||||||
|
)
|
||||||
|
.query(async (opts) => {
|
||||||
|
const { questId } = opts.input
|
||||||
|
const { user } = opts.ctx
|
||||||
|
if (
|
||||||
|
user &&
|
||||||
|
((await isQuestUnlocked(user, questId)) || config.testing.enabled)
|
||||||
|
) {
|
||||||
|
const session = await Session.findOne({
|
||||||
|
user: user.id,
|
||||||
|
quest: questId,
|
||||||
|
status: 'active',
|
||||||
|
})
|
||||||
|
if (!session) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
_id: session._id.toString(),
|
||||||
|
user: session.user,
|
||||||
|
quest: session.quest,
|
||||||
|
status: session.status,
|
||||||
|
createdAt: session.createdAt,
|
||||||
|
lastActivityAt: session.lastActivityAt,
|
||||||
|
hints: session.hints,
|
||||||
|
tasks: session.tasks,
|
||||||
|
responses: session.responses,
|
||||||
|
graph: session.graph,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new TRPCError({
|
||||||
|
code: 'BAD_REQUEST',
|
||||||
|
message: 'Quest is locked',
|
||||||
|
})
|
||||||
|
}),
|
||||||
|
})
|
||||||
Reference in new issue
Block a user