This commit is contained in:
Karol Wypchlo 2021-09-29 19:31:08 +02:00
parent 56391cfb19
commit 6f28c6ef79
No known key found for this signature in database
GPG Key ID: C92C016317A964D0
1 changed files with 3 additions and 0 deletions

View File

@ -8,12 +8,14 @@ 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);
} }
@ -30,6 +32,7 @@ export async function download(
console.log(url); 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 failed: ${error.message}`);