import { existsSync, readFileSync, readdirSync } from 'fs';
import { dirname, join } from 'path';
import { ApiCall } from "tsrpc";
import { ReqGetLog, ResGetLog } from "../monopoly/protocols/PtlGetLog";

export default async function (call: ApiCall<ReqGetLog, ResGetLog>) {
    let logStr = '';
    let dir = join(dirname(require.main.filename), 'logs');

    if (existsSync(dir)) {
        let files = readdirSync(dir);
        files.forEach(file => {
            logStr += file + ':\n';
            logStr += readFileSync(join(dir, file), 'utf-8') + '\n';
        });
    }

    call.succ(logStr);
}