config.ts 1016 B

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