diff --git a/packages/ipfs-api/src/server.ts b/packages/ipfs-api/src/server.ts index 87d2e9d1..ff2f9ca0 100644 --- a/packages/ipfs-api/src/server.ts +++ b/packages/ipfs-api/src/server.ts @@ -85,12 +85,16 @@ async function handleGetLink(req: Request, res: Response, recordsDB: Collection< } async function reuploadFile(cid: string, recordsDB: Collection): Promise { + console.log('reuploading file with cid', cid) + // get the content type const ct = await contentType(cid); const ext = toExtension(ct); + console.log('extension found', ext) // find out whether it's a directory const isDir = await isDirectory(cid); + console.log('is directory', isDir) // upload directory if (isDir) { @@ -118,10 +122,21 @@ async function reuploadFile(cid: string, recordsDB: Collection): Promis // download cid as file const filePath = `${UPLOAD_PATH}/${cid}.${ext}`; - await download(cid, filePath, isDir); + try { + await download(cid, filePath, isDir); + } catch (error) { + console.log('download error: ', error) + throw error; + } // upload the file - const skylink = await uploadFile(filePath); + let skylink; + try { + skylink = await uploadFile(filePath); + } catch (error) { + console.log('upload error: ', error) + throw error; + } // cleanup files fs.unlinkSync(filePath); diff --git a/packages/ipfs-api/src/utils.ts b/packages/ipfs-api/src/utils.ts index bbf64c8a..19addf19 100644 --- a/packages/ipfs-api/src/utils.ts +++ b/packages/ipfs-api/src/utils.ts @@ -20,6 +20,7 @@ export async function isDirectory(cid: string): Promise { export async function download(cid: string, destination: string, directory: boolean): Promise { const url = directory ? `${IPFS_INFURA_API}/api/v0/get?arg=${cid}&archive=true` : `${IPFS_GATEWAY}/${cid}`; + console.log('downloading from url', url) return new Promise((resolve, reject) => { const downloadStream = got.stream(url);