From 36778419d62694b8e8d8c029e442a085c4c3ac0e Mon Sep 17 00:00:00 2001 From: Karol Wypchlo Date: Wed, 29 Sep 2021 19:57:36 +0200 Subject: [PATCH] fix --- packages/ipfs-api/src/server.ts | 8 ++++---- packages/ipfs-api/src/utils.ts | 7 +------ 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/packages/ipfs-api/src/server.ts b/packages/ipfs-api/src/server.ts index 9ce5e9df..00f3443b 100644 --- a/packages/ipfs-api/src/server.ts +++ b/packages/ipfs-api/src/server.ts @@ -1,6 +1,6 @@ import cors from "cors"; import express, { Request, Response } from "express"; -import { rmdirSync, unlinkSync } from "fs"; +import fs from "fs"; import { extension as toExtension } from "mime-types"; import { Collection } from "mongodb"; import { @@ -110,8 +110,8 @@ async function reuploadFile( const skylink = await uploadDirectory(dirPathExtracted); // cleanup files - unlinkSync(tarPath); - rmdirSync(dirPath, { recursive: true }); + fs.unlinkSync(tarPath); + fs.rmSync(dirPath, { recursive: true }); // update record await recordsDB.updateOne({ cid }, { $set: { skylink } }); @@ -127,7 +127,7 @@ async function reuploadFile( const skylink = await uploadFile(filePath); // cleanup files - unlinkSync(filePath); + fs.unlinkSync(filePath); // update record await recordsDB.updateOne({ cid }, { $set: { skylink } }); diff --git a/packages/ipfs-api/src/utils.ts b/packages/ipfs-api/src/utils.ts index 7f9ec1a4..880b7b70 100644 --- a/packages/ipfs-api/src/utils.ts +++ b/packages/ipfs-api/src/utils.ts @@ -8,14 +8,12 @@ const client = new SkynetClient(SKYNET_PORTAL); export async function contentType(cid: string): Promise { const url = `${IPFS_GATEWAY}/${cid}`; - console.log(`got(HEAD): ${url}`); const response = await got.head(url); return response.headers["content-type"]; } export async function isDirectory(cid: string): Promise { const url = `${IPFS_INFURA_API}/api/v0/object/get?arg=${cid}&encoding=json`; - console.log(`got(GET): ${url}`); const json = await got.get(url).json(); return Boolean(json["Links"].length); } @@ -29,13 +27,10 @@ export async function download( ? `${IPFS_INFURA_API}/api/v0/get?arg=${cid}&archive=true` : `${IPFS_GATEWAY}/${cid}`; - console.log(url); - return new Promise((resolve, reject) => { - console.log(`got(STREAM): ${url}`); const downloadStream = got.stream(url); downloadStream.on("error", (error) => { - console.error(`Download failed: ${error.message}`); + console.error(`Download fail ${url}: ${error.message}`); }); const fileWriterStream = createWriteStream(destination);