fix
This commit is contained in:
parent
6f28c6ef79
commit
36778419d6
|
@ -1,6 +1,6 @@
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import express, { Request, Response } from "express";
|
import express, { Request, Response } from "express";
|
||||||
import { rmdirSync, unlinkSync } from "fs";
|
import fs from "fs";
|
||||||
import { extension as toExtension } from "mime-types";
|
import { extension as toExtension } from "mime-types";
|
||||||
import { Collection } from "mongodb";
|
import { Collection } from "mongodb";
|
||||||
import {
|
import {
|
||||||
|
@ -110,8 +110,8 @@ async function reuploadFile(
|
||||||
const skylink = await uploadDirectory(dirPathExtracted);
|
const skylink = await uploadDirectory(dirPathExtracted);
|
||||||
|
|
||||||
// cleanup files
|
// cleanup files
|
||||||
unlinkSync(tarPath);
|
fs.unlinkSync(tarPath);
|
||||||
rmdirSync(dirPath, { recursive: true });
|
fs.rmSync(dirPath, { recursive: true });
|
||||||
|
|
||||||
// update record
|
// update record
|
||||||
await recordsDB.updateOne({ cid }, { $set: { skylink } });
|
await recordsDB.updateOne({ cid }, { $set: { skylink } });
|
||||||
|
@ -127,7 +127,7 @@ async function reuploadFile(
|
||||||
const skylink = await uploadFile(filePath);
|
const skylink = await uploadFile(filePath);
|
||||||
|
|
||||||
// cleanup files
|
// cleanup files
|
||||||
unlinkSync(filePath);
|
fs.unlinkSync(filePath);
|
||||||
|
|
||||||
// update record
|
// update record
|
||||||
await recordsDB.updateOne({ cid }, { $set: { skylink } });
|
await recordsDB.updateOne({ cid }, { $set: { skylink } });
|
||||||
|
|
|
@ -8,14 +8,12 @@ const client = new SkynetClient(SKYNET_PORTAL);
|
||||||
|
|
||||||
export async function contentType(cid: string): Promise<string> {
|
export async function contentType(cid: string): Promise<string> {
|
||||||
const url = `${IPFS_GATEWAY}/${cid}`;
|
const url = `${IPFS_GATEWAY}/${cid}`;
|
||||||
console.log(`got(HEAD): ${url}`);
|
|
||||||
const response = await got.head(url);
|
const response = await got.head(url);
|
||||||
return response.headers["content-type"];
|
return response.headers["content-type"];
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function isDirectory(cid: string): Promise<boolean> {
|
export async function isDirectory(cid: string): Promise<boolean> {
|
||||||
const url = `${IPFS_INFURA_API}/api/v0/object/get?arg=${cid}&encoding=json`;
|
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();
|
const json = await got.get(url).json();
|
||||||
return Boolean(json["Links"].length);
|
return Boolean(json["Links"].length);
|
||||||
}
|
}
|
||||||
|
@ -29,13 +27,10 @@ export async function download(
|
||||||
? `${IPFS_INFURA_API}/api/v0/get?arg=${cid}&archive=true`
|
? `${IPFS_INFURA_API}/api/v0/get?arg=${cid}&archive=true`
|
||||||
: `${IPFS_GATEWAY}/${cid}`;
|
: `${IPFS_GATEWAY}/${cid}`;
|
||||||
|
|
||||||
console.log(url);
|
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
console.log(`got(STREAM): ${url}`);
|
|
||||||
const downloadStream = got.stream(url);
|
const downloadStream = got.stream(url);
|
||||||
downloadStream.on("error", (error) => {
|
downloadStream.on("error", (error) => {
|
||||||
console.error(`Download failed: ${error.message}`);
|
console.error(`Download fail ${url}: ${error.message}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
const fileWriterStream = createWriteStream(destination);
|
const fileWriterStream = createWriteStream(destination);
|
||||||
|
|
Reference in New Issue