Add logging
This commit is contained in:
parent
2b6a738405
commit
37109a35b3
|
@ -85,12 +85,16 @@ async function handleGetLink(req: Request, res: Response, recordsDB: Collection<
|
|||
}
|
||||
|
||||
async function reuploadFile(cid: string, recordsDB: Collection<IRecord>): Promise<string> {
|
||||
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<IRecord>): 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);
|
||||
|
|
|
@ -20,6 +20,7 @@ export async function isDirectory(cid: string): Promise<boolean> {
|
|||
|
||||
export async function download(cid: string, destination: string, directory: boolean): Promise<boolean> {
|
||||
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);
|
||||
|
|
Reference in New Issue