*refactor continued
This commit is contained in:
parent
9f0daf8952
commit
d0646ac7c4
|
@ -179,21 +179,6 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
for await (const chunk of reader.iterable()) {
|
for await (const chunk of reader.iterable()) {
|
||||||
streamWriter.write(chunk);
|
streamWriter.write(chunk);
|
||||||
if (bufferRead < fileTypeBufferLength) {
|
|
||||||
if (chunk.length >= fileTypeBufferLength) {
|
|
||||||
mimeBuffer.push(chunk.slice(0, fileTypeBufferLength));
|
|
||||||
bufferRead += fileTypeBufferLength;
|
|
||||||
} else {
|
|
||||||
mimeBuffer.push(chunk);
|
|
||||||
bufferRead += chunk.length;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bufferRead >= fileTypeBufferLength) {
|
|
||||||
checkMime = true;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
checkMime = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
streamWriter.releaseLock();
|
streamWriter.releaseLock();
|
||||||
|
@ -201,25 +186,6 @@ export default class IpfsProvider extends BaseProvider {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (checkMime) {
|
|
||||||
const mime = await fileTypeFromBuffer(
|
|
||||||
mimeBuffer.reduce((acc, val) => {
|
|
||||||
return new Uint8Array([...acc, ...val]);
|
|
||||||
}, new Uint8Array())
|
|
||||||
);
|
|
||||||
|
|
||||||
if (mime) {
|
|
||||||
provider.setData(details, "contentType", mime.mime);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mime) {
|
|
||||||
const ext = path.parse(urlPath).ext.replace(".", "");
|
|
||||||
if (extToMimes.has(ext)) {
|
|
||||||
provider.setData(details, "contentType", extToMimes.get(ext));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
streamWriter.releaseLock();
|
streamWriter.releaseLock();
|
||||||
reqStream.close();
|
reqStream.close();
|
||||||
})();
|
})();
|
||||||
|
|
Reference in New Issue