@cocreate/file-server 1.0.20 → 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,17 @@
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
+
8
+ ## [1.0.21](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.0.20...v1.0.21) (2022-12-05)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * testing ([a9b246d](https://github.com/CoCreate-app/CoCreate-file-server/commit/a9b246d9ed42395b81ae60b82f19e98025e72a7b))
14
+
1
15
  ## [1.0.20](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.0.19...v1.0.20) (2022-12-05)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.0.20",
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,45 +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
- console.log('before media', contentType, src)
97
-
98
- var base64Data = src.replace(/^data:image\/(png|jpeg|jpg);base64,/, '');
99
- let file = Buffer.from(base64Data, 'base64');
100
- console.log('file', contentType, file)
101
-
102
- // res.writeHead(200, {
103
- // 'Content-Type': contentType,
104
- // 'Content-Length': file.length
105
- // });
106
- console.log('after write', contentType)
107
- res.type(contentType);
108
- res.send(file);
92
+ src = src.replace(/^data:image\/(png|jpeg|jpg);base64,/, '');
93
+ src = Buffer.from(base64Data, 'base64');
109
94
  } else if (contentType === 'text/html') {
110
95
  try {
111
- let html = await render.HTML(src, organization_id);
112
- if (html)
113
- src = html
114
- }
115
- catch (err) {
96
+ src = await render.HTML(src, organization_id);
97
+ } catch (err) {
116
98
  console.warn('server-render: ' + err.message)
117
- } finally {
118
- console.log('returned html')
119
- res.type(contentType);
120
- res.send(src)
121
99
  }
122
- } else {
123
- res.type(contentType);
124
- res.send(src);
125
- }
100
+ }
101
+
102
+ return res.type(contentType).send(src);
126
103
 
127
104
  })
128
105