Skip to content

Commit 9059755

Browse files
committed
fix: video response
1 parent 8c93e78 commit 9059755

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

src/index.js

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,12 @@ class CoCreateFileSystem {
6363
});
6464

6565
if (!file || !file.document || !file.document[0])
66-
return res.status(404).send(`${url} could not be found for ${organization_id} `);
66+
return res.status(404).send(`${url} could not be found for ${organization_id}`);
6767

6868
file = file.document[0]
69-
if (!file['public'] || file['public'] === "false")
69+
if (!file['public'] || file['public'] === "false")
7070
return res.status(404).send(`access not allowed`);
7171

72-
console.log('file found', url)
7372
let src;
7473
if (file['src'])
7574
src = file['src'];
@@ -84,43 +83,23 @@ class CoCreateFileSystem {
8483
src = fileSrc[file['name']];
8584
}
8685

87-
if (!src) {
88-
console.log('src not found')
89-
// res.send('could not find src');
90-
}
86+
if (!src)
87+
return res.status(404).send(`src could not be found`);
9188

9289
let contentType = file['content-type'] || mime.lookup(url) || 'text/html';
93-
console.log('src', contentType)
9490

9591
if (contentType.startsWith('image/') || contentType.startsWith('audio/') || contentType.startsWith('video/')) {
96-
97-
var base64Data = src.replace(/^data:image\/(png|jpeg|jpg);base64,/, '');
98-
let file = Buffer.from(base64Data, 'base64');
99-
100-
// res.writeHead(200, {
101-
// 'Content-Type': contentType,
102-
// 'Content-Length': file.length
103-
// });
104-
console.log('after', contentType)
105-
res.type(contentType);
106-
res.send(file);
92+
src = src.replace(/^data:image\/(png|jpeg|jpg);base64,/, '');
93+
src = Buffer.from(base64Data, 'base64');
10794
} else if (contentType === 'text/html') {
10895
try {
109-
let html = await render.HTML(src, organization_id);
110-
if (html)
111-
src = html
112-
}
113-
catch (err) {
96+
src = await render.HTML(src, organization_id);
97+
} catch (err) {
11498
console.warn('server-render: ' + err.message)
115-
} finally {
116-
console.log('returned html')
117-
res.type(contentType);
118-
res.send(src)
11999
}
120-
} else {
121-
res.type(contentType);
122-
res.send(src);
123-
}
100+
}
101+
102+
return res.type(contentType).send(src);
124103

125104
})
126105

0 commit comments

Comments
 (0)