@net-protocol/storage 0.1.5 → 0.1.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/README.md +5 -4
- package/dist/index.js +44 -13
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +44 -13
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1081,17 +1081,37 @@ function useStorageTotalWrites({
|
|
|
1081
1081
|
var MAX_XML_DEPTH = 3;
|
|
1082
1082
|
var CONCURRENT_XML_FETCHES = 3;
|
|
1083
1083
|
function assembleXmlData(metadata, chunks, references) {
|
|
1084
|
+
const tagPositions = [];
|
|
1085
|
+
for (let i = 0; i < references.length; i++) {
|
|
1086
|
+
const ref = references[i];
|
|
1087
|
+
const chunkData2 = chunks[i];
|
|
1088
|
+
if (!chunkData2) continue;
|
|
1089
|
+
const indexAttr = ref.index !== void 0 ? ` i="${ref.index}"` : "";
|
|
1090
|
+
const operatorAttr = ref.operator ? ` o="${ref.operator}"` : "";
|
|
1091
|
+
const sourceAttr = ref.source ? ` s="${ref.source}"` : "";
|
|
1092
|
+
const xmlTag = `<net k="${ref.hash}" v="${ref.version}"${indexAttr}${operatorAttr}${sourceAttr} />`;
|
|
1093
|
+
const tagIndex = metadata.indexOf(xmlTag);
|
|
1094
|
+
if (tagIndex === -1) {
|
|
1095
|
+
continue;
|
|
1096
|
+
}
|
|
1097
|
+
tagPositions.push({
|
|
1098
|
+
ref,
|
|
1099
|
+
chunk: chunkData2,
|
|
1100
|
+
start: tagIndex,
|
|
1101
|
+
end: tagIndex + xmlTag.length,
|
|
1102
|
+
tag: xmlTag
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
tagPositions.sort((a, b) => b.start - a.start);
|
|
1084
1106
|
let result = metadata;
|
|
1085
|
-
|
|
1086
|
-
const
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
const xmlTag = `<net k="${ref.hash}" v="${ref.version}"${indexAttr}${operatorAttr}${sourceAttr} />`;
|
|
1092
|
-
result = result.replace(xmlTag, chunkData2);
|
|
1107
|
+
for (let i = 0; i < tagPositions.length; i++) {
|
|
1108
|
+
const { ref, chunk, start, end } = tagPositions[i];
|
|
1109
|
+
try {
|
|
1110
|
+
result = result.substring(0, start) + chunk + result.substring(end);
|
|
1111
|
+
} catch (error) {
|
|
1112
|
+
throw error;
|
|
1093
1113
|
}
|
|
1094
|
-
}
|
|
1114
|
+
}
|
|
1095
1115
|
return result;
|
|
1096
1116
|
}
|
|
1097
1117
|
async function fetchFromDirectStorage(reference, operator, client) {
|
|
@@ -1922,9 +1942,7 @@ var StorageClient = class {
|
|
|
1922
1942
|
const transactionConfigs = [];
|
|
1923
1943
|
for (const xmlChunk of params.xmlChunks) {
|
|
1924
1944
|
const chunks = chunkDataForStorage(xmlChunk);
|
|
1925
|
-
const chunkedHash = keccak256HashString(
|
|
1926
|
-
xmlChunk + params.operatorAddress
|
|
1927
|
-
);
|
|
1945
|
+
const chunkedHash = keccak256HashString(xmlChunk);
|
|
1928
1946
|
chunkedStorageHashes.push(chunkedHash);
|
|
1929
1947
|
const config = this.prepareChunkedPut({
|
|
1930
1948
|
key: chunkedHash,
|
|
@@ -2134,9 +2152,22 @@ function detectFileTypeFromBase64(base64Data) {
|
|
|
2134
2152
|
} catch {
|
|
2135
2153
|
}
|
|
2136
2154
|
}
|
|
2137
|
-
if (base64Data.startsWith("SUQz")
|
|
2155
|
+
if (base64Data.startsWith("SUQz")) {
|
|
2138
2156
|
return "audio/mpeg";
|
|
2139
2157
|
}
|
|
2158
|
+
if (base64Data.length >= 4) {
|
|
2159
|
+
try {
|
|
2160
|
+
const decoded = atob(base64Data.substring(0, 4));
|
|
2161
|
+
const bytes = new Uint8Array(decoded.length);
|
|
2162
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
2163
|
+
bytes[i] = decoded.charCodeAt(i);
|
|
2164
|
+
}
|
|
2165
|
+
if (bytes[0] === 255 && (bytes[1] & 240) === 240) {
|
|
2166
|
+
return "audio/mpeg";
|
|
2167
|
+
}
|
|
2168
|
+
} catch {
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2140
2171
|
if (base64Data.length > 20) {
|
|
2141
2172
|
try {
|
|
2142
2173
|
const decoded = atob(base64Data.substring(0, Math.min(50, base64Data.length)));
|