pinata 2.5.5 → 2.5.6
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/{gateway-tools-C-tdEyF2.d.mts → gateway-tools-Cx64TJRo.d.mts} +21 -0
- package/dist/{gateway-tools-C-tdEyF2.d.ts → gateway-tools-Cx64TJRo.d.ts} +21 -0
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +89 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +89 -14
- package/dist/index.mjs.map +1 -1
- package/dist/react/index.d.mts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -2439,8 +2439,12 @@ var createSignedUploadURL = async (config, options, network) => {
|
|
|
2439
2439
|
if (options.maxFileSize) {
|
|
2440
2440
|
payload.max_file_size = options.maxFileSize;
|
|
2441
2441
|
}
|
|
2442
|
-
if (options.mimeTypes) {
|
|
2443
|
-
|
|
2442
|
+
if (options.mimeTypes || options.forDirectory) {
|
|
2443
|
+
const types = new Set(options.mimeTypes ?? []);
|
|
2444
|
+
if (options.forDirectory) {
|
|
2445
|
+
types.add("directory");
|
|
2446
|
+
}
|
|
2447
|
+
payload.allow_mime_types = Array.from(types);
|
|
2444
2448
|
}
|
|
2445
2449
|
let endpoint = "https://uploads.pinata.cloud/v3";
|
|
2446
2450
|
if (config.uploadUrl) {
|
|
@@ -2881,6 +2885,89 @@ var uploadFileArray = async (config, files, network, options) => {
|
|
|
2881
2885
|
}
|
|
2882
2886
|
const jwt = options?.keys || config?.pinataJwt;
|
|
2883
2887
|
const folder = options?.metadata?.name || "folder_from_sdk";
|
|
2888
|
+
let headers;
|
|
2889
|
+
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2890
|
+
headers = {
|
|
2891
|
+
Authorization: `Bearer ${jwt}`,
|
|
2892
|
+
...config.customHeaders
|
|
2893
|
+
};
|
|
2894
|
+
} else {
|
|
2895
|
+
headers = {
|
|
2896
|
+
Authorization: `Bearer ${jwt}`,
|
|
2897
|
+
Source: "sdk/fileArray"
|
|
2898
|
+
};
|
|
2899
|
+
}
|
|
2900
|
+
if (options?.url) {
|
|
2901
|
+
const data2 = new FormData();
|
|
2902
|
+
for (const file of Array.from(files)) {
|
|
2903
|
+
const path = file.webkitRelativePath || `${folder}/${file.name}`;
|
|
2904
|
+
data2.append("file", file, path);
|
|
2905
|
+
}
|
|
2906
|
+
data2.append("network", network);
|
|
2907
|
+
data2.append("name", folder);
|
|
2908
|
+
if (options.groupId) {
|
|
2909
|
+
data2.append("group_id", options.groupId);
|
|
2910
|
+
}
|
|
2911
|
+
if (options.metadata?.keyvalues) {
|
|
2912
|
+
data2.append("keyvalues", JSON.stringify(options.metadata.keyvalues));
|
|
2913
|
+
}
|
|
2914
|
+
if (options.streamable) {
|
|
2915
|
+
data2.append("streamable", "true");
|
|
2916
|
+
}
|
|
2917
|
+
if (options.car) {
|
|
2918
|
+
data2.append("car", "true");
|
|
2919
|
+
}
|
|
2920
|
+
if (options.cid_version !== void 0) {
|
|
2921
|
+
data2.append("cid_version", options.cid_version.toString());
|
|
2922
|
+
}
|
|
2923
|
+
if (options.expires_at !== void 0) {
|
|
2924
|
+
data2.append("expires_at", options.expires_at.toString());
|
|
2925
|
+
}
|
|
2926
|
+
try {
|
|
2927
|
+
const url = new URL(options.url);
|
|
2928
|
+
const request = await fetch(url.toString(), {
|
|
2929
|
+
method: "POST",
|
|
2930
|
+
headers,
|
|
2931
|
+
body: data2
|
|
2932
|
+
});
|
|
2933
|
+
if (!request.ok) {
|
|
2934
|
+
const errorData = await request.text();
|
|
2935
|
+
if (request.status === 401 || request.status === 403) {
|
|
2936
|
+
throw new AuthenticationError(
|
|
2937
|
+
`Authentication failed: ${errorData}`,
|
|
2938
|
+
request.status,
|
|
2939
|
+
{
|
|
2940
|
+
error: errorData,
|
|
2941
|
+
code: "AUTH_ERROR",
|
|
2942
|
+
metadata: {
|
|
2943
|
+
requestUrl: request.url
|
|
2944
|
+
}
|
|
2945
|
+
}
|
|
2946
|
+
);
|
|
2947
|
+
}
|
|
2948
|
+
throw new NetworkError(`HTTP error: ${errorData}`, request.status, {
|
|
2949
|
+
error: errorData,
|
|
2950
|
+
code: "HTTP_ERROR",
|
|
2951
|
+
metadata: {
|
|
2952
|
+
requestUrl: request.url
|
|
2953
|
+
}
|
|
2954
|
+
});
|
|
2955
|
+
}
|
|
2956
|
+
const res = await request.json();
|
|
2957
|
+
const resData = res.data;
|
|
2958
|
+
return resData;
|
|
2959
|
+
} catch (error) {
|
|
2960
|
+
if (error instanceof PinataError) {
|
|
2961
|
+
throw error;
|
|
2962
|
+
}
|
|
2963
|
+
if (error instanceof Error) {
|
|
2964
|
+
throw new PinataError(`Error processing fileArray: ${error.message}`);
|
|
2965
|
+
}
|
|
2966
|
+
throw new PinataError(
|
|
2967
|
+
"An unknown error occurred while uploading an array of files"
|
|
2968
|
+
);
|
|
2969
|
+
}
|
|
2970
|
+
}
|
|
2884
2971
|
const data = new FormData();
|
|
2885
2972
|
for (const file of Array.from(files)) {
|
|
2886
2973
|
const path = file.webkitRelativePath || `${folder}/${file.name}`;
|
|
@@ -2900,18 +2987,6 @@ var uploadFileArray = async (config, files, network, options) => {
|
|
|
2900
2987
|
cidVersion: 1
|
|
2901
2988
|
})
|
|
2902
2989
|
);
|
|
2903
|
-
let headers;
|
|
2904
|
-
if (config.customHeaders && Object.keys(config.customHeaders).length > 0) {
|
|
2905
|
-
headers = {
|
|
2906
|
-
Authorization: `Bearer ${jwt}`,
|
|
2907
|
-
...config.customHeaders
|
|
2908
|
-
};
|
|
2909
|
-
} else {
|
|
2910
|
-
headers = {
|
|
2911
|
-
Authorization: `Bearer ${jwt}`,
|
|
2912
|
-
Source: "sdk/fileArray"
|
|
2913
|
-
};
|
|
2914
|
-
}
|
|
2915
2990
|
let endpoint = "https://api.pinata.cloud/pinning/pinFileToIPFS";
|
|
2916
2991
|
if (config.legacyUploadUrl) {
|
|
2917
2992
|
endpoint = config.legacyUploadUrl;
|