mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
fix: update CLIFileExistenceChecker to accept containerId in constructor
This commit is contained in:
1 parent
5077f9c677
commit
f7860c6197
2 files changed
+5
-10
No files matched your search
@@ -39,7 +39,7 @@ export const newCommand = asyncHandler(async (req: Request, res: Response) => {
|
||||
const gameSession = new GameSession(
|
||||
session,
|
||||
quest,
|
||||
new CLIFileExistenceChecker()
|
||||
new CLIFileExistenceChecker(session.containerId!)
|
||||
)
|
||||
|
||||
const event = await gameSession.runCommand(command)
|
||||
|
||||
@@ -7,14 +7,15 @@ function sanitizeId(id: string) {
|
||||
return id.replace(/[^a-zA-Z0-9]/g, '')
|
||||
}
|
||||
|
||||
// eslint-disable-next-line import/prefer-default-export
|
||||
export function checkFile(id: string, file: IFileInput) {
|
||||
export class CLIFileExistenceChecker implements IFileExistenceChecker {
|
||||
constructor(private readonly containerId: string) {}
|
||||
exists(file: IFileInput) {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
const cmd = buildFileCheckCmd(file)
|
||||
// WARNING: This is vulnerable to command injection
|
||||
execFile(
|
||||
'docker',
|
||||
['exec', sanitizeId(id), ...cmd],
|
||||
['exec', sanitizeId(this.containerId), ...cmd],
|
||||
{ timeout: 1000 },
|
||||
(error) => {
|
||||
const exists = !error
|
||||
@@ -23,10 +24,4 @@ export function checkFile(id: string, file: IFileInput) {
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
export class CLIFileExistenceChecker implements IFileExistenceChecker {
|
||||
// eslint-disable-next-line class-methods-use-this
|
||||
async exists(file: IFileInput) {
|
||||
return checkFile(file.path, file)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user