pinme 1.1.1 → 1.1.3-alpha.2
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/README.md +1 -1
- package/dist/index.js +477 -272
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -116,7 +116,7 @@ pinme rm
|
|
|
116
116
|
pinme rm bafybeifdwyoz66u5czbbjvmmais5fzrzrolxbyiydqsbrxessndt3s6zdi
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
**Note:** This action
|
|
119
|
+
**Note:** This action unpins the content from our IPFS node and deletes the ENS subdomain record. It does not ensure that the file is removed from the IPFS network.
|
|
120
120
|
|
|
121
121
|
### `list` / `ls`
|
|
122
122
|
|
package/dist/index.js
CHANGED
|
@@ -99,7 +99,7 @@ var require_main = __commonJS({
|
|
|
99
99
|
var fs6 = require("fs");
|
|
100
100
|
var path6 = require("path");
|
|
101
101
|
var os3 = require("os");
|
|
102
|
-
var
|
|
102
|
+
var crypto2 = require("crypto");
|
|
103
103
|
var packageJson = require_package();
|
|
104
104
|
var version2 = packageJson.version;
|
|
105
105
|
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
@@ -295,7 +295,7 @@ var require_main = __commonJS({
|
|
|
295
295
|
const authTag = ciphertext.subarray(-16);
|
|
296
296
|
ciphertext = ciphertext.subarray(12, -16);
|
|
297
297
|
try {
|
|
298
|
-
const aesgcm =
|
|
298
|
+
const aesgcm = crypto2.createDecipheriv("aes-256-gcm", key, nonce);
|
|
299
299
|
aesgcm.setAuthTag(authTag);
|
|
300
300
|
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
301
301
|
} catch (error) {
|
|
@@ -1481,15 +1481,15 @@ var require_follow_redirects = __commonJS({
|
|
|
1481
1481
|
// bin/index.ts
|
|
1482
1482
|
var import_dotenv = __toESM(require_main());
|
|
1483
1483
|
var import_commander = require("commander");
|
|
1484
|
-
var
|
|
1484
|
+
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.3-alpha.2";
|
|
1489
1489
|
|
|
1490
1490
|
// bin/upload.ts
|
|
1491
1491
|
var import_path5 = __toESM(require("path"));
|
|
1492
|
-
var
|
|
1492
|
+
var import_chalk2 = __toESM(require("chalk"));
|
|
1493
1493
|
var import_inquirer = __toESM(require("inquirer"));
|
|
1494
1494
|
var import_figlet = __toESM(require("figlet"));
|
|
1495
1495
|
|
|
@@ -4360,17 +4360,17 @@ var {
|
|
|
4360
4360
|
mergeConfig: mergeConfig2
|
|
4361
4361
|
} = axios_default;
|
|
4362
4362
|
|
|
4363
|
-
// bin/utils/
|
|
4363
|
+
// bin/utils/uploadToIpfs2.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"));
|
|
4367
4367
|
var import_ora = __toESM(require("ora"));
|
|
4368
|
-
var
|
|
4368
|
+
var crypto = __toESM(require("crypto"));
|
|
4369
4369
|
|
|
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("
|
|
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);
|
|
@@ -4520,256 +4520,458 @@ function getDeviceId() {
|
|
|
4520
4520
|
return deviceId;
|
|
4521
4521
|
}
|
|
4522
4522
|
|
|
4523
|
-
// bin/utils/
|
|
4524
|
-
var
|
|
4525
|
-
var
|
|
4526
|
-
|
|
4527
|
-
|
|
4528
|
-
|
|
4529
|
-
var
|
|
4530
|
-
|
|
4531
|
-
|
|
4532
|
-
|
|
4533
|
-
|
|
4534
|
-
|
|
4535
|
-
|
|
4536
|
-
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
|
|
4542
|
-
|
|
4543
|
-
|
|
4544
|
-
|
|
4545
|
-
|
|
4546
|
-
|
|
4547
|
-
|
|
4548
|
-
|
|
4549
|
-
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
|
|
4555
|
-
|
|
4556
|
-
|
|
4557
|
-
});
|
|
4558
|
-
}
|
|
4559
|
-
|
|
4523
|
+
// bin/utils/uploadToIpfs2.ts
|
|
4524
|
+
var IPFS_API_URL = "https://up.pinme.dev/api/v3";
|
|
4525
|
+
var MAX_RETRIES = parseInt(process.env.MAX_RETRIES || "2");
|
|
4526
|
+
var RETRY_DELAY = parseInt(process.env.RETRY_DELAY_MS || "1000");
|
|
4527
|
+
var TIMEOUT = parseInt(process.env.TIMEOUT_MS || "600000");
|
|
4528
|
+
var MAX_POLL_TIME = parseInt("5") * 60 * 1e3;
|
|
4529
|
+
var POLL_INTERVAL = parseInt(process.env.POLL_INTERVAL_SECONDS || "2") * 1e3;
|
|
4530
|
+
var PROGRESS_UPDATE_INTERVAL = 200;
|
|
4531
|
+
var EXPECTED_UPLOAD_TIME = 6e4;
|
|
4532
|
+
var MAX_PROGRESS = 0.95;
|
|
4533
|
+
var StepProgressBar = class {
|
|
4534
|
+
spinner;
|
|
4535
|
+
fileName;
|
|
4536
|
+
startTime;
|
|
4537
|
+
currentStep = 0;
|
|
4538
|
+
stepStartTime = 0;
|
|
4539
|
+
progressInterval = null;
|
|
4540
|
+
constructor(fileName, isDirectory = false) {
|
|
4541
|
+
this.fileName = fileName;
|
|
4542
|
+
this.spinner = (0, import_ora.default)(`Preparing to upload ${fileName}...`).start();
|
|
4543
|
+
this.startTime = Date.now();
|
|
4544
|
+
this.stepStartTime = Date.now();
|
|
4545
|
+
this.startProgress();
|
|
4546
|
+
}
|
|
4547
|
+
startStep(stepIndex, stepName) {
|
|
4548
|
+
this.currentStep = stepIndex;
|
|
4549
|
+
this.stepStartTime = Date.now();
|
|
4550
|
+
}
|
|
4551
|
+
updateProgress(progress, total) {
|
|
4552
|
+
}
|
|
4553
|
+
completeStep() {
|
|
4554
|
+
}
|
|
4555
|
+
failStep(error) {
|
|
4556
|
+
this.stopProgress();
|
|
4557
|
+
this.spinner.fail(`Upload failed: ${error}`);
|
|
4558
|
+
}
|
|
4559
|
+
complete() {
|
|
4560
|
+
this.stopProgress();
|
|
4561
|
+
const totalTime = Math.floor((Date.now() - this.startTime) / 1e3);
|
|
4562
|
+
const progressBar = this.createProgressBar(1);
|
|
4563
|
+
this.spinner.succeed(`Upload completed ${progressBar} 100% (${totalTime}s)`);
|
|
4564
|
+
}
|
|
4565
|
+
fail(error) {
|
|
4566
|
+
this.stopProgress();
|
|
4567
|
+
const totalTime = Math.floor((Date.now() - this.startTime) / 1e3);
|
|
4568
|
+
this.spinner.fail(`Upload failed: ${error} (${totalTime}s)`);
|
|
4569
|
+
}
|
|
4570
|
+
startProgress() {
|
|
4571
|
+
this.progressInterval = setInterval(() => {
|
|
4572
|
+
const elapsed = Date.now() - this.startTime;
|
|
4573
|
+
const progress = this.calculateProgress(elapsed);
|
|
4574
|
+
const progressBar = this.createProgressBar(progress);
|
|
4575
|
+
this.spinner.text = `Uploading ${this.fileName}... ${progressBar} ${Math.round(progress * 100)}%`;
|
|
4576
|
+
}, PROGRESS_UPDATE_INTERVAL);
|
|
4577
|
+
}
|
|
4578
|
+
stopProgress() {
|
|
4579
|
+
if (this.progressInterval) {
|
|
4580
|
+
clearInterval(this.progressInterval);
|
|
4581
|
+
this.progressInterval = null;
|
|
4582
|
+
}
|
|
4583
|
+
}
|
|
4584
|
+
calculateProgress(elapsed) {
|
|
4585
|
+
return Math.min(elapsed / EXPECTED_UPLOAD_TIME * MAX_PROGRESS, MAX_PROGRESS);
|
|
4586
|
+
}
|
|
4587
|
+
createProgressBar(progress, width = 20) {
|
|
4588
|
+
const percentage = Math.min(progress, 1);
|
|
4589
|
+
const filledWidth = Math.round(width * percentage);
|
|
4590
|
+
const emptyWidth = width - filledWidth;
|
|
4591
|
+
return `[${"\u2588".repeat(filledWidth)}${"\u2591".repeat(emptyWidth)}]`;
|
|
4560
4592
|
}
|
|
4561
|
-
|
|
4593
|
+
};
|
|
4594
|
+
async function calculateMD5(filePath) {
|
|
4595
|
+
return new Promise((resolve, reject) => {
|
|
4596
|
+
const hash = crypto.createHash("md5");
|
|
4597
|
+
const stream4 = import_fs_extra3.default.createReadStream(filePath);
|
|
4598
|
+
stream4.on("data", hash.update.bind(hash));
|
|
4599
|
+
stream4.on("end", () => resolve(hash.digest("hex")));
|
|
4600
|
+
stream4.on("error", reject);
|
|
4601
|
+
});
|
|
4562
4602
|
}
|
|
4563
|
-
function
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4603
|
+
async function compressDirectory(sourcePath) {
|
|
4604
|
+
return new Promise((resolve, reject) => {
|
|
4605
|
+
const tempDir = import_path4.default.join(process.cwd(), "temp");
|
|
4606
|
+
if (!import_fs_extra3.default.existsSync(tempDir)) {
|
|
4607
|
+
import_fs_extra3.default.mkdirSync(tempDir, { recursive: true });
|
|
4608
|
+
}
|
|
4609
|
+
const outputPath = import_path4.default.join(
|
|
4610
|
+
tempDir,
|
|
4611
|
+
`${import_path4.default.basename(sourcePath)}_${Date.now()}.zip`
|
|
4612
|
+
);
|
|
4613
|
+
const output = import_fs_extra3.default.createWriteStream(outputPath);
|
|
4614
|
+
const zlib2 = require("zlib");
|
|
4615
|
+
const gzip = zlib2.createGzip({ level: 9 });
|
|
4616
|
+
output.on("close", () => resolve(outputPath));
|
|
4617
|
+
gzip.on("error", reject);
|
|
4618
|
+
gzip.pipe(output);
|
|
4619
|
+
const stats = import_fs_extra3.default.statSync(sourcePath);
|
|
4620
|
+
if (stats.isDirectory()) {
|
|
4621
|
+
const archive = require("archiver");
|
|
4622
|
+
const archiveStream = archive("zip", { zlib: { level: 9 } });
|
|
4623
|
+
archiveStream.on("error", reject);
|
|
4624
|
+
archiveStream.pipe(output);
|
|
4625
|
+
archiveStream.directory(sourcePath, false);
|
|
4626
|
+
archiveStream.finalize();
|
|
4627
|
+
} else {
|
|
4628
|
+
const fileStream = import_fs_extra3.default.createReadStream(sourcePath);
|
|
4629
|
+
fileStream.pipe(gzip);
|
|
4573
4630
|
}
|
|
4574
|
-
}
|
|
4575
|
-
return count;
|
|
4631
|
+
});
|
|
4576
4632
|
}
|
|
4577
|
-
async function
|
|
4578
|
-
const
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4633
|
+
async function initChunkSession(filePath, deviceId, isDirectory = false) {
|
|
4634
|
+
const stats = import_fs_extra3.default.statSync(filePath);
|
|
4635
|
+
const fileName = import_path4.default.basename(filePath);
|
|
4636
|
+
const fileSize = stats.size;
|
|
4637
|
+
const md5 = await calculateMD5(filePath);
|
|
4638
|
+
try {
|
|
4639
|
+
const response = await axios_default.post(
|
|
4640
|
+
`${IPFS_API_URL}/chunk/init`,
|
|
4641
|
+
{
|
|
4642
|
+
file_name: fileName,
|
|
4643
|
+
file_size: fileSize,
|
|
4644
|
+
md5,
|
|
4645
|
+
is_directory: isDirectory,
|
|
4646
|
+
uid: deviceId
|
|
4647
|
+
},
|
|
4648
|
+
{
|
|
4649
|
+
timeout: TIMEOUT,
|
|
4650
|
+
headers: { "Content-Type": "application/json" }
|
|
4651
|
+
}
|
|
4584
4652
|
);
|
|
4653
|
+
const { code, msg, data } = response.data;
|
|
4654
|
+
if (code === 200 && data) {
|
|
4655
|
+
return data;
|
|
4656
|
+
}
|
|
4657
|
+
throw new Error(`Session initialization failed: ${msg} (code: ${code})`);
|
|
4658
|
+
} catch (error) {
|
|
4659
|
+
if (axios_default.isAxiosError(error)) {
|
|
4660
|
+
throw new Error(`Network error: ${error.message}`);
|
|
4661
|
+
}
|
|
4662
|
+
throw error;
|
|
4585
4663
|
}
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
directoryPath = directoryPath.slice(0, -1);
|
|
4589
|
-
const dist = directoryPath.split(import_path4.default.sep).pop() || "";
|
|
4590
|
-
const files = loadFilesToArrRecursively(directoryPath, dist);
|
|
4591
|
-
const totalFiles = files.length;
|
|
4592
|
-
files.forEach((file) => {
|
|
4593
|
-
formData.append("file", import_fs_extra3.default.createReadStream(file.path), {
|
|
4594
|
-
filename: file.name
|
|
4595
|
-
});
|
|
4596
|
-
});
|
|
4597
|
-
const startTime = Date.now();
|
|
4598
|
-
const spinner = (0, import_ora.default)(`Uploading ${dist} (${totalFiles} files)... 0s`).start();
|
|
4599
|
-
const timeInterval = setInterval(() => {
|
|
4600
|
-
const elapsed = Math.floor((Date.now() - startTime) / 1e3);
|
|
4601
|
-
spinner.text = `Uploading ${dist} (${totalFiles} files)... ${elapsed}s`;
|
|
4602
|
-
}, 1e3);
|
|
4664
|
+
}
|
|
4665
|
+
async function uploadChunkWithAbort(sessionId, chunkIndex, chunkData, deviceId, signal, retryCount = 0) {
|
|
4603
4666
|
try {
|
|
4667
|
+
if (signal.aborted) {
|
|
4668
|
+
throw new Error("Request cancelled");
|
|
4669
|
+
}
|
|
4670
|
+
const form = new import_form_data2.default();
|
|
4671
|
+
form.append("session_id", sessionId);
|
|
4672
|
+
form.append("chunk_index", chunkIndex.toString());
|
|
4673
|
+
form.append("uid", deviceId);
|
|
4674
|
+
form.append("chunk", chunkData, {
|
|
4675
|
+
filename: `chunk_${chunkIndex}`,
|
|
4676
|
+
contentType: "application/octet-stream"
|
|
4677
|
+
});
|
|
4604
4678
|
const response = await axios_default.post(
|
|
4605
|
-
`${
|
|
4606
|
-
|
|
4679
|
+
`${IPFS_API_URL}/chunk/upload`,
|
|
4680
|
+
form,
|
|
4607
4681
|
{
|
|
4608
|
-
headers: {
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
timeout: 18e5
|
|
4612
|
-
// 30 minutes timeout
|
|
4682
|
+
headers: { ...form.getHeaders() },
|
|
4683
|
+
timeout: TIMEOUT,
|
|
4684
|
+
signal
|
|
4613
4685
|
}
|
|
4614
4686
|
);
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
|
|
4618
|
-
const directoryItem = resData.find((item) => item.Name === dist);
|
|
4619
|
-
if (directoryItem) {
|
|
4620
|
-
const elapsed = Math.floor((Date.now() - startTime) / 1e3);
|
|
4621
|
-
spinner.succeed(
|
|
4622
|
-
`Successfully uploaded ${dist} (${totalFiles} files) in ${elapsed}s`
|
|
4623
|
-
);
|
|
4624
|
-
const fileCount = countFilesInDirectory(directoryPath);
|
|
4625
|
-
const uploadData = {
|
|
4626
|
-
path: directoryPath,
|
|
4627
|
-
filename: import_path4.default.basename(directoryPath),
|
|
4628
|
-
contentHash: directoryItem.Hash,
|
|
4629
|
-
previewHash: null,
|
|
4630
|
-
size: sizeCheck.size,
|
|
4631
|
-
fileCount,
|
|
4632
|
-
isDirectory: true,
|
|
4633
|
-
shortUrl: directoryItem.ShortUrl || null
|
|
4634
|
-
};
|
|
4635
|
-
saveUploadHistory(uploadData);
|
|
4636
|
-
return {
|
|
4637
|
-
hash: directoryItem.Hash,
|
|
4638
|
-
shortUrl: directoryItem.ShortUrl
|
|
4639
|
-
};
|
|
4640
|
-
}
|
|
4641
|
-
spinner.fail(`Directory hash not found in response`);
|
|
4642
|
-
console.log(import_chalk2.default.red(`Directory hash not found in response`));
|
|
4643
|
-
} else {
|
|
4644
|
-
spinner.fail(`Invalid response format from IPFS`);
|
|
4645
|
-
console.log(import_chalk2.default.red(`Invalid response format from IPFS`));
|
|
4687
|
+
const { code, msg, data } = response.data;
|
|
4688
|
+
if (code === 200 && data) {
|
|
4689
|
+
return data;
|
|
4646
4690
|
}
|
|
4647
|
-
|
|
4691
|
+
throw new Error(`Chunk upload failed: ${msg} (code: ${code})`);
|
|
4648
4692
|
} catch (error) {
|
|
4649
|
-
|
|
4650
|
-
|
|
4651
|
-
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
|
|
4655
|
-
|
|
4693
|
+
if (error.name === "CanceledError" || signal.aborted) {
|
|
4694
|
+
throw new Error("Request cancelled");
|
|
4695
|
+
}
|
|
4696
|
+
if (retryCount < MAX_RETRIES) {
|
|
4697
|
+
await delayWithAbortCheck(RETRY_DELAY, signal);
|
|
4698
|
+
return uploadChunkWithAbort(
|
|
4699
|
+
sessionId,
|
|
4700
|
+
chunkIndex,
|
|
4701
|
+
chunkData,
|
|
4702
|
+
deviceId,
|
|
4703
|
+
signal,
|
|
4704
|
+
retryCount + 1
|
|
4705
|
+
);
|
|
4706
|
+
}
|
|
4707
|
+
throw new Error(
|
|
4708
|
+
`Chunk ${chunkIndex + 1} upload failed after ${MAX_RETRIES} retries: ${error.message}`
|
|
4709
|
+
);
|
|
4710
|
+
}
|
|
4711
|
+
}
|
|
4712
|
+
async function delayWithAbortCheck(delay, signal) {
|
|
4713
|
+
return new Promise((resolve, reject) => {
|
|
4714
|
+
const timeoutId = setTimeout(() => {
|
|
4715
|
+
if (signal.aborted) {
|
|
4716
|
+
reject(new Error("Request cancelled"));
|
|
4717
|
+
} else {
|
|
4718
|
+
resolve();
|
|
4719
|
+
}
|
|
4720
|
+
}, delay);
|
|
4721
|
+
if (signal.aborted) {
|
|
4722
|
+
clearTimeout(timeoutId);
|
|
4723
|
+
reject(new Error("Request cancelled"));
|
|
4724
|
+
return;
|
|
4725
|
+
}
|
|
4726
|
+
const checkInterval = setInterval(() => {
|
|
4727
|
+
if (signal.aborted) {
|
|
4728
|
+
clearTimeout(timeoutId);
|
|
4729
|
+
clearInterval(checkInterval);
|
|
4730
|
+
reject(new Error("Request cancelled"));
|
|
4731
|
+
}
|
|
4732
|
+
}, 50);
|
|
4733
|
+
});
|
|
4734
|
+
}
|
|
4735
|
+
async function uploadFileChunks(filePath, sessionId, totalChunks, chunkSize, deviceId, progressBar) {
|
|
4736
|
+
const fileData = import_fs_extra3.default.readFileSync(filePath);
|
|
4737
|
+
const abortController = new AbortController();
|
|
4738
|
+
let completedCount = 0;
|
|
4739
|
+
let hasFatalError = false;
|
|
4740
|
+
let fatalError = null;
|
|
4741
|
+
const uploadTasks = Array.from({ length: totalChunks }, (_, chunkIndex) => {
|
|
4742
|
+
const start = chunkIndex * chunkSize;
|
|
4743
|
+
const end = Math.min(start + chunkSize, fileData.length);
|
|
4744
|
+
const chunkData = fileData.slice(start, end);
|
|
4745
|
+
return async () => {
|
|
4746
|
+
if (abortController.signal.aborted) return;
|
|
4747
|
+
try {
|
|
4748
|
+
await uploadChunkWithAbort(
|
|
4749
|
+
sessionId,
|
|
4750
|
+
chunkIndex,
|
|
4751
|
+
chunkData,
|
|
4752
|
+
deviceId,
|
|
4753
|
+
abortController.signal
|
|
4656
4754
|
);
|
|
4657
|
-
return
|
|
4755
|
+
if (abortController.signal.aborted) return;
|
|
4756
|
+
completedCount++;
|
|
4757
|
+
progressBar.updateProgress(completedCount, totalChunks);
|
|
4758
|
+
} catch (error) {
|
|
4759
|
+
if (error.name === "AbortError" || abortController.signal.aborted) {
|
|
4760
|
+
return;
|
|
4761
|
+
}
|
|
4762
|
+
hasFatalError = true;
|
|
4763
|
+
fatalError = `Chunk ${chunkIndex + 1}/${totalChunks} upload failed: ${error.message}`;
|
|
4764
|
+
abortController.abort();
|
|
4765
|
+
throw new Error(fatalError);
|
|
4658
4766
|
}
|
|
4767
|
+
};
|
|
4768
|
+
});
|
|
4769
|
+
try {
|
|
4770
|
+
const results = await Promise.allSettled(uploadTasks.map((task) => task()));
|
|
4771
|
+
const failedResults = results.filter((result) => result.status === "rejected");
|
|
4772
|
+
if (failedResults.length > 0) {
|
|
4773
|
+
const firstFailure = failedResults[0];
|
|
4774
|
+
throw new Error(firstFailure.reason.message || "Error occurred during upload");
|
|
4659
4775
|
}
|
|
4660
|
-
|
|
4661
|
-
|
|
4662
|
-
|
|
4776
|
+
if (hasFatalError) {
|
|
4777
|
+
throw new Error(fatalError || "Unknown error occurred during upload");
|
|
4778
|
+
}
|
|
4779
|
+
} catch (error) {
|
|
4780
|
+
throw fatalError ? new Error(fatalError) : error;
|
|
4663
4781
|
}
|
|
4664
4782
|
}
|
|
4665
|
-
async function
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
|
|
4669
|
-
|
|
4670
|
-
|
|
4671
|
-
|
|
4783
|
+
async function completeChunkUpload(sessionId, deviceId) {
|
|
4784
|
+
try {
|
|
4785
|
+
const response = await axios_default.post(
|
|
4786
|
+
`${IPFS_API_URL}/chunk/complete`,
|
|
4787
|
+
{ session_id: sessionId, uid: deviceId },
|
|
4788
|
+
{
|
|
4789
|
+
timeout: TIMEOUT,
|
|
4790
|
+
headers: { "Content-Type": "application/json" }
|
|
4791
|
+
}
|
|
4672
4792
|
);
|
|
4793
|
+
const { code, msg, data } = response.data;
|
|
4794
|
+
if (code === 200 && data) {
|
|
4795
|
+
return data.trace_id;
|
|
4796
|
+
}
|
|
4797
|
+
throw new Error(`Complete upload failed: ${msg} (code: ${code})`);
|
|
4798
|
+
} catch (error) {
|
|
4799
|
+
if (axios_default.isAxiosError(error)) {
|
|
4800
|
+
throw new Error(`Network error: ${error.message}`);
|
|
4801
|
+
}
|
|
4802
|
+
throw error;
|
|
4673
4803
|
}
|
|
4674
|
-
|
|
4675
|
-
|
|
4676
|
-
const spinner = (0, import_ora.default)(`Uploading ${fileName}... 0s`).start();
|
|
4677
|
-
const timeInterval = setInterval(() => {
|
|
4678
|
-
const elapsed = Math.floor((Date.now() - startTime) / 1e3);
|
|
4679
|
-
spinner.text = `Uploading ${fileName}... ${elapsed}s`;
|
|
4680
|
-
}, 1e3);
|
|
4804
|
+
}
|
|
4805
|
+
async function getChunkStatus(sessionId, deviceId) {
|
|
4681
4806
|
try {
|
|
4682
|
-
const
|
|
4683
|
-
|
|
4684
|
-
formData.append("file", import_fs_extra3.default.createReadStream(filePath), {
|
|
4685
|
-
filename: encodedFileName
|
|
4686
|
-
});
|
|
4687
|
-
const response = await axios_default.post(
|
|
4688
|
-
`${ipfsApiUrl}/add?uid=${deviceId}&cidV=1`,
|
|
4689
|
-
formData,
|
|
4807
|
+
const response = await axios_default.get(
|
|
4808
|
+
`${IPFS_API_URL}/up_status`,
|
|
4690
4809
|
{
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
}
|
|
4694
|
-
timeout: 18e5
|
|
4695
|
-
// 30 minutes timeout
|
|
4810
|
+
params: { trace_id: sessionId, uid: deviceId },
|
|
4811
|
+
timeout: TIMEOUT,
|
|
4812
|
+
headers: { "Content-Type": "application/json" }
|
|
4696
4813
|
}
|
|
4697
4814
|
);
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4703
|
-
|
|
4704
|
-
|
|
4705
|
-
|
|
4706
|
-
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4711
|
-
|
|
4712
|
-
|
|
4713
|
-
|
|
4714
|
-
|
|
4715
|
-
|
|
4815
|
+
const { code, msg, data } = response.data;
|
|
4816
|
+
if (code === 200) {
|
|
4817
|
+
return data;
|
|
4818
|
+
}
|
|
4819
|
+
throw new Error(`Server returned error: ${msg} (code: ${code})`);
|
|
4820
|
+
} catch (error) {
|
|
4821
|
+
if (axios_default.isAxiosError(error)) {
|
|
4822
|
+
throw new Error(`Network error: ${error.message}`);
|
|
4823
|
+
}
|
|
4824
|
+
throw error;
|
|
4825
|
+
}
|
|
4826
|
+
}
|
|
4827
|
+
async function monitorChunkProgress(traceId, deviceId) {
|
|
4828
|
+
let consecutiveErrors = 0;
|
|
4829
|
+
const startTime = Date.now();
|
|
4830
|
+
while (Date.now() - startTime < MAX_POLL_TIME) {
|
|
4831
|
+
try {
|
|
4832
|
+
const status = await getChunkStatus(traceId, deviceId);
|
|
4833
|
+
consecutiveErrors = 0;
|
|
4834
|
+
if (status.is_ready && status.upload_rst.Hash) {
|
|
4716
4835
|
return {
|
|
4717
|
-
hash:
|
|
4718
|
-
shortUrl:
|
|
4836
|
+
hash: status.upload_rst.Hash,
|
|
4837
|
+
shortUrl: status.upload_rst.ShortUrl
|
|
4719
4838
|
};
|
|
4720
4839
|
}
|
|
4721
|
-
|
|
4722
|
-
|
|
4723
|
-
|
|
4724
|
-
|
|
4725
|
-
console.log(import_chalk2.default.red(`Invalid response format from IPFS`));
|
|
4726
|
-
}
|
|
4727
|
-
return null;
|
|
4728
|
-
} catch (error) {
|
|
4729
|
-
clearInterval(timeInterval);
|
|
4730
|
-
if (error.response && error.response.data && error.response.data.code) {
|
|
4731
|
-
const errorCode = error.response.data.code.toString();
|
|
4732
|
-
if (ERROR_CODES[errorCode]) {
|
|
4733
|
-
spinner.fail(`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`);
|
|
4734
|
-
console.log(
|
|
4735
|
-
import_chalk2.default.red(`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`)
|
|
4736
|
-
);
|
|
4737
|
-
return null;
|
|
4840
|
+
} catch (error) {
|
|
4841
|
+
consecutiveErrors++;
|
|
4842
|
+
if (consecutiveErrors > 10) {
|
|
4843
|
+
throw new Error(`Polling failed: ${error.message}`);
|
|
4738
4844
|
}
|
|
4739
4845
|
}
|
|
4740
|
-
|
|
4741
|
-
console.log(import_chalk2.default.red(`Error: ${error.message}`));
|
|
4742
|
-
return null;
|
|
4846
|
+
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL));
|
|
4743
4847
|
}
|
|
4848
|
+
const maxPollTimeMinutes = Math.floor(MAX_POLL_TIME / (60 * 1e3));
|
|
4849
|
+
throw new Error(`Polling timeout after ${maxPollTimeMinutes} minutes`);
|
|
4744
4850
|
}
|
|
4745
|
-
async function
|
|
4746
|
-
const
|
|
4747
|
-
if (
|
|
4748
|
-
throw new Error(
|
|
4851
|
+
async function uploadDirectoryInChunks(directoryPath, deviceId) {
|
|
4852
|
+
const sizeCheck = checkDirectorySizeLimit(directoryPath);
|
|
4853
|
+
if (sizeCheck.exceeds) {
|
|
4854
|
+
throw new Error(
|
|
4855
|
+
`Directory ${directoryPath} exceeds size limit ${formatSize(sizeCheck.limit)} (size: ${formatSize(sizeCheck.size)})`
|
|
4856
|
+
);
|
|
4749
4857
|
}
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
const
|
|
4754
|
-
|
|
4755
|
-
|
|
4756
|
-
|
|
4858
|
+
const progressBar = new StepProgressBar(import_path4.default.basename(directoryPath), true);
|
|
4859
|
+
try {
|
|
4860
|
+
progressBar.startStep(0, "Preparing compression");
|
|
4861
|
+
const compressedPath = await compressDirectory(directoryPath);
|
|
4862
|
+
progressBar.completeStep();
|
|
4863
|
+
progressBar.startStep(1, "Initializing session");
|
|
4864
|
+
const sessionInfo = await initChunkSession(compressedPath, deviceId, true);
|
|
4865
|
+
progressBar.completeStep();
|
|
4866
|
+
progressBar.startStep(2, "Chunk upload");
|
|
4867
|
+
await uploadFileChunks(
|
|
4868
|
+
compressedPath,
|
|
4869
|
+
sessionInfo.session_id,
|
|
4870
|
+
sessionInfo.total_chunks,
|
|
4871
|
+
sessionInfo.chunk_size,
|
|
4872
|
+
deviceId,
|
|
4873
|
+
progressBar
|
|
4874
|
+
);
|
|
4875
|
+
progressBar.completeStep();
|
|
4876
|
+
progressBar.startStep(3, "Completing upload");
|
|
4877
|
+
const traceId = await completeChunkUpload(sessionInfo.session_id, deviceId);
|
|
4878
|
+
progressBar.completeStep();
|
|
4879
|
+
progressBar.startStep(4, "Waiting for processing");
|
|
4880
|
+
const result = await monitorChunkProgress(traceId, deviceId);
|
|
4881
|
+
progressBar.completeStep();
|
|
4882
|
+
try {
|
|
4883
|
+
import_fs_extra3.default.unlinkSync(compressedPath);
|
|
4884
|
+
} catch (error) {
|
|
4757
4885
|
}
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
contentHash
|
|
4762
|
-
|
|
4886
|
+
const uploadData = {
|
|
4887
|
+
path: directoryPath,
|
|
4888
|
+
filename: import_path4.default.basename(directoryPath),
|
|
4889
|
+
contentHash: (result == null ? void 0 : result.hash) || "unknown",
|
|
4890
|
+
size: sizeCheck.size,
|
|
4891
|
+
fileCount: 0,
|
|
4892
|
+
isDirectory: true,
|
|
4893
|
+
shortUrl: (result == null ? void 0 : result.shortUrl) || null
|
|
4894
|
+
};
|
|
4895
|
+
saveUploadHistory(uploadData);
|
|
4896
|
+
if (!(result == null ? void 0 : result.hash)) {
|
|
4897
|
+
throw new Error("Server did not return valid hash value");
|
|
4763
4898
|
}
|
|
4899
|
+
progressBar.complete();
|
|
4900
|
+
return result;
|
|
4901
|
+
} catch (error) {
|
|
4902
|
+
progressBar.fail(error.message);
|
|
4903
|
+
throw error;
|
|
4764
4904
|
}
|
|
4765
|
-
|
|
4766
|
-
|
|
4767
|
-
|
|
4905
|
+
}
|
|
4906
|
+
async function uploadFileInChunks(filePath, deviceId) {
|
|
4907
|
+
const sizeCheck = checkFileSizeLimit(filePath);
|
|
4908
|
+
if (sizeCheck.exceeds) {
|
|
4909
|
+
throw new Error(
|
|
4910
|
+
`File ${filePath} exceeds size limit ${formatSize(sizeCheck.limit)} (size: ${formatSize(sizeCheck.size)})`
|
|
4911
|
+
);
|
|
4912
|
+
}
|
|
4913
|
+
const fileName = import_path4.default.basename(filePath);
|
|
4914
|
+
const progressBar = new StepProgressBar(fileName, false);
|
|
4915
|
+
try {
|
|
4916
|
+
progressBar.startStep(0, "Initializing session");
|
|
4917
|
+
const sessionInfo = await initChunkSession(filePath, deviceId, false);
|
|
4918
|
+
progressBar.completeStep();
|
|
4919
|
+
progressBar.startStep(1, "Chunk upload");
|
|
4920
|
+
await uploadFileChunks(
|
|
4921
|
+
filePath,
|
|
4922
|
+
sessionInfo.session_id,
|
|
4923
|
+
sessionInfo.total_chunks,
|
|
4924
|
+
sessionInfo.chunk_size,
|
|
4925
|
+
deviceId,
|
|
4926
|
+
progressBar
|
|
4927
|
+
);
|
|
4928
|
+
progressBar.completeStep();
|
|
4929
|
+
progressBar.startStep(2, "Completing upload");
|
|
4930
|
+
const traceId = await completeChunkUpload(sessionInfo.session_id, deviceId);
|
|
4931
|
+
progressBar.completeStep();
|
|
4932
|
+
progressBar.startStep(3, "Waiting for processing");
|
|
4933
|
+
const result = await monitorChunkProgress(traceId, deviceId);
|
|
4934
|
+
progressBar.completeStep();
|
|
4935
|
+
const uploadData = {
|
|
4936
|
+
path: filePath,
|
|
4937
|
+
filename: fileName,
|
|
4938
|
+
contentHash: (result == null ? void 0 : result.hash) || "unknown",
|
|
4768
4939
|
previewHash: null,
|
|
4769
|
-
|
|
4940
|
+
size: sizeCheck.size,
|
|
4941
|
+
fileCount: 1,
|
|
4942
|
+
isDirectory: false,
|
|
4943
|
+
shortUrl: (result == null ? void 0 : result.shortUrl) || null
|
|
4770
4944
|
};
|
|
4945
|
+
saveUploadHistory(uploadData);
|
|
4946
|
+
if (!(result == null ? void 0 : result.hash)) {
|
|
4947
|
+
throw new Error("Server did not return valid hash value");
|
|
4948
|
+
}
|
|
4949
|
+
progressBar.complete();
|
|
4950
|
+
return result;
|
|
4951
|
+
} catch (error) {
|
|
4952
|
+
progressBar.fail(error.message);
|
|
4953
|
+
throw error;
|
|
4954
|
+
}
|
|
4955
|
+
}
|
|
4956
|
+
async function uploadToIpfs2_default(filePath) {
|
|
4957
|
+
const deviceId = getDeviceId();
|
|
4958
|
+
if (!deviceId) {
|
|
4959
|
+
throw new Error("Device ID not found");
|
|
4960
|
+
}
|
|
4961
|
+
try {
|
|
4962
|
+
const isDirectory = import_fs_extra3.default.statSync(filePath).isDirectory();
|
|
4963
|
+
const result = isDirectory ? await uploadDirectoryInChunks(filePath, deviceId) : await uploadFileInChunks(filePath, deviceId);
|
|
4964
|
+
if (result == null ? void 0 : result.hash) {
|
|
4965
|
+
return {
|
|
4966
|
+
contentHash: result.hash,
|
|
4967
|
+
previewHash: null,
|
|
4968
|
+
shortUrl: result.shortUrl
|
|
4969
|
+
};
|
|
4970
|
+
}
|
|
4971
|
+
return null;
|
|
4972
|
+
} catch (error) {
|
|
4973
|
+
return null;
|
|
4771
4974
|
}
|
|
4772
|
-
return null;
|
|
4773
4975
|
}
|
|
4774
4976
|
|
|
4775
4977
|
// bin/upload.ts
|
|
@@ -4798,7 +5000,7 @@ function checkPathSync(inputPath) {
|
|
|
4798
5000
|
}
|
|
4799
5001
|
return null;
|
|
4800
5002
|
} catch (error) {
|
|
4801
|
-
console.error(
|
|
5003
|
+
console.error(import_chalk2.default.red(`error checking path: ${error.message}`));
|
|
4802
5004
|
return null;
|
|
4803
5005
|
}
|
|
4804
5006
|
}
|
|
@@ -4817,26 +5019,27 @@ var upload_default = async (options) => {
|
|
|
4817
5019
|
if (argPath && !argPath.startsWith("-")) {
|
|
4818
5020
|
const absolutePath = checkPathSync(argPath);
|
|
4819
5021
|
if (!absolutePath) {
|
|
4820
|
-
console.log(
|
|
5022
|
+
console.log(import_chalk2.default.red(`path ${argPath} does not exist`));
|
|
4821
5023
|
return;
|
|
4822
5024
|
}
|
|
4823
|
-
console.log(
|
|
5025
|
+
console.log(import_chalk2.default.blue(`uploading ${absolutePath} to ipfs...`));
|
|
4824
5026
|
try {
|
|
4825
|
-
const result = await
|
|
5027
|
+
const result = await uploadToIpfs2_default(absolutePath);
|
|
4826
5028
|
if (result) {
|
|
4827
5029
|
const encryptedCID = encryptHash(result.contentHash, secretKey);
|
|
4828
5030
|
console.log(
|
|
4829
|
-
|
|
5031
|
+
import_chalk2.default.cyan(
|
|
4830
5032
|
import_figlet.default.textSync("Successful", { horizontalLayout: "full" })
|
|
4831
5033
|
)
|
|
4832
5034
|
);
|
|
4833
|
-
console.log(
|
|
4834
|
-
console.log(
|
|
5035
|
+
console.log(import_chalk2.default.cyan(`URL:`));
|
|
5036
|
+
console.log(import_chalk2.default.cyan(`${URL2}${encryptedCID}`));
|
|
5037
|
+
console.log(import_chalk2.default.green("\n\u{1F389} \u4E0A\u4F20\u5B8C\u6210\uFF0C\u7A0B\u5E8F\u9000\u51FA"));
|
|
4835
5038
|
}
|
|
4836
5039
|
} catch (error) {
|
|
4837
|
-
console.error(
|
|
5040
|
+
console.error(import_chalk2.default.red(`Error: ${error.message}`));
|
|
4838
5041
|
}
|
|
4839
|
-
|
|
5042
|
+
process.exit(0);
|
|
4840
5043
|
}
|
|
4841
5044
|
const answer = await import_inquirer.default.prompt([
|
|
4842
5045
|
{
|
|
@@ -4848,44 +5051,46 @@ var upload_default = async (options) => {
|
|
|
4848
5051
|
if (answer.path) {
|
|
4849
5052
|
const absolutePath = checkPathSync(answer.path);
|
|
4850
5053
|
if (!absolutePath) {
|
|
4851
|
-
console.log(
|
|
5054
|
+
console.log(import_chalk2.default.red(`path ${answer.path} does not exist`));
|
|
4852
5055
|
return;
|
|
4853
5056
|
}
|
|
4854
|
-
console.log(
|
|
5057
|
+
console.log(import_chalk2.default.blue(`uploading ${absolutePath} to ipfs...`));
|
|
4855
5058
|
try {
|
|
4856
|
-
const result = await
|
|
5059
|
+
const result = await uploadToIpfs2_default(absolutePath);
|
|
4857
5060
|
if (result) {
|
|
4858
5061
|
const encryptedCID = encryptHash(result.contentHash, secretKey);
|
|
4859
5062
|
console.log(
|
|
4860
|
-
|
|
5063
|
+
import_chalk2.default.cyan(
|
|
4861
5064
|
import_figlet.default.textSync("Successful", { horizontalLayout: "full" })
|
|
4862
5065
|
)
|
|
4863
5066
|
);
|
|
4864
|
-
console.log(
|
|
4865
|
-
console.log(
|
|
5067
|
+
console.log(import_chalk2.default.cyan(`URL:`));
|
|
5068
|
+
console.log(import_chalk2.default.cyan(`${URL2}${encryptedCID}`));
|
|
5069
|
+
console.log(import_chalk2.default.green("\n\u{1F389} \u4E0A\u4F20\u5B8C\u6210\uFF0C\u7A0B\u5E8F\u9000\u51FA"));
|
|
4866
5070
|
}
|
|
4867
5071
|
} catch (error) {
|
|
4868
|
-
console.error(
|
|
5072
|
+
console.error(import_chalk2.default.red(`Error: ${error.message}`));
|
|
4869
5073
|
}
|
|
5074
|
+
process.exit(0);
|
|
4870
5075
|
}
|
|
4871
5076
|
} catch (error) {
|
|
4872
|
-
console.error(
|
|
5077
|
+
console.error(import_chalk2.default.red(`error executing: ${error.message}`));
|
|
4873
5078
|
console.error(error.stack);
|
|
4874
5079
|
}
|
|
4875
5080
|
};
|
|
4876
5081
|
|
|
4877
5082
|
// bin/remove.ts
|
|
4878
|
-
var
|
|
5083
|
+
var import_chalk4 = __toESM(require("chalk"));
|
|
4879
5084
|
var import_inquirer2 = __toESM(require("inquirer"));
|
|
4880
5085
|
var import_figlet2 = __toESM(require("figlet"));
|
|
4881
5086
|
|
|
4882
5087
|
// bin/utils/removeFromIpfs.ts
|
|
4883
|
-
var
|
|
4884
|
-
var
|
|
5088
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
5089
|
+
var ipfsApiUrl = "https://up.pinme.dev/api/v3";
|
|
4885
5090
|
async function removeFromIpfs(value, type = "hash") {
|
|
4886
5091
|
try {
|
|
4887
5092
|
const uid = getDeviceId();
|
|
4888
|
-
console.log(
|
|
5093
|
+
console.log(import_chalk3.default.blue(`Removing content from IPFS: ${value}...`));
|
|
4889
5094
|
const queryParams = new URLSearchParams({
|
|
4890
5095
|
uid
|
|
4891
5096
|
});
|
|
@@ -4894,37 +5099,37 @@ async function removeFromIpfs(value, type = "hash") {
|
|
|
4894
5099
|
} else {
|
|
4895
5100
|
queryParams.append("arg", value);
|
|
4896
5101
|
}
|
|
4897
|
-
const response = await axios_default.post(`${
|
|
5102
|
+
const response = await axios_default.post(`${ipfsApiUrl}/block/rm?${queryParams.toString()}`, {
|
|
4898
5103
|
timeout: 3e4
|
|
4899
5104
|
// 30 seconds timeout
|
|
4900
5105
|
});
|
|
4901
5106
|
const { code, msg, data } = response.data;
|
|
4902
5107
|
if (code === 200) {
|
|
4903
|
-
console.log(
|
|
4904
|
-
console.log(
|
|
5108
|
+
console.log(import_chalk3.default.green("\u2713 Removal successful!"));
|
|
5109
|
+
console.log(import_chalk3.default.cyan(`Content ${type}: ${value} has been removed from IPFS network`));
|
|
4905
5110
|
return true;
|
|
4906
5111
|
} else {
|
|
4907
|
-
console.log(
|
|
4908
|
-
console.log(
|
|
5112
|
+
console.log(import_chalk3.default.red("\u2717 Removal failed"));
|
|
5113
|
+
console.log(import_chalk3.default.red(`Error: ${msg || "Unknown error occurred"}`));
|
|
4909
5114
|
return false;
|
|
4910
5115
|
}
|
|
4911
5116
|
} catch (error) {
|
|
4912
|
-
console.log(
|
|
5117
|
+
console.log(import_chalk3.default.red("\u2717 Removal failed", error));
|
|
4913
5118
|
if (error.response) {
|
|
4914
5119
|
const { status, data } = error.response;
|
|
4915
|
-
console.log(
|
|
5120
|
+
console.log(import_chalk3.default.red(`HTTP Error ${status}: ${(data == null ? void 0 : data.msg) || "Server error"}`));
|
|
4916
5121
|
if (status === 404) {
|
|
4917
|
-
console.log(
|
|
5122
|
+
console.log(import_chalk3.default.yellow("Content not found on the network or already removed"));
|
|
4918
5123
|
} else if (status === 403) {
|
|
4919
|
-
console.log(
|
|
5124
|
+
console.log(import_chalk3.default.yellow("Permission denied - you may not have access to remove this content"));
|
|
4920
5125
|
} else if (status === 500) {
|
|
4921
|
-
console.log(
|
|
5126
|
+
console.log(import_chalk3.default.yellow("Server internal error - please try again later"));
|
|
4922
5127
|
}
|
|
4923
5128
|
} else if (error.request) {
|
|
4924
|
-
console.log(
|
|
4925
|
-
console.log(
|
|
5129
|
+
console.log(import_chalk3.default.red("Network error: Unable to connect to IPFS service"));
|
|
5130
|
+
console.log(import_chalk3.default.yellow("Please check your internet connection and try again"));
|
|
4926
5131
|
} else {
|
|
4927
|
-
console.log(
|
|
5132
|
+
console.log(import_chalk3.default.red(`Error: ${error.message}`));
|
|
4928
5133
|
}
|
|
4929
5134
|
return false;
|
|
4930
5135
|
}
|
|
@@ -4983,30 +5188,30 @@ var remove_default = async (options) => {
|
|
|
4983
5188
|
if (argHash && !argHash.startsWith("-")) {
|
|
4984
5189
|
const parsedInput = parseInput(argHash);
|
|
4985
5190
|
if (!parsedInput) {
|
|
4986
|
-
console.log(
|
|
4987
|
-
console.log(
|
|
4988
|
-
console.log(
|
|
4989
|
-
console.log(
|
|
4990
|
-
console.log(
|
|
4991
|
-
console.log(
|
|
5191
|
+
console.log(import_chalk4.default.red(`Invalid input format: ${argHash}`));
|
|
5192
|
+
console.log(import_chalk4.default.yellow("Supported formats:"));
|
|
5193
|
+
console.log(import_chalk4.default.yellow(" - IPFS hash: bafybeig..."));
|
|
5194
|
+
console.log(import_chalk4.default.yellow(" - Full URL: https://bafybeig....pinme.dev"));
|
|
5195
|
+
console.log(import_chalk4.default.yellow(" - Subname: 3abt6ztu"));
|
|
5196
|
+
console.log(import_chalk4.default.yellow(" - Subname URL: https://3abt6ztu.pinit.eth.limo"));
|
|
4992
5197
|
return;
|
|
4993
5198
|
}
|
|
4994
5199
|
try {
|
|
4995
5200
|
const success = await removeFromIpfs(parsedInput.value, parsedInput.type);
|
|
4996
5201
|
if (success) {
|
|
4997
5202
|
console.log(
|
|
4998
|
-
|
|
5203
|
+
import_chalk4.default.cyan(
|
|
4999
5204
|
import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
|
|
5000
5205
|
)
|
|
5001
5206
|
);
|
|
5002
5207
|
}
|
|
5003
5208
|
} catch (error) {
|
|
5004
|
-
console.error(
|
|
5209
|
+
console.error(import_chalk4.default.red(`Error: ${error.message}`));
|
|
5005
5210
|
}
|
|
5006
5211
|
return;
|
|
5007
5212
|
}
|
|
5008
|
-
console.log(
|
|
5009
|
-
console.log(
|
|
5213
|
+
console.log(import_chalk4.default.yellow("\u26A0\uFE0F Warning: This action will permanently remove the content from IPFS network"));
|
|
5214
|
+
console.log(import_chalk4.default.yellow("\u26A0\uFE0F Make sure you have the correct IPFS hash"));
|
|
5010
5215
|
console.log("");
|
|
5011
5216
|
const confirmAnswer = await import_inquirer2.default.prompt([
|
|
5012
5217
|
{
|
|
@@ -5017,7 +5222,7 @@ var remove_default = async (options) => {
|
|
|
5017
5222
|
}
|
|
5018
5223
|
]);
|
|
5019
5224
|
if (!confirmAnswer.confirm) {
|
|
5020
|
-
console.log(
|
|
5225
|
+
console.log(import_chalk4.default.yellow("Operation cancelled"));
|
|
5021
5226
|
return;
|
|
5022
5227
|
}
|
|
5023
5228
|
const answer = await import_inquirer2.default.prompt([
|
|
@@ -5040,7 +5245,7 @@ var remove_default = async (options) => {
|
|
|
5040
5245
|
if (answer.input) {
|
|
5041
5246
|
const parsedInput = parseInput(answer.input.trim());
|
|
5042
5247
|
if (!parsedInput) {
|
|
5043
|
-
console.log(
|
|
5248
|
+
console.log(import_chalk4.default.red("Invalid input format"));
|
|
5044
5249
|
return;
|
|
5045
5250
|
}
|
|
5046
5251
|
const finalConfirm = await import_inquirer2.default.prompt([
|
|
@@ -5052,24 +5257,24 @@ var remove_default = async (options) => {
|
|
|
5052
5257
|
}
|
|
5053
5258
|
]);
|
|
5054
5259
|
if (!finalConfirm.confirm) {
|
|
5055
|
-
console.log(
|
|
5260
|
+
console.log(import_chalk4.default.yellow("Operation cancelled"));
|
|
5056
5261
|
return;
|
|
5057
5262
|
}
|
|
5058
5263
|
try {
|
|
5059
5264
|
const success = await removeFromIpfs(parsedInput.value, parsedInput.type);
|
|
5060
5265
|
if (success) {
|
|
5061
5266
|
console.log(
|
|
5062
|
-
|
|
5267
|
+
import_chalk4.default.cyan(
|
|
5063
5268
|
import_figlet2.default.textSync("Successful", { horizontalLayout: "full" })
|
|
5064
5269
|
)
|
|
5065
5270
|
);
|
|
5066
5271
|
}
|
|
5067
5272
|
} catch (error) {
|
|
5068
|
-
console.error(
|
|
5273
|
+
console.error(import_chalk4.default.red(`Error: ${error.message}`));
|
|
5069
5274
|
}
|
|
5070
5275
|
}
|
|
5071
5276
|
} catch (error) {
|
|
5072
|
-
console.error(
|
|
5277
|
+
console.error(import_chalk4.default.red(`Error executing remove command: ${error.message}`));
|
|
5073
5278
|
console.error(error.stack);
|
|
5074
5279
|
}
|
|
5075
5280
|
};
|
|
@@ -5078,11 +5283,11 @@ var remove_default = async (options) => {
|
|
|
5078
5283
|
import_dotenv.default.config();
|
|
5079
5284
|
function showBanner() {
|
|
5080
5285
|
console.log(
|
|
5081
|
-
|
|
5286
|
+
import_chalk5.default.cyan(
|
|
5082
5287
|
import_figlet3.default.textSync("Pinme", { horizontalLayout: "full" })
|
|
5083
5288
|
)
|
|
5084
5289
|
);
|
|
5085
|
-
console.log(
|
|
5290
|
+
console.log(import_chalk5.default.cyan("A command-line tool for uploading files to IPFS\n"));
|
|
5086
5291
|
}
|
|
5087
5292
|
var program = new import_commander.Command();
|
|
5088
5293
|
program.name("pinme").version(version).option("-v, --version", "output the current version");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinme",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.3-alpha.2",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"author": "Glitter Protocol",
|
|
27
27
|
"license": "MIT",
|
|
28
28
|
"dependencies": {
|
|
29
|
+
"archiver": "^7.0.1",
|
|
29
30
|
"axios": "^1.3.2",
|
|
30
31
|
"base-x": "^5.0.1",
|
|
31
32
|
"bip39": "^3.1.0",
|