pinme 1.1.1-alpha.2 → 1.1.1-alpha.4

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/dist/index.js +118 -51
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -1485,7 +1485,7 @@ var import_chalk6 = __toESM(require("chalk"));
1485
1485
  var import_figlet3 = __toESM(require("figlet"));
1486
1486
 
1487
1487
  // package.json
1488
- var version = "1.1.1-alpha.2";
1488
+ var version = "1.1.1-alpha.4";
1489
1489
 
1490
1490
  // bin/upload.ts
1491
1491
  var import_path5 = __toESM(require("path"));
@@ -4370,7 +4370,7 @@ var import_chalk2 = __toESM(require("chalk"));
4370
4370
  // bin/utils/uploadLimits.ts
4371
4371
  var import_fs = __toESM(require("fs"));
4372
4372
  var import_path = __toESM(require("path"));
4373
- var FILE_SIZE_LIMIT = parseInt("20", 10) * 1024 * 1024;
4373
+ var FILE_SIZE_LIMIT = parseInt("500", 10) * 1024 * 1024;
4374
4374
  var DIRECTORY_SIZE_LIMIT = parseInt("500", 10) * 1024 * 1024;
4375
4375
  function checkFileSizeLimit(filePath) {
4376
4376
  const stats = import_fs.default.statSync(filePath);
@@ -4527,7 +4527,7 @@ var pollInterval = parseInt(process.env.POLL_INTERVAL_SECONDS || "2") * 1e3;
4527
4527
  var pollTimeout = parseInt(process.env.POLL_TIMEOUT_SECONDS || "10") * 1e3;
4528
4528
  async function pollUploadStatus(traceId, deviceId, smartProgress, startTime) {
4529
4529
  let consecutiveErrors = 0;
4530
- const maxConsecutiveErrors = 3;
4530
+ let stopProgressUpdates = false;
4531
4531
  while (Date.now() - startTime < maxPollTime) {
4532
4532
  try {
4533
4533
  const response = await axios_default.get(
@@ -4545,11 +4545,12 @@ async function pollUploadStatus(traceId, deviceId, smartProgress, startTime) {
4545
4545
  const { code, msg, data } = response.data;
4546
4546
  if (code === 200) {
4547
4547
  consecutiveErrors = 0;
4548
+ stopProgressUpdates = false;
4548
4549
  if (data.is_ready) {
4549
4550
  smartProgress.complete(traceId);
4550
4551
  return data;
4551
4552
  } else {
4552
- smartProgress.update();
4553
+ smartProgress.updateDisplay();
4553
4554
  }
4554
4555
  } else {
4555
4556
  console.log(import_chalk2.default.yellow(`Warning: ${msg}`));
@@ -4557,15 +4558,17 @@ async function pollUploadStatus(traceId, deviceId, smartProgress, startTime) {
4557
4558
  } catch (error) {
4558
4559
  consecutiveErrors++;
4559
4560
  console.log(import_chalk2.default.yellow(`Polling error: ${error.message}`));
4560
- if (consecutiveErrors >= maxConsecutiveErrors) {
4561
- console.log(import_chalk2.default.red(`Too many consecutive polling errors (${consecutiveErrors}), stopping progress updates`));
4562
- break;
4561
+ if (stopProgressUpdates) {
4562
+ smartProgress.updateTimeOnly();
4563
4563
  }
4564
4564
  }
4565
4565
  await new Promise((resolve) => setTimeout(resolve, pollInterval));
4566
4566
  }
4567
4567
  const maxPollTimeMinutes = Math.floor(maxPollTime / (60 * 1e3));
4568
- smartProgress.fail(`Upload timeout after ${maxPollTimeMinutes} minutes`, traceId);
4568
+ smartProgress.fail(
4569
+ `Upload timeout after ${maxPollTimeMinutes} minutes`,
4570
+ traceId
4571
+ );
4569
4572
  return null;
4570
4573
  }
4571
4574
  function diagnoseDirectoryUploadError(directoryName, resData, expectedName) {
@@ -4607,7 +4610,7 @@ function handleMultipartError(error, context) {
4607
4610
  return `Upload error: ${error.message}`;
4608
4611
  }
4609
4612
  var ERROR_CODES = {
4610
- "30001": `File too large, single file max size: ${"20"}MB,single folder max size: ${"500"}MB`,
4613
+ "30001": `File too large, single file max size: ${"500"}MB,single folder max size: ${"500"}MB`,
4611
4614
  "30002": `Max storage quorum ${Number("1000") / 1e3} GB reached`
4612
4615
  };
4613
4616
  function loadFilesToArrRecursively(directoryPath, dist, basePath) {
@@ -4617,13 +4620,8 @@ function loadFilesToArrRecursively(directoryPath, dist, basePath) {
4617
4620
  const parentDir = import_path4.default.dirname(directoryPath);
4618
4621
  basePath = parentDir.endsWith(sep) ? parentDir : parentDir + sep;
4619
4622
  }
4620
- console.log(import_chalk2.default.blue("\n\u{1F4C1} Directory Structure Analysis:"));
4621
- console.log(import_chalk2.default.gray(` Upload directory: ${directoryPath}`));
4622
- console.log(import_chalk2.default.gray(` Base path: ${basePath}`));
4623
- console.log(import_chalk2.default.gray(` Directory name: ${dist}`));
4624
4623
  if (import_fs_extra3.default.statSync(directoryPath).isDirectory()) {
4625
4624
  const files = import_fs_extra3.default.readdirSync(directoryPath);
4626
- console.log(import_chalk2.default.gray(` Files found in directory: ${files.length}`));
4627
4625
  files.forEach((file) => {
4628
4626
  const filePath = import_path4.default.join(directoryPath, file);
4629
4627
  if (import_fs_extra3.default.statSync(filePath).isFile()) {
@@ -4637,25 +4635,22 @@ function loadFilesToArrRecursively(directoryPath, dist, basePath) {
4637
4635
  }
4638
4636
  const relativePath = filePath.replace(basePath, "");
4639
4637
  const encodedPath = relativePath.replaceAll(sep, "%2F");
4640
- console.log(import_chalk2.default.cyan(` \u{1F4C4} File: ${file}`));
4641
- console.log(import_chalk2.default.gray(` Full path: ${filePath}`));
4642
- console.log(import_chalk2.default.gray(` Relative path: ${relativePath}`));
4643
- console.log(import_chalk2.default.gray(` Encoded path: ${encodedPath}`));
4644
4638
  filesArr.push({
4645
4639
  name: encodedPath,
4646
4640
  path: filePath
4647
4641
  });
4648
4642
  } else if (import_fs_extra3.default.statSync(filePath).isDirectory()) {
4649
- console.log(import_chalk2.default.yellow(` \u{1F4C2} Subdirectory: ${file}`));
4650
- console.log(import_chalk2.default.gray(` Path: ${filePath}`));
4651
- const recursiveFiles = loadFilesToArrRecursively(filePath, dist, basePath);
4643
+ const recursiveFiles = loadFilesToArrRecursively(
4644
+ filePath,
4645
+ dist,
4646
+ basePath
4647
+ );
4652
4648
  filesArr.push(...recursiveFiles);
4653
4649
  }
4654
4650
  });
4655
4651
  } else {
4656
4652
  console.error("Error: path must be a directory");
4657
4653
  }
4658
- console.log(import_chalk2.default.green(` \u2705 Total files processed: ${filesArr.length}`));
4659
4654
  return filesArr;
4660
4655
  }
4661
4656
  function countFilesInDirectory(directoryPath) {
@@ -4688,15 +4683,10 @@ async function uploadDirectory(directoryPath, deviceId) {
4688
4683
  const files = loadFilesToArrRecursively(directoryPath, dist);
4689
4684
  const totalFiles = files.length;
4690
4685
  if (totalFiles === 0) {
4691
- throw new Error(`Directory ${directoryPath} is empty or contains no valid files`);
4686
+ throw new Error(
4687
+ `Directory ${directoryPath} is empty or contains no valid files`
4688
+ );
4692
4689
  }
4693
- console.log(import_chalk2.default.blue("\n\u{1F4CB} Final Upload File List:"));
4694
- console.log(import_chalk2.default.gray(` Upload root directory: ${dist}`));
4695
- files.forEach((file, index) => {
4696
- console.log(import_chalk2.default.gray(` ${index + 1}. ${file.name}`));
4697
- });
4698
- console.log(import_chalk2.default.green(` Total files to upload: ${totalFiles}
4699
- `));
4700
4690
  files.forEach((file) => {
4701
4691
  if (!import_fs_extra3.default.existsSync(file.path)) {
4702
4692
  throw new Error(`File not found: ${file.path}`);
@@ -4719,9 +4709,17 @@ async function uploadDirectory(directoryPath, deviceId) {
4719
4709
  } catch (error) {
4720
4710
  }
4721
4711
  });
4722
- const smartProgress = new SmartProgressBar(dist, totalFiles, totalSize, spinner);
4712
+ const smartProgress = new SmartProgressBar(
4713
+ dist,
4714
+ totalFiles,
4715
+ totalSize,
4716
+ spinner
4717
+ );
4718
+ const timeInterval = setInterval(() => {
4719
+ smartProgress.updateTime();
4720
+ }, 1e3);
4723
4721
  const progressInterval = setInterval(() => {
4724
- smartProgress.update();
4722
+ smartProgress.updateProgress();
4725
4723
  }, 200);
4726
4724
  try {
4727
4725
  smartProgress.startUpload();
@@ -4741,9 +4739,10 @@ async function uploadDirectory(directoryPath, deviceId) {
4741
4739
  const { trace_id } = response.data.data;
4742
4740
  if (!trace_id) {
4743
4741
  smartProgress.fail("No request id received from server");
4742
+ clearInterval(timeInterval);
4744
4743
  return null;
4745
4744
  }
4746
- smartProgress.update();
4745
+ smartProgress.updateDisplay();
4747
4746
  const uploadResult = await pollUploadStatus(
4748
4747
  trace_id,
4749
4748
  deviceId,
@@ -4751,6 +4750,7 @@ async function uploadDirectory(directoryPath, deviceId) {
4751
4750
  startTime
4752
4751
  );
4753
4752
  if (!uploadResult) {
4753
+ clearInterval(timeInterval);
4754
4754
  return null;
4755
4755
  }
4756
4756
  const directoryItem = uploadResult.upload_rst;
@@ -4767,6 +4767,7 @@ async function uploadDirectory(directoryPath, deviceId) {
4767
4767
  shortUrl: directoryItem.ShortUrl || null
4768
4768
  };
4769
4769
  saveUploadHistory(uploadData);
4770
+ clearInterval(timeInterval);
4770
4771
  return {
4771
4772
  hash: directoryItem.Hash,
4772
4773
  shortUrl: directoryItem.ShortUrl
@@ -4777,7 +4778,7 @@ async function uploadDirectory(directoryPath, deviceId) {
4777
4778
  uploadResult.upload_rst,
4778
4779
  dist
4779
4780
  );
4780
- smartProgress.fail("Directory hash not found in response", trace_id);
4781
+ smartProgress.fail("Directory hash not found in response");
4781
4782
  console.log(
4782
4783
  import_chalk2.default.red(
4783
4784
  `
@@ -4790,18 +4791,22 @@ async function uploadDirectory(directoryPath, deviceId) {
4790
4791
  console.log(import_chalk2.default.blue(`
4791
4792
  \u{1F527} Solutions:`));
4792
4793
  console.log(
4793
- import_chalk2.default.gray(
4794
- ` 1. Ensure directory is not empty and contains valid files`
4795
- )
4794
+ import_chalk2.default.gray(` 1. Ensure directory is not empty and contains valid files`)
4796
4795
  );
4797
4796
  console.log(import_chalk2.default.gray(` 2. Check network connection stability`));
4798
4797
  console.log(
4799
4798
  import_chalk2.default.gray(` 3. Try uploading a smaller directory for testing`)
4800
4799
  );
4800
+ clearInterval(timeInterval);
4801
+ return null;
4801
4802
  } catch (error) {
4802
4803
  clearInterval(progressInterval);
4804
+ clearInterval(timeInterval);
4803
4805
  if (error.message && error.message.includes("multipart")) {
4804
- const errorMessage = handleMultipartError(error, `Directory upload: ${dist}`);
4806
+ const errorMessage = handleMultipartError(
4807
+ error,
4808
+ `Directory upload: ${dist}`
4809
+ );
4805
4810
  smartProgress.fail(errorMessage);
4806
4811
  console.log(import_chalk2.default.red(`
4807
4812
  \u274C ${errorMessage}`));
@@ -4810,7 +4815,9 @@ async function uploadDirectory(directoryPath, deviceId) {
4810
4815
  if (error.response && error.response.data && error.response.data.code) {
4811
4816
  const errorCode = error.response.data.code.toString();
4812
4817
  if (ERROR_CODES[errorCode]) {
4813
- smartProgress.fail(`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`);
4818
+ smartProgress.fail(
4819
+ `Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`
4820
+ );
4814
4821
  console.log(
4815
4822
  import_chalk2.default.red(`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`)
4816
4823
  );
@@ -4855,8 +4862,11 @@ async function uploadFile(filePath, deviceId) {
4855
4862
  } catch (error) {
4856
4863
  }
4857
4864
  const smartProgress = new SmartProgressBar(fileName, 1, totalSize, spinner);
4865
+ const timeInterval = setInterval(() => {
4866
+ smartProgress.updateTime();
4867
+ }, 1e3);
4858
4868
  const progressInterval = setInterval(() => {
4859
- smartProgress.update();
4869
+ smartProgress.updateProgress();
4860
4870
  }, 200);
4861
4871
  try {
4862
4872
  smartProgress.startUpload();
@@ -4881,9 +4891,10 @@ async function uploadFile(filePath, deviceId) {
4881
4891
  const trace_id = response.data.data.trace_id;
4882
4892
  if (!trace_id) {
4883
4893
  smartProgress.fail("No request id received from server");
4894
+ clearInterval(timeInterval);
4884
4895
  return null;
4885
4896
  }
4886
- smartProgress.update();
4897
+ smartProgress.updateDisplay();
4887
4898
  const uploadResult = await pollUploadStatus(
4888
4899
  trace_id,
4889
4900
  deviceId,
@@ -4891,6 +4902,7 @@ async function uploadFile(filePath, deviceId) {
4891
4902
  startTime
4892
4903
  );
4893
4904
  if (!uploadResult) {
4905
+ clearInterval(timeInterval);
4894
4906
  return null;
4895
4907
  }
4896
4908
  const fileItem = uploadResult.upload_rst;
@@ -4907,12 +4919,13 @@ async function uploadFile(filePath, deviceId) {
4907
4919
  };
4908
4920
  saveUploadHistory(uploadData);
4909
4921
  smartProgress.complete(trace_id);
4922
+ clearInterval(timeInterval);
4910
4923
  return {
4911
4924
  hash: fileItem.Hash,
4912
4925
  shortUrl: fileItem.ShortUrl
4913
4926
  };
4914
4927
  }
4915
- smartProgress.fail("File hash not found in response", trace_id);
4928
+ smartProgress.fail("File hash not found in response");
4916
4929
  console.log(
4917
4930
  import_chalk2.default.red(`
4918
4931
  \u274C File upload failed: File hash not found in response`)
@@ -4921,19 +4934,23 @@ async function uploadFile(filePath, deviceId) {
4921
4934
  \u{1F4CB} Error diagnosis information:`));
4922
4935
  console.log(import_chalk2.default.gray(` - File name: ${fileName}`));
4923
4936
  console.log(
4924
- import_chalk2.default.gray(
4925
- ` - Name returned by IPFS: ${uploadResult.upload_rst.Name}`
4926
- )
4937
+ import_chalk2.default.gray(` - Name returned by IPFS: ${uploadResult.upload_rst.Name}`)
4927
4938
  );
4928
4939
  console.log(import_chalk2.default.blue(`
4929
4940
  \u{1F527} Solutions:`));
4930
4941
  console.log(import_chalk2.default.gray(` 1. Check if file is corrupted or unreadable`));
4931
4942
  console.log(import_chalk2.default.gray(` 2. Check network connection stability`));
4932
4943
  console.log(import_chalk2.default.gray(` 3. Try uploading a smaller file for testing`));
4944
+ clearInterval(timeInterval);
4945
+ return null;
4933
4946
  } catch (error) {
4934
4947
  clearInterval(progressInterval);
4948
+ clearInterval(timeInterval);
4935
4949
  if (error.message && error.message.includes("multipart")) {
4936
- const errorMessage = handleMultipartError(error, `File upload: ${fileName}`);
4950
+ const errorMessage = handleMultipartError(
4951
+ error,
4952
+ `File upload: ${fileName}`
4953
+ );
4937
4954
  smartProgress.fail(errorMessage);
4938
4955
  console.log(import_chalk2.default.red(`
4939
4956
  \u274C ${errorMessage}`));
@@ -4942,7 +4959,9 @@ async function uploadFile(filePath, deviceId) {
4942
4959
  if (error.response && error.response.data && error.response.data.code) {
4943
4960
  const errorCode = error.response.data.code.toString();
4944
4961
  if (ERROR_CODES[errorCode]) {
4945
- smartProgress.fail(`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`);
4962
+ smartProgress.fail(
4963
+ `Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`
4964
+ );
4946
4965
  console.log(
4947
4966
  import_chalk2.default.red(`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`)
4948
4967
  );
@@ -5024,6 +5043,56 @@ var SmartProgressBar = class {
5024
5043
  const fileInfo = this.fileCount > 1 ? `${this.fileName} (${this.fileCount} files)` : this.fileName;
5025
5044
  this.spinner.text = `Uploading ${fileInfo} ${progressBar} ${duration} (${status})`;
5026
5045
  }
5046
+ // Update time display only (called every second)
5047
+ updateTime() {
5048
+ if (this.isCompleted) {
5049
+ return;
5050
+ }
5051
+ const elapsed = Math.floor((Date.now() - this.startTime) / 1e3);
5052
+ const duration = this.formatDuration(elapsed);
5053
+ const progress = this.calculateProgress();
5054
+ const progressBar = this.createProgressBar(progress);
5055
+ let status = "";
5056
+ if (this.isUploading) {
5057
+ status = "uploading";
5058
+ } else if (this.isPolling) {
5059
+ status = "processing";
5060
+ } else {
5061
+ status = "preparing";
5062
+ }
5063
+ const fileInfo = this.fileCount > 1 ? `${this.fileName} (${this.fileCount} files)` : this.fileName;
5064
+ this.spinner.text = `Uploading ${fileInfo} ${progressBar} ${duration} (${status})`;
5065
+ }
5066
+ // Update progress bar only (called every 200ms)
5067
+ updateProgress() {
5068
+ if (this.isCompleted) {
5069
+ return;
5070
+ }
5071
+ const progress = this.calculateProgress();
5072
+ const elapsed = Math.floor((Date.now() - this.startTime) / 1e3);
5073
+ const progressBar = this.createProgressBar(progress);
5074
+ const duration = this.formatDuration(elapsed);
5075
+ let status = "";
5076
+ if (this.isUploading) {
5077
+ status = "uploading";
5078
+ } else if (this.isPolling) {
5079
+ status = "processing";
5080
+ } else {
5081
+ status = "preparing";
5082
+ }
5083
+ const fileInfo = this.fileCount > 1 ? `${this.fileName} (${this.fileCount} files)` : this.fileName;
5084
+ this.spinner.text = `Uploading ${fileInfo} ${progressBar} ${duration} (${status})`;
5085
+ }
5086
+ // Update display (for manual updates)
5087
+ updateDisplay() {
5088
+ this.updateTime();
5089
+ }
5090
+ // Update progress display only (no progress bar)
5091
+ updateTimeOnly() {
5092
+ const elapsed = Math.floor((Date.now() - this.startTime) / 1e3);
5093
+ const duration = this.formatDuration(elapsed);
5094
+ this.spinner.text = `Uploading ${this.fileName} ${duration}`;
5095
+ }
5027
5096
  // Complete progress
5028
5097
  complete(traceId) {
5029
5098
  if (this.isCompleted) {
@@ -5032,8 +5101,7 @@ var SmartProgressBar = class {
5032
5101
  const progressBar = this.createProgressBar(1);
5033
5102
  const elapsed = Math.floor((Date.now() - this.startTime) / 1e3);
5034
5103
  const duration = this.formatDuration(elapsed);
5035
- const traceInfo = traceId ? ` (trace_id: ${traceId})` : "";
5036
- this.spinner.succeed(`Upload completed ${progressBar} ${duration}${traceInfo}`);
5104
+ this.spinner.succeed(`Upload completed ${progressBar} ${duration}`);
5037
5105
  this.isCompleted = true;
5038
5106
  }
5039
5107
  // Fail progress
@@ -5043,8 +5111,7 @@ var SmartProgressBar = class {
5043
5111
  }
5044
5112
  const elapsed = Math.floor((Date.now() - this.startTime) / 1e3);
5045
5113
  const duration = this.formatDuration(elapsed);
5046
- const traceInfo = traceId ? ` (trace_id: ${traceId})` : "";
5047
- this.spinner.fail(`${message} ${duration}${traceInfo}`);
5114
+ this.spinner.fail(`${message} ${duration}`);
5048
5115
  this.isCompleted = true;
5049
5116
  }
5050
5117
  // Create visual progress bar
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinme",
3
- "version": "1.1.1-alpha.2",
3
+ "version": "1.1.1-alpha.4",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },