mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-07 19:10:12 +08:00
wip: migrate backend to new game package
This commit is contained in:
1 parent
1d843f7355
commit
1616f62755
94 files changed
+263
-3055
No files matched your search
@@ -1,15 +1,15 @@
|
||||
import { execFile } from 'child_process'
|
||||
|
||||
import { buildFileCheckCmd } from '@linux-odyssey/utils'
|
||||
import type { IFileCondition } from '@linux-odyssey/models'
|
||||
import type { IFileExistenceChecker, IFileInput } from '@linux-odyssey/game'
|
||||
|
||||
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: IFileCondition) {
|
||||
return new Promise((resolve, reject) => {
|
||||
export function checkFile(id: string, file: IFileInput) {
|
||||
return new Promise<boolean>((resolve) => {
|
||||
const cmd = buildFileCheckCmd(file)
|
||||
// WARNING: This is vulnerable to command injection
|
||||
execFile(
|
||||
@@ -18,12 +18,15 @@ export function checkFile(id: string, file: IFileCondition) {
|
||||
{ timeout: 1000 },
|
||||
(error) => {
|
||||
const exists = !error
|
||||
if (exists === file.exists) {
|
||||
resolve(true)
|
||||
} else {
|
||||
reject(new Error('File check failed'))
|
||||
}
|
||||
resolve(exists)
|
||||
}
|
||||
)
|
||||
})
|
||||
}
|
||||
|
||||
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