Skip to content

Commit

Permalink
fix(plugin-media): handling stream errors for fs
Browse files Browse the repository at this point in the history
  • Loading branch information
tristanMatthias committed Jan 20, 2019
1 parent 9054511 commit 591b946
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions packages/admin/src/components/pages/Admin/Media/PageMedia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class PageMedia extends connect(store)(LitElement) {
}

public render() {
const animation = 0.025;
const animation = 0.0125;
return html`
${CSS}
${this._loading
Expand All @@ -36,7 +36,9 @@ export class PageMedia extends connect(store)(LitElement) {
<ui-image src="/api/v1/media/${r.id}?width=400" />
</div>
<div class="details">
<span>${r.name}</span>
<span>
${r.name}
</span>
<ui-avatar user="${r.author}"></ui-avatar>
</div>
</li>
Expand Down
9 changes: 6 additions & 3 deletions packages/plugin-media/src/providers/filesystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,13 @@ export const handlerGet = (
res.header('content-type', file.type);


try {
let stream: Readable = fs.createReadStream(path.resolve(location, file.id));
let stream: Readable = fs.createReadStream(path.resolve(location, file.id));
stream.on('error', (err) => {
next(err);
return;
});

try {
if (req.query.width) {
const width = parseInt(req.query.width);
if (typeof width === 'number') {
Expand All @@ -98,7 +102,6 @@ export const handlerGet = (
res.locals.content.set(stream);
next();


} catch (e) {
next(e);
}
Expand Down

0 comments on commit 591b946

Please sign in to comment.