BackupLoader.js 940 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import {FsUtils} from "../lib/FsUtils";
  2. import {CardsStorage} from "../utils/CardsStorage";
  3. import {CardTypes} from "../utils/database";
  4. export function loadBackup(storage) {
  5. // Fetch file content
  6. const path = FsUtils.fullPath('backup.txt');
  7. const backupData = FsUtils.fetchTextFile(path).split("\n");
  8. console.log("LOAD BACKUP", backupData);
  9. for(let row of backupData) {
  10. let card = {},
  11. parts = row.substring(1).split(";");
  12. if(row[0] == "0") {
  13. const typeInfo = CardTypes[parts[0]];
  14. card = {
  15. format: typeInfo.format,
  16. icon: parts[0],
  17. content: parts[1]
  18. };
  19. } else if (row[0] == "1") {
  20. card = {
  21. icon: "",
  22. title: parts[0],
  23. content: parts[1],
  24. format: parts[2],
  25. color: parseInt(parts[3])
  26. };
  27. } else continue;
  28. card.filename = `card_${Math.round(Math.random() * 1e8)}.png`;
  29. card.index = storage.data.length;
  30. storage.data.push(card);
  31. }
  32. storage._write();
  33. hmFS.remove(path);
  34. }