@cocreate/file-server 1.0.21 → 1.0.22

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.0.22](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.0.21...v1.0.22) (2022-12-06)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * video response ([9059755](https://github.com/CoCreate-app/CoCreate-file-server/commit/905975589082d547b34c6f0a581174e7860c4b36))
7
+
1
8
  ## [1.0.21](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.0.20...v1.0.21) (2022-12-05)
2
9
 
3
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.0.21",
3
+ "version": "1.0.22",
4
4
  "description": "A simple file-server component in vanilla javascript. Easily configured using HTML5 data-attributes and/or JavaScript API.",
5
5
  "keywords": [
6
6
  "file-server",
package/src/index.js CHANGED
@@ -63,13 +63,12 @@ class CoCreateFileSystem {
63
63
  });
64
64
 
65
65
  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}`);
67
67
 
68
68
  file = file.document[0]
69
- if (!file['public'] || file['public'] === "false")
69
+ if (!file['public'] || file['public'] === "false")
70
70
  return res.status(404).send(`access not allowed`);
71
71
 
72
- console.log('file found', url)
73
72
  let src;
74
73
  if (file['src'])
75
74
  src = file['src'];
@@ -84,43 +83,23 @@ class CoCreateFileSystem {
84
83
  src = fileSrc[file['name']];
85
84
  }
86
85
 
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`);
91
88
 
92
89
  let contentType = file['content-type'] || mime.lookup(url) || 'text/html';
93
- console.log('src', contentType)
94
90
 
95
91
  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');
107
94
  } else if (contentType === 'text/html') {
108
95
  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) {
114
98
  console.warn('server-render: ' + err.message)
115
- } finally {
116
- console.log('returned html')
117
- res.type(contentType);
118
- res.send(src)
119
99
  }
120
- } else {
121
- res.type(contentType);
122
- res.send(src);
123
- }
100
+ }
101
+
102
+ return res.type(contentType).send(src);
124
103
 
125
104
  })
126
105