pinme 1.0.3 → 1.0.5
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 +2 -2
- package/dist/index.js +188 -100
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -130,14 +130,14 @@ pinme help
|
|
|
130
130
|
|
|
131
131
|
## Upload Limits
|
|
132
132
|
|
|
133
|
-
- Single file size limit:
|
|
133
|
+
- Single file size limit: 20MB
|
|
134
134
|
- Total directory size limit: 500MB
|
|
135
135
|
|
|
136
136
|
## File Storage
|
|
137
137
|
|
|
138
138
|
Uploaded files are stored on the IPFS network and accessible through the Glitter Protocol's IPFS gateway. After a successful upload, you will receive:
|
|
139
139
|
|
|
140
|
-
1. IPFS hash
|
|
140
|
+
1. IPFS content hash
|
|
141
141
|
2. Accessible URL link
|
|
142
142
|
|
|
143
143
|
### Log Locations
|
package/dist/index.js
CHANGED
|
@@ -367,7 +367,7 @@ var import_chalk4 = __toESM(require("chalk"));
|
|
|
367
367
|
var import_figlet2 = __toESM(require("figlet"));
|
|
368
368
|
|
|
369
369
|
// package.json
|
|
370
|
-
var version = "1.0.
|
|
370
|
+
var version = "1.0.5";
|
|
371
371
|
|
|
372
372
|
// bin/upload.ts
|
|
373
373
|
var import_path5 = __toESM(require("path"));
|
|
@@ -386,7 +386,7 @@ var import_chalk2 = __toESM(require("chalk"));
|
|
|
386
386
|
// bin/utils/uploadLimits.ts
|
|
387
387
|
var import_fs = __toESM(require("fs"));
|
|
388
388
|
var import_path = __toESM(require("path"));
|
|
389
|
-
var FILE_SIZE_LIMIT = parseInt("
|
|
389
|
+
var FILE_SIZE_LIMIT = parseInt("20", 10) * 1024 * 1024;
|
|
390
390
|
var DIRECTORY_SIZE_LIMIT = parseInt("500", 10) * 1024 * 1024;
|
|
391
391
|
function checkFileSizeLimit(filePath) {
|
|
392
392
|
const stats = import_fs.default.statSync(filePath);
|
|
@@ -454,7 +454,8 @@ var saveUploadHistory = (uploadData) => {
|
|
|
454
454
|
previewHash: uploadData.previewHash,
|
|
455
455
|
size: uploadData.size,
|
|
456
456
|
fileCount: uploadData.fileCount || 1,
|
|
457
|
-
type: uploadData.isDirectory ? "directory" : "file"
|
|
457
|
+
type: uploadData.isDirectory ? "directory" : "file",
|
|
458
|
+
shortUrl: (uploadData == null ? void 0 : uploadData.shortUrl) || null
|
|
458
459
|
};
|
|
459
460
|
history.uploads.unshift(newRecord);
|
|
460
461
|
import_fs_extra.default.writeJsonSync(HISTORY_FILE, history, { spaces: 2 });
|
|
@@ -480,25 +481,23 @@ var displayUploadHistory = (limit = 10) => {
|
|
|
480
481
|
console.log(import_chalk.default.yellow("No upload history found."));
|
|
481
482
|
return;
|
|
482
483
|
}
|
|
483
|
-
console.log(import_chalk.default.
|
|
484
|
-
console.log(import_chalk.default.
|
|
485
|
-
history.
|
|
486
|
-
|
|
487
|
-
console.log(import_chalk.default.
|
|
488
|
-
console.log(import_chalk.default.
|
|
489
|
-
console.log(import_chalk.default.
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
console.log(import_chalk.default.cyan(`Files: ${record.fileCount}`));
|
|
484
|
+
console.log(import_chalk.default.cyan("Upload History:"));
|
|
485
|
+
console.log(import_chalk.default.cyan("-".repeat(80)));
|
|
486
|
+
const recentHistory = history.slice(-limit);
|
|
487
|
+
recentHistory.forEach((item, index) => {
|
|
488
|
+
console.log(import_chalk.default.green(`${index + 1}. ${item.filename}`));
|
|
489
|
+
console.log(import_chalk.default.white(` Path: ${item.path}`));
|
|
490
|
+
console.log(import_chalk.default.white(` Content Hash: ${item.contentHash}`));
|
|
491
|
+
if (item.shortUrl) {
|
|
492
|
+
console.log(import_chalk.default.white(` ENS URL: https://${item.shortUrl}.pinit.eth.limo`));
|
|
493
493
|
}
|
|
494
|
-
console.log(import_chalk.default.
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
console.log(import_chalk.default.cyan(`URL: https://ipfs.glitterprotocol.dev/ipfs/${record.contentHash}`));
|
|
494
|
+
console.log(import_chalk.default.white(` Size: ${formatSize(item.size)}`));
|
|
495
|
+
console.log(import_chalk.default.white(` Files: ${item.fileCount}`));
|
|
496
|
+
console.log(import_chalk.default.white(` Type: ${item.type === "directory" ? "Directory" : "File"}`));
|
|
497
|
+
if (item.timestamp) {
|
|
498
|
+
console.log(import_chalk.default.white(` Date: ${new Date(item.timestamp).toLocaleString()}`));
|
|
500
499
|
}
|
|
501
|
-
console.log(import_chalk.default.
|
|
500
|
+
console.log(import_chalk.default.cyan("-".repeat(80)));
|
|
502
501
|
});
|
|
503
502
|
const totalSize = history.reduce((sum, record) => sum + record.size, 0);
|
|
504
503
|
const totalFiles = history.reduce((sum, record) => sum + record.fileCount, 0);
|
|
@@ -539,6 +538,10 @@ function getDeviceId() {
|
|
|
539
538
|
|
|
540
539
|
// bin/utils/uploadToIpfs.ts
|
|
541
540
|
var ipfsApiUrl = "https://ipfs.glitterprotocol.dev/api/v2";
|
|
541
|
+
var ERROR_CODES = {
|
|
542
|
+
"30001": `File too large, single file max size: ${"20"}MB,single folder max size: ${"500"}MB`,
|
|
543
|
+
"30002": `Max storage quorum ${Number("1000") / 1e3} GB reached`
|
|
544
|
+
};
|
|
542
545
|
var dirPath = null;
|
|
543
546
|
function loadFilesToArrRecursively(directoryPath, dist) {
|
|
544
547
|
const filesArr = [];
|
|
@@ -551,7 +554,11 @@ function loadFilesToArrRecursively(directoryPath, dist) {
|
|
|
551
554
|
if (import_fs_extra3.default.statSync(filePath).isFile()) {
|
|
552
555
|
const sizeCheck = checkFileSizeLimit(filePath);
|
|
553
556
|
if (sizeCheck.exceeds) {
|
|
554
|
-
throw new Error(
|
|
557
|
+
throw new Error(
|
|
558
|
+
`File ${file} exceeds size limit of ${formatSize(
|
|
559
|
+
sizeCheck.limit
|
|
560
|
+
)} (size: ${formatSize(sizeCheck.size)})`
|
|
561
|
+
);
|
|
555
562
|
}
|
|
556
563
|
const filePathWithNoEndSep = filePath.replace(dirPath, "");
|
|
557
564
|
const filePathEncodeSep = filePathWithNoEndSep.replaceAll(sep, "%2F");
|
|
@@ -586,10 +593,15 @@ function countFilesInDirectory(directoryPath) {
|
|
|
586
593
|
async function uploadDirectory(directoryPath, deviceId) {
|
|
587
594
|
const sizeCheck = checkDirectorySizeLimit(directoryPath);
|
|
588
595
|
if (sizeCheck.exceeds) {
|
|
589
|
-
throw new Error(
|
|
596
|
+
throw new Error(
|
|
597
|
+
`Directory ${directoryPath} exceeds size limit of ${formatSize(
|
|
598
|
+
sizeCheck.limit
|
|
599
|
+
)} (size: ${formatSize(sizeCheck.size)})`
|
|
600
|
+
);
|
|
590
601
|
}
|
|
591
602
|
const formData = new import_form_data.default();
|
|
592
|
-
if (directoryPath.endsWith(import_path4.default.sep))
|
|
603
|
+
if (directoryPath.endsWith(import_path4.default.sep))
|
|
604
|
+
directoryPath = directoryPath.slice(0, -1);
|
|
593
605
|
const dist = directoryPath.split(import_path4.default.sep).pop() || "";
|
|
594
606
|
const files = loadFilesToArrRecursively(directoryPath, dist);
|
|
595
607
|
files.forEach((file) => {
|
|
@@ -598,94 +610,170 @@ async function uploadDirectory(directoryPath, deviceId) {
|
|
|
598
610
|
});
|
|
599
611
|
});
|
|
600
612
|
const spinner = (0, import_ora.default)(`Uploading ${directoryPath} to glitter ipfs...`).start();
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
613
|
+
try {
|
|
614
|
+
const response = await import_axios.default.post(
|
|
615
|
+
`${ipfsApiUrl}/add?uid=${deviceId}&cidV=1`,
|
|
616
|
+
formData,
|
|
617
|
+
{
|
|
618
|
+
headers: {
|
|
619
|
+
...formData.getHeaders()
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
);
|
|
623
|
+
const resData = response.data.data;
|
|
624
|
+
if (Array.isArray(resData) && resData.length > 0) {
|
|
625
|
+
const directoryItem = resData.find((item) => item.Name === dist);
|
|
626
|
+
if (directoryItem) {
|
|
627
|
+
spinner.succeed(
|
|
628
|
+
`Successfully uploaded ${directoryPath} to glitter ipfs`
|
|
629
|
+
);
|
|
630
|
+
const fileStats = import_fs_extra3.default.statSync(directoryPath);
|
|
631
|
+
const fileCount = countFilesInDirectory(directoryPath);
|
|
632
|
+
const uploadData = {
|
|
633
|
+
path: directoryPath,
|
|
634
|
+
filename: import_path4.default.basename(directoryPath),
|
|
635
|
+
contentHash: directoryItem.Hash,
|
|
636
|
+
previewHash: null,
|
|
637
|
+
size: sizeCheck.size,
|
|
638
|
+
fileCount,
|
|
639
|
+
isDirectory: true,
|
|
640
|
+
shortUrl: directoryItem.ShortUrl || null
|
|
641
|
+
};
|
|
642
|
+
saveUploadHistory(uploadData);
|
|
643
|
+
return {
|
|
644
|
+
hash: directoryItem.Hash,
|
|
645
|
+
shortUrl: directoryItem.ShortUrl
|
|
646
|
+
};
|
|
647
|
+
}
|
|
648
|
+
spinner.fail(`Directory hash not found in response`);
|
|
649
|
+
console.log(import_chalk2.default.red(`Directory hash not found in response`));
|
|
650
|
+
} else {
|
|
651
|
+
spinner.fail(`Invalid response format from IPFS`);
|
|
652
|
+
console.log(import_chalk2.default.red(`Invalid response format from IPFS`));
|
|
604
653
|
}
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
isDirectory: true
|
|
621
|
-
};
|
|
622
|
-
saveUploadHistory(uploadData);
|
|
623
|
-
return directoryItem.Hash;
|
|
654
|
+
return null;
|
|
655
|
+
} catch (error) {
|
|
656
|
+
if (error.response && error.response.data && error.response.data.code) {
|
|
657
|
+
const errorCode = error.response.data.code.toString();
|
|
658
|
+
if (ERROR_CODES[errorCode]) {
|
|
659
|
+
spinner.fail(
|
|
660
|
+
`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`
|
|
661
|
+
);
|
|
662
|
+
console.log(
|
|
663
|
+
import_chalk2.default.red(
|
|
664
|
+
`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`
|
|
665
|
+
)
|
|
666
|
+
);
|
|
667
|
+
return null;
|
|
668
|
+
}
|
|
624
669
|
}
|
|
625
|
-
spinner.fail();
|
|
626
|
-
console.log(import_chalk2.default.red(`
|
|
627
|
-
|
|
628
|
-
spinner.fail();
|
|
629
|
-
console.log(import_chalk2.default.red(`Invalid response format from IPFS`));
|
|
670
|
+
spinner.fail(`Error: ${error.message}`);
|
|
671
|
+
console.log(import_chalk2.default.red(`Error: ${error.message}`));
|
|
672
|
+
return null;
|
|
630
673
|
}
|
|
631
|
-
return null;
|
|
632
674
|
}
|
|
633
675
|
async function uploadFile(filePath, deviceId) {
|
|
634
676
|
const sizeCheck = checkFileSizeLimit(filePath);
|
|
635
677
|
if (sizeCheck.exceeds) {
|
|
636
|
-
throw new Error(
|
|
678
|
+
throw new Error(
|
|
679
|
+
`File ${filePath} exceeds size limit of ${formatSize(
|
|
680
|
+
sizeCheck.limit
|
|
681
|
+
)} (size: ${formatSize(sizeCheck.size)})`
|
|
682
|
+
);
|
|
637
683
|
}
|
|
638
|
-
const formData = new import_form_data.default();
|
|
639
|
-
formData.append("file", import_fs_extra3.default.createReadStream(filePath), {
|
|
640
|
-
filename: filePath.split(import_path4.default.sep).pop() || ""
|
|
641
|
-
});
|
|
642
684
|
const spinner = (0, import_ora.default)(`Uploading ${filePath} to glitter ipfs...`).start();
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
685
|
+
try {
|
|
686
|
+
const formData = new import_form_data.default();
|
|
687
|
+
formData.append("file", import_fs_extra3.default.createReadStream(filePath), {
|
|
688
|
+
filename: filePath.split(import_path4.default.sep).pop() || ""
|
|
689
|
+
});
|
|
690
|
+
const response = await import_axios.default.post(
|
|
691
|
+
`${ipfsApiUrl}/add?uid=${deviceId}&cidV=1`,
|
|
692
|
+
formData,
|
|
693
|
+
{
|
|
694
|
+
headers: {
|
|
695
|
+
...formData.getHeaders()
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
);
|
|
699
|
+
const resData = response.data.data;
|
|
700
|
+
if (Array.isArray(resData) && resData.length > 0) {
|
|
701
|
+
const fileItem = resData.find(
|
|
702
|
+
(item) => item.Name === filePath.split(import_path4.default.sep).pop() || ""
|
|
703
|
+
);
|
|
704
|
+
if (fileItem) {
|
|
705
|
+
spinner.succeed(`Successfully uploaded ${filePath} to glitter ipfs`);
|
|
706
|
+
const uploadData = {
|
|
707
|
+
path: filePath,
|
|
708
|
+
filename: filePath.split(import_path4.default.sep).pop() || "",
|
|
709
|
+
contentHash: fileItem.Hash,
|
|
710
|
+
previewHash: null,
|
|
711
|
+
size: sizeCheck.size,
|
|
712
|
+
fileCount: 1,
|
|
713
|
+
isDirectory: false,
|
|
714
|
+
shortUrl: fileItem.ShortUrl || null
|
|
715
|
+
};
|
|
716
|
+
saveUploadHistory(uploadData);
|
|
717
|
+
return {
|
|
718
|
+
hash: fileItem.Hash,
|
|
719
|
+
shortUrl: fileItem.ShortUrl
|
|
720
|
+
};
|
|
721
|
+
}
|
|
722
|
+
spinner.fail(`File hash not found in response`);
|
|
723
|
+
console.log(import_chalk2.default.red(`File hash not found in response`));
|
|
724
|
+
} else {
|
|
725
|
+
spinner.fail(`Invalid response format from IPFS`);
|
|
726
|
+
console.log(import_chalk2.default.red(`Invalid response format from IPFS`));
|
|
646
727
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
}
|
|
662
|
-
saveUploadHistory(uploadData);
|
|
663
|
-
return fileItem.Hash;
|
|
728
|
+
return null;
|
|
729
|
+
} catch (error) {
|
|
730
|
+
if (error.response && error.response.data && error.response.data.code) {
|
|
731
|
+
const errorCode = error.response.data.code.toString();
|
|
732
|
+
if (ERROR_CODES[errorCode]) {
|
|
733
|
+
spinner.fail(
|
|
734
|
+
`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`
|
|
735
|
+
);
|
|
736
|
+
console.log(
|
|
737
|
+
import_chalk2.default.red(
|
|
738
|
+
`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`
|
|
739
|
+
)
|
|
740
|
+
);
|
|
741
|
+
return null;
|
|
742
|
+
}
|
|
664
743
|
}
|
|
665
|
-
spinner.fail();
|
|
666
|
-
console.log(import_chalk2.default.red(`
|
|
667
|
-
|
|
668
|
-
spinner.fail();
|
|
669
|
-
console.log(import_chalk2.default.red(`Invalid response format from IPFS`));
|
|
744
|
+
spinner.fail(`Error: ${error.message}`);
|
|
745
|
+
console.log(import_chalk2.default.red(`Error: ${error.message}`));
|
|
746
|
+
return null;
|
|
670
747
|
}
|
|
671
|
-
return null;
|
|
672
748
|
}
|
|
673
749
|
async function uploadToIpfs_default(filePath) {
|
|
674
750
|
const deviceId = getDeviceId();
|
|
675
751
|
if (!deviceId) {
|
|
676
752
|
throw new Error("Device ID not found");
|
|
677
753
|
}
|
|
754
|
+
let contentHash = "";
|
|
755
|
+
let shortUrl = "";
|
|
678
756
|
if (import_fs_extra3.default.statSync(filePath).isDirectory()) {
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
757
|
+
const result = await uploadDirectory(filePath, deviceId);
|
|
758
|
+
if (result) {
|
|
759
|
+
contentHash = result.hash;
|
|
760
|
+
shortUrl = result.shortUrl || "";
|
|
761
|
+
}
|
|
683
762
|
} else {
|
|
763
|
+
const result = await uploadFile(filePath, deviceId);
|
|
764
|
+
if (result) {
|
|
765
|
+
contentHash = result.hash;
|
|
766
|
+
shortUrl = result.shortUrl || "";
|
|
767
|
+
}
|
|
768
|
+
}
|
|
769
|
+
if (contentHash) {
|
|
684
770
|
return {
|
|
685
|
-
contentHash
|
|
686
|
-
previewHash: null
|
|
771
|
+
contentHash,
|
|
772
|
+
previewHash: null,
|
|
773
|
+
shortUrl
|
|
687
774
|
};
|
|
688
775
|
}
|
|
776
|
+
return null;
|
|
689
777
|
}
|
|
690
778
|
|
|
691
779
|
// bin/upload.ts
|
|
@@ -741,15 +829,15 @@ var upload_default = async (options) => {
|
|
|
741
829
|
const result = await uploadToIpfs_default(absolutePath);
|
|
742
830
|
if (result) {
|
|
743
831
|
const encryptedCID = encryptHash(result.contentHash, secretKey);
|
|
744
|
-
console.log(
|
|
745
|
-
|
|
746
|
-
|
|
832
|
+
console.log(
|
|
833
|
+
import_chalk3.default.cyan(
|
|
834
|
+
import_figlet.default.textSync("Successful", { horizontalLayout: "full" })
|
|
835
|
+
)
|
|
836
|
+
);
|
|
747
837
|
console.log(import_chalk3.default.cyan(`URL: ${URL2}${encryptedCID}`));
|
|
748
|
-
} else {
|
|
749
|
-
console.log(import_chalk3.default.red(`upload failed`));
|
|
750
838
|
}
|
|
751
839
|
} catch (error) {
|
|
752
|
-
console.error(import_chalk3.default.red(`
|
|
840
|
+
console.error(import_chalk3.default.red(`Error: ${error.message}`));
|
|
753
841
|
}
|
|
754
842
|
return;
|
|
755
843
|
}
|
|
@@ -771,15 +859,15 @@ var upload_default = async (options) => {
|
|
|
771
859
|
const result = await uploadToIpfs_default(absolutePath);
|
|
772
860
|
if (result) {
|
|
773
861
|
const encryptedCID = encryptHash(result.contentHash, secretKey);
|
|
774
|
-
console.log(
|
|
775
|
-
|
|
776
|
-
|
|
862
|
+
console.log(
|
|
863
|
+
import_chalk3.default.cyan(
|
|
864
|
+
import_figlet.default.textSync("Successful", { horizontalLayout: "full" })
|
|
865
|
+
)
|
|
866
|
+
);
|
|
777
867
|
console.log(import_chalk3.default.cyan(`URL: ${URL2}${encryptedCID}`));
|
|
778
|
-
} else {
|
|
779
|
-
console.log(import_chalk3.default.red(`upload failed`));
|
|
780
868
|
}
|
|
781
869
|
} catch (error) {
|
|
782
|
-
console.error(import_chalk3.default.red(`
|
|
870
|
+
console.error(import_chalk3.default.red(`Error: ${error.message}`));
|
|
783
871
|
}
|
|
784
872
|
}
|
|
785
873
|
} catch (error) {
|