mirror of
https://gitlab.com/MrFry/mrfrys-node-server
synced 2025-04-01 20:24:18 +02:00
p2p fixes
This commit is contained in:
parent
2edc87d5dd
commit
16d6f04936
17 changed files with 707 additions and 582 deletions
|
@ -504,7 +504,7 @@ export function loadJSON(
|
|||
|
||||
if (!utils.FileExists(dataPath)) {
|
||||
logger.Log(
|
||||
`${dataPath} data file did not exist, created empty one!`,
|
||||
`${dataPath} data file does not exist, created empty one!`,
|
||||
'yellowbg'
|
||||
)
|
||||
utils.WriteFile(JSON.stringify([]), dataPath)
|
||||
|
@ -513,7 +513,6 @@ export function loadJSON(
|
|||
try {
|
||||
acc.push({
|
||||
...dataFile,
|
||||
path: dataPath,
|
||||
index: index,
|
||||
data: loadData(dataPath),
|
||||
})
|
||||
|
@ -529,8 +528,8 @@ export function loadJSON(
|
|||
|
||||
const { subjCount, questionCount } = countOfQdbs(res)
|
||||
logger.Log(
|
||||
`Loaded ${subjCount} subjects with ${questionCount} questions from ${res.length} question db-s`,
|
||||
logger.GetColor('green')
|
||||
`Loaded ${subjCount.toLocaleString()} subjects with ${questionCount.toLocaleString()} questions from ${res.length.toLocaleString()} question db-s`,
|
||||
'blue'
|
||||
)
|
||||
|
||||
return res
|
||||
|
@ -565,10 +564,7 @@ export function backupData(questionDbs: Array<QuestionDb>): void {
|
|||
// logger.Log(`Backing up ${data.name}...`)
|
||||
writeData(
|
||||
data.data,
|
||||
`${path}${data.name}_${utils.GetDateString(
|
||||
undefined,
|
||||
true
|
||||
)}.json`
|
||||
`${path}${data.name}_${utils.GetDateString()}.json`
|
||||
)
|
||||
// logger.Log('Done')
|
||||
} catch (err) {
|
||||
|
|
|
@ -421,12 +421,13 @@ function C(color?: string): string {
|
|||
|
||||
function logTable(
|
||||
table: (string | number)[][],
|
||||
options: { colWidth?: number[] } = {}
|
||||
options: { colWidth?: number[]; rowPrefix?: string } = {}
|
||||
): void {
|
||||
const { colWidth, rowPrefix } = options
|
||||
|
||||
table.forEach((row, i) => {
|
||||
const rowString: string[] = []
|
||||
row.forEach((cell, j) => {
|
||||
const { colWidth } = options
|
||||
const cellColor = j === 0 || i === 0 ? 'blue' : 'green'
|
||||
let cellVal = ''
|
||||
if (!isNaN(+cell)) {
|
||||
|
@ -447,7 +448,7 @@ function logTable(
|
|||
|
||||
rowString.push(C(cellColor) + cellVal + C())
|
||||
})
|
||||
Log(rowString.join('\t'))
|
||||
Log((rowPrefix || '') + rowString.join('\t'))
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue