config.ts 854 B

123456789101112131415161718192021222324252627282930313233
  1. import fs from "fs";
  2. import path from "path";
  3. import moment from "moment";
  4. import env from "./env";
  5. console.log(__dirname);
  6. const configJson = fs.readFileSync(path.join(__dirname, "../config.json"));
  7. const store = JSON.parse(configJson.toString());
  8. export default store;
  9. const timeLog = path.join(__dirname, "../../logs/time.log");
  10. let syncTime = {};
  11. if (fs.existsSync(path.join(__dirname, "../../logs/time.log"))) {
  12. try {
  13. syncTime = fs.readFileSync(timeLog).toJSON();
  14. } catch (err) {
  15. syncTime = {};
  16. }
  17. }
  18. store["syncTime"] = syncTime;
  19. // module.exports = store;
  20. export function updateSyncTime(): void {
  21. if (env.server && env.exam) {
  22. syncTime[env.server.host + "_" + env.exam.id] = moment().format(
  23. "YYYY-MM-DD HH:mm:ss"
  24. );
  25. store["syncTime"] = syncTime;
  26. fs.writeFileSync(timeLog, JSON.stringify(syncTime));
  27. }
  28. }