mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 03:20:13 +08:00
feat: reload all quest on starting
This commit is contained in:
1 parent
3f8bcb5446
commit
3fed851b7b
2 files changed
+12
-13
No files matched your search
@@ -110,6 +110,9 @@ export async function isQuestUnlocked(user, questId) {
|
||||
if (!quest) {
|
||||
throw new Error(`Quest ${questId} not found`)
|
||||
}
|
||||
if (!quest.requirements) {
|
||||
return true
|
||||
}
|
||||
return quest.requirements.every((requiredQuestId) => {
|
||||
const progress = userProfile.progress.get(requiredQuestId)
|
||||
return progress && progress.completed
|
||||
|
||||
@@ -22,7 +22,8 @@ async function mapQuests(callback) {
|
||||
)
|
||||
}
|
||||
|
||||
export function loadAndUpdateQuests() {
|
||||
export async function loadAndUpdateQuests() {
|
||||
await Quest.deleteMany({})
|
||||
return mapQuests(async (id, questPath) => {
|
||||
const files = await fs.readdir(questPath)
|
||||
if (!files.includes('game.yml')) {
|
||||
@@ -32,23 +33,18 @@ export function loadAndUpdateQuests() {
|
||||
try {
|
||||
const body = await fs.readFile(path.join(questPath, 'game.yml'), 'utf-8')
|
||||
|
||||
const quest = yaml.parse(body, {
|
||||
const questData = yaml.parse(body, {
|
||||
merge: true,
|
||||
})
|
||||
|
||||
const image = files.includes('Dockerfile') ? id : 'base'
|
||||
|
||||
return await Quest.findByIdAndUpdate(
|
||||
id,
|
||||
{
|
||||
_id: id,
|
||||
image,
|
||||
...quest,
|
||||
},
|
||||
{
|
||||
upsert: true,
|
||||
}
|
||||
)
|
||||
const quest = new Quest({
|
||||
_id: id,
|
||||
image,
|
||||
...questData,
|
||||
})
|
||||
await quest.save()
|
||||
} catch (error) {
|
||||
console.error(`Error parsing quest ${id}:`, error.message)
|
||||
throw error
|
||||
|
||||
Reference in new issue
Block a user