Download multiple times if filesize is 0
This commit is contained in:
parent
bd86eb4cce
commit
72cad4ff5c
|
@ -130,12 +130,6 @@ async function reuploadFile(cid: string, recordsDB: Collection<IRecord>): Promis
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
|
|
||||||
// sleep 3s
|
|
||||||
// TODO: hacky addition because I saw some 0-byte uploads
|
|
||||||
await sleep(3000)
|
|
||||||
const fileStats = fs.statSync(filePath)
|
|
||||||
console.log('file size', fileStats.size)
|
|
||||||
|
|
||||||
// upload the file
|
// upload the file
|
||||||
let skylink;
|
let skylink;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { SkynetClient } from "@skynetlabs/skynet-nodejs";
|
import { SkynetClient } from "@skynetlabs/skynet-nodejs";
|
||||||
import { createReadStream, createWriteStream } from "fs";
|
import { createReadStream, createWriteStream, statSync } from "fs";
|
||||||
import got from "got";
|
import got from "got";
|
||||||
import { extract } from "tar-fs";
|
import { extract } from "tar-fs";
|
||||||
import { IPFS_GATEWAY, IPFS_INFURA_API, SKYNET_PORTAL } from "./consts";
|
import { IPFS_GATEWAY, IPFS_INFURA_API, SKYNET_PORTAL } from "./consts";
|
||||||
|
@ -29,12 +29,23 @@ export async function isDirectory(cid: string): Promise<boolean> {
|
||||||
export async function download(cid: string, destination: string, directory: boolean): Promise<void> {
|
export async function download(cid: string, destination: string, directory: boolean): Promise<void> {
|
||||||
const url = directory ? `${IPFS_INFURA_API}/api/v0/get?arg=${cid}&archive=true` : `${IPFS_GATEWAY}/${cid}`;
|
const url = directory ? `${IPFS_INFURA_API}/api/v0/get?arg=${cid}&archive=true` : `${IPFS_GATEWAY}/${cid}`;
|
||||||
|
|
||||||
console.log('downloading from url', url)
|
let fileSize = 0;
|
||||||
const pipeline = promisify(stream.pipeline);
|
let attempts = 0;
|
||||||
await pipeline(
|
|
||||||
got.stream(url),
|
while (fileSize === 0 && attempts <= 3) {
|
||||||
createWriteStream(destination)
|
attempts++
|
||||||
);
|
|
||||||
|
console.log('downloading from url', url, ' attempt ', attempts)
|
||||||
|
const pipeline = promisify(stream.pipeline);
|
||||||
|
await pipeline(
|
||||||
|
got.stream(url),
|
||||||
|
createWriteStream(destination)
|
||||||
|
);
|
||||||
|
|
||||||
|
const fileStats = statSync(destination)
|
||||||
|
fileSize = fileStats.size
|
||||||
|
console.log('file size', fileSize)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function extractArchive(src: string, dst: string) {
|
export async function extractArchive(src: string, dst: string) {
|
||||||
|
|
Reference in New Issue