const http = require('http');
const fs = require('fs');

function checkIfPhishing(urlToPrint, path, lang = 'zh') {
  fs.mkdirSync(path, { recursive: true });
  const file = fs.createWriteStream(`${path}/${lang}.json`);
  const request = http.get(urlToPrint, function (response) {
    response.pipe(file).on('finish', function () {
      console.log(`lang: ${lang} get translate in ${path} Done!`);
      // console.log(fs.readFileSync(`${lang}.json`, { encoding: "utf8" }));
    });
  });
}
// editor zh
checkIfPhishing(
  'http://192.168.0.163:8080/download/geo_jp/backend/zh_Hans/',
  'src/locales/lang/json',
  'zh-CN',
);
// editor en
checkIfPhishing(
  'http://192.168.0.163:8080/download/geo_jp/backend/ja/',
  'src/locales/lang/json',
  'ja',
);
