esoftplay 0.0.142-s → 0.0.142-u

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bin/cli.js +8 -9
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -546,6 +546,8 @@ async function preload_api() {
546
546
  let cjson = await readToJSON(confjson)
547
547
  const { protocol, domain, uri, preload_api } = cjson.config
548
548
  if (preload_api?.length > 0) {
549
+ fs.rmSync("./assets/preload_api", { recursive: true, force: true })
550
+ fs.rmSync("./assets/preload_assets", { recursive: true, force: true })
549
551
  for (const apiUri of preload_api) {
550
552
  let fullUrl = apiUri.includes("://") ? apiUri : `${(protocol || 'http')}://api.${domain}${(uri || "/")}${apiUri}`
551
553
  const lastString = fullUrl.slice(fullUrl.lastIndexOf("/") + 1) // Fixed index adjustment
@@ -570,8 +572,6 @@ async function preload_api() {
570
572
  fs.mkdirSync('./assets/preload_api', { recursive: true })
571
573
  }
572
574
  fs.writeFileSync(`./assets/preload_api/${lastString}.json`, data)
573
-
574
-
575
575
  let objectData = JSON.parse(data)
576
576
 
577
577
  async function readDeepObject(obj, path = []) {
@@ -587,7 +587,7 @@ async function preload_api() {
587
587
  const value = obj
588
588
  var cursor = path.join(".")
589
589
  if (/\.(jpg|jpeg|png|gif|bmp|webp|svg|pdf|txt)$/i.test(value)) {
590
- const localFilePath = await downloadFile(value)
590
+ const localFilePath = await downloadFile(value, "./assets/preload_assets/" + lastString)
591
591
  objectData = LibObject.set(objectData, localFilePath)(cursor)
592
592
  const newData = JSON.stringify(objectData, undefined, 2)
593
593
  fs.writeFileSync(`./assets/preload_api/${lastString}.json`, newData, { encoding: "utf8" })
@@ -599,10 +599,9 @@ async function preload_api() {
599
599
  if (!fs.existsSync(downloadDir)) {
600
600
  fs.mkdirSync(downloadDir, { recursive: true });
601
601
  }
602
-
603
602
  const fileName = path.basename(url);
604
603
  const filePath = path.join(downloadDir, fileName);
605
-
604
+
606
605
  for (let attempt = 1; attempt <= retries; attempt++) {
607
606
  try {
608
607
  return await new Promise((resolve, reject) => {
@@ -612,9 +611,9 @@ async function preload_api() {
612
611
  reject(new Error(`Failed to fetch ${url}: ${response.statusCode}`));
613
612
  return;
614
613
  }
615
-
614
+
616
615
  response.pipe(fileStream);
617
-
616
+
618
617
  fileStream.on('finish', () => {
619
618
  fileStream.close(() => {
620
619
  // Validate that file is not empty
@@ -625,12 +624,12 @@ async function preload_api() {
625
624
  }
626
625
  });
627
626
  });
628
-
627
+
629
628
  fileStream.on('error', (error) => {
630
629
  fileStream.close(() => reject(error));
631
630
  });
632
631
  });
633
-
632
+
634
633
  request.on('error', (error) => reject(error));
635
634
  });
636
635
  } catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "esoftplay",
3
- "version": "0.0.142-s",
3
+ "version": "0.0.142-u",
4
4
  "description": "embedding data from esoftplay framework (web based) into mobile app",
5
5
  "main": "cache/index.js",
6
6
  "types": "../../index.d.ts",