Refactoring and small optimizations

This commit is contained in:
2022-01-30 12:18:36 +01:00
parent 9dcfade3fd
commit 33d567aaed
10 changed files with 91 additions and 34 deletions

View File

@@ -12,9 +12,9 @@ class Logger {
* @param {string} proto the context/protocol/section outputting the message
* @param {string} args the acutal message
*/
info(proto: string, args: string) {
public info(proto: string, args: string) {
process.stdout.write(
this.#__formatter(proto, args)
this.formatter(proto, args)
)
}
/**
@@ -22,9 +22,9 @@ class Logger {
* @param {string} proto the context/protocol/section outputting the message
* @param {string} args the acutal message
*/
warn(proto: string, args: string) {
public warn(proto: string, args: string) {
process.stdout.write(
`${ansi.yellow}${this.#__formatter(proto, args)}${ansi.reset}`
`${ansi.yellow}${this.formatter(proto, args)}${ansi.reset}`
)
}
/**
@@ -32,13 +32,13 @@ class Logger {
* @param {string} proto the context/protocol/section outputting the message
* @param {string} args the acutal message
*/
err(proto: string, args: string) {
public err(proto: string, args: string) {
process.stdout.write(
`${ansi.red}${this.#__formatter(proto, args)}${ansi.reset}`
`${ansi.red}${this.formatter(proto, args)}${ansi.reset}`
)
}
#__formatter(proto: any, args: any) {
private formatter(proto: any, args: any) {
return `[${proto}]\t${args}\n`
}
}

View File

@@ -1,6 +1,6 @@
import { spawn } from 'child_process';
import { exec, spawn } from 'child_process';
import fs = require('fs');
import net = require('net');
// import net = require('net');
import { logger } from './logger';
/**
@@ -39,3 +39,11 @@ export async function killProcess(pid: number) {
logger('proc', `Successfully killed yt-dlp process, pid: ${pid}`)
})
}
export function getFreeDiskSpace(socket: any) {
let buffer: string = '';
let message: string = 'free-space';
exec("df -h / | tail -1 | awk '{print $4}'", (_, stdout) => {
socket.emit(message, stdout)
})
}