mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
fix: update project root detection and quest directory path (#181)
This commit is contained in:
3 files changed
+25
-7
No files matched your search
@@ -8,7 +8,12 @@ import { questManager } from '../../models/quest'
|
||||
import { CLIFileExistenceChecker } from '../../containers/cli'
|
||||
|
||||
export const newCommand = asyncHandler(async (req: Request, res: Response) => {
|
||||
const command = commandSchema.parse(req.body)
|
||||
const body = commandSchema.safeParse(req.body)
|
||||
if (!body.success) {
|
||||
res.status(400).json({ message: 'Invalid command', errors: body.error })
|
||||
return
|
||||
}
|
||||
const command = body.data
|
||||
|
||||
const { sessionId } = req.user as any
|
||||
const session = await Session.findById(sessionId)
|
||||
@@ -40,10 +45,10 @@ export const newCommand = asyncHandler(async (req: Request, res: Response) => {
|
||||
new CLIFileExistenceChecker(session.containerId!)
|
||||
)
|
||||
|
||||
const event = await gameSession.runCommand(command)
|
||||
const event = await gameSession.runCommand(body)
|
||||
|
||||
const c = new Command({
|
||||
...command,
|
||||
...body,
|
||||
session: sessionId,
|
||||
stage: event,
|
||||
})
|
||||
|
||||
+15
-3
@@ -1,8 +1,9 @@
|
||||
import validator from 'validator'
|
||||
import { config as dotenvConfig } from 'dotenv'
|
||||
import path from 'path'
|
||||
import { get } from './utils/env.js'
|
||||
import fs from 'fs'
|
||||
import { loadOrCreateKeyPair } from './utils/crypto.js'
|
||||
import { get } from './utils/env.js'
|
||||
|
||||
// Import dotenv and load ../.env
|
||||
dotenvConfig({ path: '../.env' })
|
||||
@@ -92,8 +93,19 @@ function createConfig() {
|
||||
}
|
||||
|
||||
function getProjectRoot(): string {
|
||||
const root = path.join(path.dirname(__filename), '..', '..')
|
||||
return root
|
||||
// Start from the current file's directory
|
||||
let currentDir = __dirname
|
||||
|
||||
// Keep going up until we find the root package.json with workspaces
|
||||
while (currentDir !== path.parse(currentDir).root) {
|
||||
const packageJsonPath = path.join(currentDir, 'package.json')
|
||||
if (fs.existsSync(packageJsonPath)) {
|
||||
return path.join(currentDir, '..')
|
||||
}
|
||||
currentDir = path.dirname(currentDir)
|
||||
}
|
||||
|
||||
throw new Error('Could not find project root directory')
|
||||
}
|
||||
|
||||
const config = createConfig()
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
IQuest,
|
||||
} from '../../../packages/game'
|
||||
import logger from '../utils/logger.js'
|
||||
import config from '../config.js'
|
||||
|
||||
class QuestValidationError extends Error {
|
||||
questId: string
|
||||
@@ -37,7 +38,7 @@ class QuestValidationError extends Error {
|
||||
|
||||
class QuestManager {
|
||||
private quests = new Map<string, IQuest>()
|
||||
private questDirectory = path.join(process.cwd(), '..', 'quests')
|
||||
private questDirectory = path.join(config.projectRoot, 'quests')
|
||||
|
||||
get(id: string) {
|
||||
return this.quests.get(id)
|
||||
|
||||
Reference in new issue
Block a user