p2p fixes

This commit is contained in:
mrfry
2023-03-26 19:11:07 +02:00
parent 2edc87d5dd
commit 16d6f04936
17 changed files with 707 additions and 582 deletions
+30
View File
@@ -37,12 +37,16 @@ export default {
renameFile: renameFile,
deleteDir: deleteDir,
formatBytes: formatBytes,
getGitRevision: getGitRevision,
getScriptVersion: getScriptVersion,
}
import * as child_process from 'child_process'
import fs from 'fs'
import { v4 as uuidv4 } from 'uuid'
import logger from '../utils/logger'
import constants from '../constants.json'
import { Request } from '../types/basicTypes'
interface URLFormatOptions {
@@ -309,3 +313,29 @@ function formatBytes(number: number, unit: 'MB' | 'GB' = 'MB'): string {
}
return `${number} byte`
}
function getGitRevision(dir: string): string {
try {
return child_process
.execSync('git rev-parse HEAD', {
cwd: dir,
stdio: [0, 'pipe', null],
})
.toString()
.trim()
} catch (e) {
return 'Failed to get revision'
}
}
function getScriptVersion(): string {
const scriptContent = ReadFile(constants.moodleTestUserscriptPath)
let temp: string | string[] = scriptContent.split('\n').find((x) => {
return x.includes('@version')
})
temp = temp.split(' ')
temp = temp[temp.length - 1]
return temp
}