Skip to content

Commit baa0b06

Browse files
committed
fix: update retrieveBlueprintAsset to return a Promise and await its result in the assets route
1 parent 3fa2bad commit baa0b06

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

meteor/server/api/blueprints/api.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export async function uploadBlueprintAsset(cred: RequestCredentials, fileId: str
127127
await fsp.mkdir(assetDirPath, { recursive: true })
128128
await fsp.writeFile(assetPath, data)
129129
}
130-
export function retrieveBlueprintAsset(_cred: RequestCredentials, fileId: string): ReadStream {
130+
export async function retrieveBlueprintAsset(_cred: RequestCredentials, fileId: string): Promise<ReadStream> {
131131
check(fileId, String)
132132

133133
const storePath = getSystemStorePath()
@@ -137,7 +137,11 @@ export function retrieveBlueprintAsset(_cred: RequestCredentials, fileId: string
137137
throw new Error('Requested asset outside of asset storage path')
138138
}
139139

140-
return createReadStream(assetPath)
140+
const stream = createReadStream(assetPath)
141+
return new Promise((resolve, reject) => {
142+
stream.on('open', () => resolve(stream))
143+
stream.on('error', (err) => reject(err))
144+
})
141145
}
142146
/** Only to be called from internal functions */
143147
export async function internalUploadBlueprint(

meteor/server/api/blueprints/http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ blueprintsRouter.get('/assets/*fileId', async (ctx) => {
187187
const filePath = ctx.params.fileId
188188
if (filePath.match(/\.(png|svg|gif)?$/)) {
189189
try {
190-
const dataStream = retrieveBlueprintAsset(ctx, filePath)
190+
const dataStream = await retrieveBlueprintAsset(ctx, filePath)
191191
const extension = path.extname(filePath)
192192
if (extension === '.svg') {
193193
ctx.response.type = 'image/svg+xml'

0 commit comments

Comments
 (0)