sync.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. var sync_db_list = new Array("term/sync_index.php");
  2. //var sync_db_list = ["doc/sync_index.php", "term/sync_index.php", "usent/sync.php"];
  3. var sync_curr_do_db = 0;
  4. function sync_index_init() {}
  5. function sync_pull() {
  6. sync_curr_do_db = 0;
  7. $("#sync_result").html("working"); //
  8. sync_do_db($("#sync_server_address").val(), $("#sync_local_address").val(), 1);
  9. }
  10. function sync_push() {
  11. sync_curr_do_db = 0;
  12. $("#sync_result").html("working"); //
  13. sync_do_db($("#sync_local_address").val(), $("#sync_server_address").val(), 1);
  14. }
  15. function sync_do_db(src, dest, time = 1) {
  16. $.get(
  17. "sync.php",
  18. {
  19. server: $("#sync_server_address").val(),
  20. localhost: $("#sync_local_address").val(),
  21. path: sync_db_list[sync_curr_do_db],
  22. time: time,
  23. },
  24. function (data) {
  25. let result;
  26. try {
  27. result = JSON.parse(data);
  28. } catch (error) {
  29. console.error(error + " data:" + data);
  30. return;
  31. }
  32. $("#sync_result").html($("#sync_result").html() + "<br>" + result.message + "<br>" + result.row); //
  33. if (result.row == 1000) {
  34. sync_do_db(src, dest, result.time);
  35. } else {
  36. sync_curr_do_db++;
  37. if (sync_curr_do_db < sync_db_list.length) {
  38. sync_do_db(src, dest, 1);
  39. } else {
  40. $("#sync_result").html($("#sync_result").html() + "<br>All Done"); //
  41. }
  42. }
  43. }
  44. );
  45. }