mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
auto connect session, create session after button
This commit is contained in:
1 parent
ea2ba2c7a0
commit
15465feda9
2 files changed
+40
-25
No files matched your search
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { useToast } from 'vue-toastification'
|
||||
import { ref } from 'vue'
|
||||
import { init, setQuest } from '../../store/session'
|
||||
import { getActiveSession, setQuest, createSession } from '../../store/session'
|
||||
import { LoadQuestError, LoadSessionError } from '../../utils/errors'
|
||||
|
||||
const props = defineProps({
|
||||
@@ -12,12 +12,12 @@ const props = defineProps({
|
||||
})
|
||||
|
||||
const toast = useToast()
|
||||
const showCover = ref(true)
|
||||
setQuest(props.questId)
|
||||
const startSession = async () => {
|
||||
showCover.value = false
|
||||
const showCover = ref(false)
|
||||
|
||||
function init(questId: string) {
|
||||
if (!questId) throw new Error('No quest ID provided')
|
||||
try {
|
||||
await init(props.questId)
|
||||
getActiveSession(props.questId)
|
||||
} catch (err: any) {
|
||||
if (err instanceof LoadQuestError) {
|
||||
toast.error(`無法讀取關卡: ${err.questId},請確認網頁連結。`)
|
||||
@@ -27,6 +27,20 @@ const startSession = async () => {
|
||||
toast.error(`無法建立工作階段: ${err.questId},請重新登入再試一次。`)
|
||||
return
|
||||
}
|
||||
console.error(err)
|
||||
toast.warning('Failed to connect previous session. Creating a new one...')
|
||||
showCover.value = true
|
||||
}
|
||||
}
|
||||
|
||||
init(props.questId)
|
||||
setQuest(props.questId)
|
||||
|
||||
const startSession = async () => {
|
||||
showCover.value = false
|
||||
try {
|
||||
createSession()
|
||||
} catch (err: any) {
|
||||
console.error(err)
|
||||
toast.error(err.message)
|
||||
}
|
||||
|
||||
+20
-19
@@ -80,14 +80,15 @@ export async function createSession() {
|
||||
}
|
||||
}
|
||||
|
||||
async function getActiveSession(questId: string) {
|
||||
export async function getActiveSession(questId: string) {
|
||||
try {
|
||||
const res = await api.post('/sessions/active', { questId })
|
||||
await setSession(res.data)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
toast.warning('Failed to connect previous session. Creating a new one...')
|
||||
await createSession()
|
||||
throw new LoadSessionError('Failed to load session', questId)
|
||||
// toast.warning('Failed to connect previous session. Creating a new one...')
|
||||
// await createSession()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,22 +120,22 @@ export function reset() {
|
||||
store.quest = null
|
||||
}
|
||||
|
||||
export async function init(questId: string) {
|
||||
if (!questId) throw new Error('No quest ID provided')
|
||||
// reset()
|
||||
// try {
|
||||
// await setQuest(questId)
|
||||
// } catch (err) {
|
||||
// console.error(err)
|
||||
// throw new LoadQuestError('Failed to load quest', questId)
|
||||
// }
|
||||
try {
|
||||
await getActiveSession(questId)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
throw new LoadSessionError('Failed to load session', questId)
|
||||
}
|
||||
}
|
||||
// export async function init(questId: string) {
|
||||
// if (!questId) throw new Error('No quest ID provided')
|
||||
// reset()
|
||||
// try {
|
||||
// await setQuest(questId)
|
||||
// } catch (err) {
|
||||
// console.error(err)
|
||||
// throw new LoadQuestError('Failed to load quest', questId)
|
||||
// }
|
||||
// try {
|
||||
// await getActiveSession(questId)
|
||||
// } catch (err) {
|
||||
// console.error(err)
|
||||
// throw new LoadSessionError('Failed to load session', questId)
|
||||
// }
|
||||
// }
|
||||
|
||||
function setup() {
|
||||
socket.on('terminal', (data: string) => {
|
||||
|
||||
Reference in new issue
Block a user