pinme 1.1.3-alpha.3 → 1.1.4-alpha.1
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.
- package/dist/index.js +58 -28
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1485,7 +1485,7 @@ var import_chalk5 = __toESM(require("chalk"));
|
|
|
1485
1485
|
var import_figlet3 = __toESM(require("figlet"));
|
|
1486
1486
|
|
|
1487
1487
|
// package.json
|
|
1488
|
-
var version = "1.1.
|
|
1488
|
+
var version = "1.1.4-alpha.1";
|
|
1489
1489
|
|
|
1490
1490
|
// bin/upload.ts
|
|
1491
1491
|
var import_path5 = __toESM(require("path"));
|
|
@@ -4360,7 +4360,7 @@ var {
|
|
|
4360
4360
|
mergeConfig: mergeConfig2
|
|
4361
4361
|
} = axios_default;
|
|
4362
4362
|
|
|
4363
|
-
// bin/utils/
|
|
4363
|
+
// bin/utils/uploadToIpfsSplit.ts
|
|
4364
4364
|
var import_fs_extra3 = __toESM(require("fs-extra"));
|
|
4365
4365
|
var import_path4 = __toESM(require("path"));
|
|
4366
4366
|
var import_form_data2 = __toESM(require("form-data"));
|
|
@@ -4520,7 +4520,7 @@ function getDeviceId() {
|
|
|
4520
4520
|
return deviceId;
|
|
4521
4521
|
}
|
|
4522
4522
|
|
|
4523
|
-
// bin/utils/
|
|
4523
|
+
// bin/utils/uploadToIpfsSplit.ts
|
|
4524
4524
|
var IPFS_API_URL = "https://pinme.dev/api/v3";
|
|
4525
4525
|
var MAX_RETRIES = parseInt(process.env.MAX_RETRIES || "2");
|
|
4526
4526
|
var RETRY_DELAY = parseInt(process.env.RETRY_DELAY_MS || "1000");
|
|
@@ -4529,7 +4529,7 @@ var MAX_POLL_TIME = parseInt("5") * 60 * 1e3;
|
|
|
4529
4529
|
var POLL_INTERVAL = parseInt(process.env.POLL_INTERVAL_SECONDS || "2") * 1e3;
|
|
4530
4530
|
var PROGRESS_UPDATE_INTERVAL = 200;
|
|
4531
4531
|
var EXPECTED_UPLOAD_TIME = 6e4;
|
|
4532
|
-
var MAX_PROGRESS = 0.
|
|
4532
|
+
var MAX_PROGRESS = 0.9;
|
|
4533
4533
|
var StepProgressBar = class {
|
|
4534
4534
|
spinner;
|
|
4535
4535
|
fileName;
|
|
@@ -4537,6 +4537,8 @@ var StepProgressBar = class {
|
|
|
4537
4537
|
currentStep = 0;
|
|
4538
4538
|
stepStartTime = 0;
|
|
4539
4539
|
progressInterval = null;
|
|
4540
|
+
isSimulatingProgress = false;
|
|
4541
|
+
simulationStartTime = 0;
|
|
4540
4542
|
constructor(fileName, isDirectory = false) {
|
|
4541
4543
|
this.fileName = fileName;
|
|
4542
4544
|
this.spinner = (0, import_ora.default)(`Preparing to upload ${fileName}...`).start();
|
|
@@ -4552,6 +4554,15 @@ var StepProgressBar = class {
|
|
|
4552
4554
|
}
|
|
4553
4555
|
completeStep() {
|
|
4554
4556
|
}
|
|
4557
|
+
// 开始模拟进度,用于在90%后继续显示进度
|
|
4558
|
+
startSimulatingProgress() {
|
|
4559
|
+
this.isSimulatingProgress = true;
|
|
4560
|
+
this.simulationStartTime = Date.now();
|
|
4561
|
+
}
|
|
4562
|
+
// 停止模拟进度
|
|
4563
|
+
stopSimulatingProgress() {
|
|
4564
|
+
this.isSimulatingProgress = false;
|
|
4565
|
+
}
|
|
4555
4566
|
failStep(error) {
|
|
4556
4567
|
this.stopProgress();
|
|
4557
4568
|
this.spinner.fail(`Upload failed: ${error}`);
|
|
@@ -4570,7 +4581,14 @@ var StepProgressBar = class {
|
|
|
4570
4581
|
startProgress() {
|
|
4571
4582
|
this.progressInterval = setInterval(() => {
|
|
4572
4583
|
const elapsed = Date.now() - this.startTime;
|
|
4573
|
-
|
|
4584
|
+
let progress;
|
|
4585
|
+
if (this.isSimulatingProgress) {
|
|
4586
|
+
const simulationElapsed = Date.now() - this.simulationStartTime;
|
|
4587
|
+
const simulationProgress = Math.min(simulationElapsed / 6e4, 1);
|
|
4588
|
+
progress = 0.9 + simulationProgress * 0.09;
|
|
4589
|
+
} else {
|
|
4590
|
+
progress = this.calculateProgress(elapsed);
|
|
4591
|
+
}
|
|
4574
4592
|
const duration = this.formatDuration(Math.floor(elapsed / 1e3));
|
|
4575
4593
|
const progressBar = this.createProgressBar(progress);
|
|
4576
4594
|
this.spinner.text = `Uploading ${this.fileName}... ${progressBar} ${Math.round(progress * 100)}% (${duration})`;
|
|
@@ -4839,29 +4857,41 @@ async function getChunkStatus(sessionId, deviceId) {
|
|
|
4839
4857
|
throw error;
|
|
4840
4858
|
}
|
|
4841
4859
|
}
|
|
4842
|
-
async function monitorChunkProgress(traceId, deviceId) {
|
|
4860
|
+
async function monitorChunkProgress(traceId, deviceId, progressBar) {
|
|
4843
4861
|
let consecutiveErrors = 0;
|
|
4844
4862
|
const startTime = Date.now();
|
|
4845
|
-
|
|
4846
|
-
|
|
4847
|
-
|
|
4848
|
-
|
|
4849
|
-
|
|
4850
|
-
|
|
4851
|
-
|
|
4852
|
-
|
|
4853
|
-
|
|
4854
|
-
|
|
4855
|
-
|
|
4856
|
-
|
|
4857
|
-
|
|
4858
|
-
|
|
4863
|
+
if (progressBar) {
|
|
4864
|
+
progressBar.startSimulatingProgress();
|
|
4865
|
+
}
|
|
4866
|
+
try {
|
|
4867
|
+
while (Date.now() - startTime < MAX_POLL_TIME) {
|
|
4868
|
+
try {
|
|
4869
|
+
const status = await getChunkStatus(traceId, deviceId);
|
|
4870
|
+
consecutiveErrors = 0;
|
|
4871
|
+
if (status.is_ready && status.upload_rst.Hash) {
|
|
4872
|
+
if (progressBar) {
|
|
4873
|
+
progressBar.stopSimulatingProgress();
|
|
4874
|
+
}
|
|
4875
|
+
return {
|
|
4876
|
+
hash: status.upload_rst.Hash,
|
|
4877
|
+
shortUrl: status.upload_rst.ShortUrl
|
|
4878
|
+
};
|
|
4879
|
+
}
|
|
4880
|
+
} catch (error) {
|
|
4881
|
+
consecutiveErrors++;
|
|
4882
|
+
if (consecutiveErrors > 10) {
|
|
4883
|
+
throw new Error(`Polling failed: ${error.message}`);
|
|
4884
|
+
}
|
|
4859
4885
|
}
|
|
4886
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
|
4887
|
+
}
|
|
4888
|
+
const maxPollTimeMinutes = Math.floor(MAX_POLL_TIME / (60 * 1e3));
|
|
4889
|
+
throw new Error(`Polling timeout after ${maxPollTimeMinutes} minutes`);
|
|
4890
|
+
} finally {
|
|
4891
|
+
if (progressBar) {
|
|
4892
|
+
progressBar.stopSimulatingProgress();
|
|
4860
4893
|
}
|
|
4861
|
-
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
|
4862
4894
|
}
|
|
4863
|
-
const maxPollTimeMinutes = Math.floor(MAX_POLL_TIME / (60 * 1e3));
|
|
4864
|
-
throw new Error(`Polling timeout after ${maxPollTimeMinutes} minutes`);
|
|
4865
4895
|
}
|
|
4866
4896
|
async function uploadDirectoryInChunks(directoryPath, deviceId) {
|
|
4867
4897
|
const sizeCheck = checkDirectorySizeLimit(directoryPath);
|
|
@@ -4892,7 +4922,7 @@ async function uploadDirectoryInChunks(directoryPath, deviceId) {
|
|
|
4892
4922
|
const traceId = await completeChunkUpload(sessionInfo.session_id, deviceId);
|
|
4893
4923
|
progressBar.completeStep();
|
|
4894
4924
|
progressBar.startStep(4, "Waiting for processing");
|
|
4895
|
-
const result = await monitorChunkProgress(traceId, deviceId);
|
|
4925
|
+
const result = await monitorChunkProgress(traceId, deviceId, progressBar);
|
|
4896
4926
|
progressBar.completeStep();
|
|
4897
4927
|
try {
|
|
4898
4928
|
import_fs_extra3.default.unlinkSync(compressedPath);
|
|
@@ -4945,7 +4975,7 @@ async function uploadFileInChunks(filePath, deviceId) {
|
|
|
4945
4975
|
const traceId = await completeChunkUpload(sessionInfo.session_id, deviceId);
|
|
4946
4976
|
progressBar.completeStep();
|
|
4947
4977
|
progressBar.startStep(3, "Waiting for processing");
|
|
4948
|
-
const result = await monitorChunkProgress(traceId, deviceId);
|
|
4978
|
+
const result = await monitorChunkProgress(traceId, deviceId, progressBar);
|
|
4949
4979
|
progressBar.completeStep();
|
|
4950
4980
|
const uploadData = {
|
|
4951
4981
|
path: filePath,
|
|
@@ -4968,7 +4998,7 @@ async function uploadFileInChunks(filePath, deviceId) {
|
|
|
4968
4998
|
throw error;
|
|
4969
4999
|
}
|
|
4970
5000
|
}
|
|
4971
|
-
async function
|
|
5001
|
+
async function uploadToIpfsSplit_default(filePath) {
|
|
4972
5002
|
const deviceId = getDeviceId();
|
|
4973
5003
|
if (!deviceId) {
|
|
4974
5004
|
throw new Error("Device ID not found");
|
|
@@ -5039,7 +5069,7 @@ var upload_default = async (options) => {
|
|
|
5039
5069
|
}
|
|
5040
5070
|
console.log(import_chalk2.default.blue(`uploading ${absolutePath} to ipfs...`));
|
|
5041
5071
|
try {
|
|
5042
|
-
const result = await
|
|
5072
|
+
const result = await uploadToIpfsSplit_default(absolutePath);
|
|
5043
5073
|
if (result) {
|
|
5044
5074
|
const encryptedCID = encryptHash(result.contentHash, secretKey);
|
|
5045
5075
|
console.log(
|
|
@@ -5071,7 +5101,7 @@ var upload_default = async (options) => {
|
|
|
5071
5101
|
}
|
|
5072
5102
|
console.log(import_chalk2.default.blue(`uploading ${absolutePath} to ipfs...`));
|
|
5073
5103
|
try {
|
|
5074
|
-
const result = await
|
|
5104
|
+
const result = await uploadToIpfsSplit_default(absolutePath);
|
|
5075
5105
|
if (result) {
|
|
5076
5106
|
const encryptedCID = encryptHash(result.contentHash, secretKey);
|
|
5077
5107
|
console.log(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinme",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.4-alpha.1",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
"rollup-plugin-terser": "^7.0.2"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
62
|
+
"node": ">= 16.13.0"
|
|
63
63
|
}
|
|
64
64
|
}
|