Skip to content

Commit

Permalink
Use stream/pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
otoyo committed Dec 2, 2023
1 parent 0d0bcf9 commit 745df32
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/lib/notion/client.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs, { createWriteStream } from 'node:fs'
import { pipeline } from 'node:stream/promises'
import axios, { AxiosResponse } from 'axios'
import sharp from 'sharp'
import retry from 'async-retry'
Expand Down Expand Up @@ -410,7 +411,13 @@ export async function downloadFile(url: URL) {
if (res.headers['content-type'] === 'image/jpeg') {
stream = stream.pipe(rotate)
}
return stream.pipe(new ExifTransformer()).pipe(writeStream)
try {
return pipeline(stream, new ExifTransformer(), writeStream)
} catch (err) {
console.log(err)
writeStream.end()
return Promise.resolve()
}
}

export async function getDatabase(): Promise<Database> {
Expand Down

0 comments on commit 745df32

Please sign in to comment.