pinme 1.0.6 → 1.0.7
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 +10 -19
- package/package.json +1 -1
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.7";
|
|
371
371
|
|
|
372
372
|
// bin/upload.ts
|
|
373
373
|
var import_path5 = __toESM(require("path"));
|
|
@@ -627,7 +627,6 @@ async function uploadDirectory(directoryPath, deviceId) {
|
|
|
627
627
|
spinner.succeed(
|
|
628
628
|
`Successfully uploaded ${directoryPath} to glitter ipfs`
|
|
629
629
|
);
|
|
630
|
-
const fileStats = import_fs_extra3.default.statSync(directoryPath);
|
|
631
630
|
const fileCount = countFilesInDirectory(directoryPath);
|
|
632
631
|
const uploadData = {
|
|
633
632
|
path: directoryPath,
|
|
@@ -656,13 +655,9 @@ async function uploadDirectory(directoryPath, deviceId) {
|
|
|
656
655
|
if (error.response && error.response.data && error.response.data.code) {
|
|
657
656
|
const errorCode = error.response.data.code.toString();
|
|
658
657
|
if (ERROR_CODES[errorCode]) {
|
|
659
|
-
spinner.fail(
|
|
660
|
-
`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`
|
|
661
|
-
);
|
|
658
|
+
spinner.fail(`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`);
|
|
662
659
|
console.log(
|
|
663
|
-
import_chalk2.default.red(
|
|
664
|
-
`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`
|
|
665
|
-
)
|
|
660
|
+
import_chalk2.default.red(`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`)
|
|
666
661
|
);
|
|
667
662
|
return null;
|
|
668
663
|
}
|
|
@@ -684,8 +679,10 @@ async function uploadFile(filePath, deviceId) {
|
|
|
684
679
|
const spinner = (0, import_ora.default)(`Uploading ${filePath} to glitter ipfs...`).start();
|
|
685
680
|
try {
|
|
686
681
|
const formData = new import_form_data.default();
|
|
682
|
+
const fileName = filePath.split(import_path4.default.sep).pop() || "";
|
|
683
|
+
const encodedFileName = encodeURIComponent(fileName);
|
|
687
684
|
formData.append("file", import_fs_extra3.default.createReadStream(filePath), {
|
|
688
|
-
filename:
|
|
685
|
+
filename: encodedFileName
|
|
689
686
|
});
|
|
690
687
|
const response = await import_axios.default.post(
|
|
691
688
|
`${ipfsApiUrl}/add?uid=${deviceId}&cidV=1`,
|
|
@@ -698,14 +695,12 @@ async function uploadFile(filePath, deviceId) {
|
|
|
698
695
|
);
|
|
699
696
|
const resData = response.data.data;
|
|
700
697
|
if (Array.isArray(resData) && resData.length > 0) {
|
|
701
|
-
const fileItem = resData.find(
|
|
702
|
-
(item) => item.Name === filePath.split(import_path4.default.sep).pop() || ""
|
|
703
|
-
);
|
|
698
|
+
const fileItem = resData.find((item) => item.Name === fileName);
|
|
704
699
|
if (fileItem) {
|
|
705
700
|
spinner.succeed(`Successfully uploaded ${filePath} to glitter ipfs`);
|
|
706
701
|
const uploadData = {
|
|
707
702
|
path: filePath,
|
|
708
|
-
filename:
|
|
703
|
+
filename: fileName,
|
|
709
704
|
contentHash: fileItem.Hash,
|
|
710
705
|
previewHash: null,
|
|
711
706
|
size: sizeCheck.size,
|
|
@@ -730,13 +725,9 @@ async function uploadFile(filePath, deviceId) {
|
|
|
730
725
|
if (error.response && error.response.data && error.response.data.code) {
|
|
731
726
|
const errorCode = error.response.data.code.toString();
|
|
732
727
|
if (ERROR_CODES[errorCode]) {
|
|
733
|
-
spinner.fail(
|
|
734
|
-
`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`
|
|
735
|
-
);
|
|
728
|
+
spinner.fail(`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`);
|
|
736
729
|
console.log(
|
|
737
|
-
import_chalk2.default.red(
|
|
738
|
-
`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`
|
|
739
|
-
)
|
|
730
|
+
import_chalk2.default.red(`Error: ${ERROR_CODES[errorCode]} (Code: ${errorCode})`)
|
|
740
731
|
);
|
|
741
732
|
return null;
|
|
742
733
|
}
|