mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
Feat filegraph (#194)
* feat: update filegraph on touch command * feat: update filegraph on mkdir * feat: add different parsing opts for each command * refactor: replace axios with fetch. put handleCommand to a new file * feat: add config for mounting cli in dev stage * refactor: clean up unused validators * feat: add command handler for copy files. reuse resolvePath function * feat: add rm handler, support specific files deletion. Glob not supported yet * feat: handle discover cases that the folder is actually empty * feat: handle discover empty folder better and support rmdir * feat: handle mv command * refactor: remove unused console logs
This commit is contained in:
1 parent
a732c1d119
commit
f0a09ac4d9
19 files changed
+326
-119
No files matched your search
@@ -1,9 +1,8 @@
|
||||
import { Router } from 'express'
|
||||
import * as commandController from '../controllers/commandController.js'
|
||||
import { newCommandValidator } from '../validators/commandValidator.js'
|
||||
|
||||
const router = Router()
|
||||
|
||||
router.post('/', newCommandValidator, commandController.newCommand)
|
||||
router.post('/', commandController.newCommand)
|
||||
|
||||
export default router
|
||||
@@ -1,17 +0,0 @@
|
||||
import { body } from 'express-validator'
|
||||
import { noError } from '../../middleware/validator.js'
|
||||
|
||||
const checkCommand = () => body('command').isString().notEmpty().trim()
|
||||
const checkPwd = () => body('pwd').isString().notEmpty().trim()
|
||||
const checkOutput = () => body('output').trim().optional()
|
||||
const checkError = () => body('error').trim().optional()
|
||||
const checkParams = () => body('params').isObject().optional()
|
||||
|
||||
export const newCommandValidator = [
|
||||
checkCommand(),
|
||||
checkPwd(),
|
||||
checkOutput(),
|
||||
checkError(),
|
||||
checkParams(),
|
||||
noError,
|
||||
]
|
||||
@@ -1,7 +0,0 @@
|
||||
import { check } from 'express-validator'
|
||||
import { noError } from '../../middleware/validator.js'
|
||||
|
||||
export const checkQuestId = () =>
|
||||
check('questId').notEmpty().isString().isLowercase().isLength({ max: 64 })
|
||||
|
||||
export const questIdValidator = [checkQuestId(), noError]
|
||||
@@ -1,14 +0,0 @@
|
||||
import { check } from 'express-validator'
|
||||
import { checkQuestId } from './questValidator.js'
|
||||
import { noError } from '../../middleware/validator.js'
|
||||
|
||||
const checkSessionStatus = () =>
|
||||
check('status').isString().isIn(['active', 'inactive', 'finished'])
|
||||
|
||||
export const checkSessionId = () =>
|
||||
check('sessionId').notEmpty().isString().isMongoId()
|
||||
|
||||
export const sessionListValidator = [checkQuestId(), checkSessionStatus()]
|
||||
export const sessionDetailValidator = [checkSessionId()]
|
||||
export const createSessionValidator = [checkQuestId(), noError]
|
||||
export const activeSessionValidator = [checkQuestId(), noError]
|
||||
@@ -82,7 +82,8 @@ function createConfig() {
|
||||
network: get('DOCKER_NETWORK', 'linux-odyssey-players-dev'),
|
||||
defaultImage: get('QUEST_IMAGE', 'linuxodyssey/quest-base'),
|
||||
imagePrefix: get('DOCKER_PREFIX', 'linuxodyssey/quest-'),
|
||||
mountQuest: process.env.MOUNT_QUEST === 'true',
|
||||
mountQuest: !isProduction && process.env.MOUNT_QUEST === 'true',
|
||||
mountCLI: !isProduction && process.env.MOUNT_CLI === 'true',
|
||||
hostProjectRoot: get('HOST_PROJECT_ROOT', projectRoot),
|
||||
keypairPath,
|
||||
keypair,
|
||||
|
||||
@@ -39,13 +39,18 @@ export async function createContainer(
|
||||
`${config.docker.hostProjectRoot}/quests/${questId}/home:/etc/skel:ro`
|
||||
)
|
||||
}
|
||||
if (!config.isProduction && config.docker.mountQuest && imageId !== 'base') {
|
||||
if (config.docker.mountQuest && imageId !== 'base') {
|
||||
logger.info('Mounting quest directory', questId)
|
||||
binds = [
|
||||
`${config.docker.hostProjectRoot}/quests/${questId}/home:/home/commander`,
|
||||
`${config.docker.hostProjectRoot}/packages/container:/usr/local/lib/container`,
|
||||
]
|
||||
}
|
||||
if (config.docker.mountCLI) {
|
||||
logger.info('Mounting CLI', questId)
|
||||
binds.push(
|
||||
`${config.docker.hostProjectRoot}/packages/container:/usr/local/lib/container`
|
||||
)
|
||||
}
|
||||
const option = newContainerOptions(name, imageId, { binds })
|
||||
await createNetworkIfNotExists(config.docker.network)
|
||||
return engine.createContainer(option)
|
||||
|
||||
@@ -38,6 +38,7 @@ async function main() {
|
||||
}
|
||||
|
||||
if (config.testing.enabled) {
|
||||
logger.info('Setting up test environment')
|
||||
await setupTest()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user