fix bug on local

This commit is contained in:
cupcakearmy 2022-02-05 23:21:59 +01:00
parent 432d9dd140
commit 6f3f9dd9d9
No known key found for this signature in database
GPG Key ID: 3235314B4D31232F

View File

@ -1,6 +1,7 @@
import fs from 'fs' import fs from 'fs'
import { join, resolve } from 'path' import { join, resolve } from 'path'
import { promisify } from 'util' import { promisify } from 'util'
import { App } from '..'
import { Storage } from './' import { Storage } from './'
@ -37,8 +38,9 @@ export class Local implements Storage {
}) })
} }
readStream(path: string): Promise<NodeJS.ReadableStream> { async readStream(path: string): Promise<NodeJS.ReadableStream> {
const file = join(this.root, path) const file = join(this.root, path)
if (!(await this.exists(path))) throw new Error(`File not found: ${path}`)
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
const stream = fs.createReadStream(file) const stream = fs.createReadStream(file)
stream.on('error', reject) stream.on('error', reject)