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