Skip to content
This repository has been archived by the owner on May 25, 2023. It is now read-only.

Commit

Permalink
Settings reloaded
Browse files Browse the repository at this point in the history
  • Loading branch information
alkihis committed Feb 5, 2021
1 parent 70153a0 commit 6bd6c7f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
9 changes: 7 additions & 2 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import mongoose from 'mongoose';
import Task, { isValidTaskType } from './api/tasks/Task';
import { COLLECTIONS } from './models';
import { purgePartial, getCompleteUserFromTwitterScreenName } from './helpers';
import { TweetCounter } from './constants';
import { reloadSettings, TweetCounter } from './constants';

export const CliSettings = {
db_ok: false
Expand All @@ -17,10 +17,15 @@ export function startCli() {
}

const cli = new CliHelper({
onNoMatch: "Command not recognized.",
onNoMatch: "Command not recognized. Available commands are: reload-settings, coll, exit, task.",
suggestions: true
});

cli.command('reload-settings', () => {
reloadSettings();
return 'Settings reloaded.';
});

const collection = cli.command(
'coll',
(_, __, validator) => validator ? "Available commands for coll: list, drop" : "Can't access collections: Database is not ready.",
Expand Down
16 changes: 14 additions & 2 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,22 @@ import { readFileSync, writeFileSync } from "fs";
import logger from "./logger";
import path from 'path';

export const VERSION = "1.7.2";
export const CONFIG_FILE = JSON.parse(readFileSync(__dirname + "/../settings.json", "utf-8"));
export const VERSION = "1.8.0";
export const CONFIG_FILE: any = {}
export const CLASSIC_ARCHIVE_PATH = path.resolve(__dirname + "/../static/classic_archive.zip");

export function reloadSettings() {
const settings = JSON.parse(readFileSync(__dirname + "/../settings.json", "utf-8"));

for (const key in settings) {
if (settings.hasOwnProperty(key)) {
CONFIG_FILE[key] = settings[key];
}
}
}

reloadSettings();

export const TweetCounter = new class {
protected count_file: { deleted: number };
protected filename = __dirname + "/../misc/deleted_count.json";
Expand Down

0 comments on commit 6bd6c7f

Please sign in to comment.