@net-protocol/storage 0.1.4 → 0.1.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/README.md +5 -4
- package/dist/index.js +43 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +43 -10
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -5
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) {
|
|
@@ -2134,9 +2154,22 @@ function detectFileTypeFromBase64(base64Data) {
|
|
|
2134
2154
|
} catch {
|
|
2135
2155
|
}
|
|
2136
2156
|
}
|
|
2137
|
-
if (base64Data.startsWith("SUQz")
|
|
2157
|
+
if (base64Data.startsWith("SUQz")) {
|
|
2138
2158
|
return "audio/mpeg";
|
|
2139
2159
|
}
|
|
2160
|
+
if (base64Data.length >= 4) {
|
|
2161
|
+
try {
|
|
2162
|
+
const decoded = atob(base64Data.substring(0, 4));
|
|
2163
|
+
const bytes = new Uint8Array(decoded.length);
|
|
2164
|
+
for (let i = 0; i < decoded.length; i++) {
|
|
2165
|
+
bytes[i] = decoded.charCodeAt(i);
|
|
2166
|
+
}
|
|
2167
|
+
if (bytes[0] === 255 && (bytes[1] & 240) === 240) {
|
|
2168
|
+
return "audio/mpeg";
|
|
2169
|
+
}
|
|
2170
|
+
} catch {
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2140
2173
|
if (base64Data.length > 20) {
|
|
2141
2174
|
try {
|
|
2142
2175
|
const decoded = atob(base64Data.substring(0, Math.min(50, base64Data.length)));
|