This commit is contained in:
Karol Wypchlo 2021-09-29 19:57:36 +02:00
parent 6f28c6ef79
commit 36778419d6
No known key found for this signature in database
GPG Key ID: C92C016317A964D0
2 changed files with 5 additions and 10 deletions

View File

@ -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 } });

View File

@ -8,14 +8,12 @@ const client = new SkynetClient(SKYNET_PORTAL);
export async function contentType(cid: string): Promise<string> {
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<boolean> {
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);