@cocreate/file-server 1.9.1 → 1.10.0

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.
@@ -58,8 +58,7 @@ jobs:
58
58
  run: echo "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}" > ~/.npmrc
59
59
  - name: Install dependencies
60
60
  run: yarn install
61
- - name: Build
62
- run: yarn build
61
+
63
62
  - name: Set Environment Variables
64
63
  run: |
65
64
  echo "organization_id=${{ secrets.COCREATE_ORGANIZATION_ID }}" >> $GITHUB_ENV
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ # [1.10.0](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.9.2...v1.10.0) (2023-09-07)
2
+
3
+
4
+ ### Features
5
+
6
+ * defaultFile balanceFalse returned as response if organization balance false below 0 ([ecd86b1](https://github.com/CoCreate-app/CoCreate-file-server/commit/ecd86b1ee76007bbfffa88841072970804cc8e98))
7
+ * Log inBound and outBound bandwidth ([2f79c40](https://github.com/CoCreate-app/CoCreate-file-server/commit/2f79c40e8429c6cb189964a51f4a275497bc352b))
8
+
9
+ ## [1.9.2](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.9.1...v1.9.2) (2023-08-21)
10
+
11
+
12
+ ### Bug Fixes
13
+
14
+ * removed webpack.config and build step as no webpack.config exist ([f76e65f](https://github.com/CoCreate-app/CoCreate-file-server/commit/f76e65f84478ba6cd61eef0a2ca52d439b887738))
15
+
1
16
  ## [1.9.1](https://github.com/CoCreate-app/CoCreate-file-server/compare/v1.9.0...v1.9.1) (2023-08-21)
2
17
 
3
18
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/file-server",
3
- "version": "1.9.1",
3
+ "version": "1.10.0",
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
@@ -42,7 +42,7 @@ class CoCreateFileSystem {
42
42
  return file.object[0].src
43
43
  }
44
44
 
45
- let default403, default404, hostNotFound, signup
45
+ let default403, default404, hostNotFound, signup, balanceFalse
46
46
  defaultFiles('/403.html').then((file) => {
47
47
  default403 = file
48
48
  })
@@ -52,6 +52,9 @@ class CoCreateFileSystem {
52
52
  defaultFiles('/hostNotFound.html').then((file) => {
53
53
  hostNotFound = file
54
54
  })
55
+ defaultFiles('/balanceFalse').then((file) => {
56
+ balanceFalse = file
57
+ })
55
58
  defaultFiles('/superadmin/signup.html').then((file) => {
56
59
  signup = file
57
60
  })
@@ -76,22 +79,25 @@ class CoCreateFileSystem {
76
79
 
77
80
  if (!org || !org.object || !org.object[0]) {
78
81
  hostNotFound = hostNotFound || 'An organization could not be found using the host: ' + hostname + ' in platformDB: ' + process.env.organization_id
79
- res.writeHead(404, { 'Content-Type': 'text/html' });
80
- if (org.storage === false && org.error)
81
- res.setHeader('storage', 'false')
82
- else
83
- res.setHeader('storage', 'true')
84
-
82
+ res.writeHead(404, { 'Content-Type': 'text/html', 'storage': organization.storage });
85
83
  return res.end(hostNotFound);
86
84
  } else {
87
85
  organization = { _id: org.object[0]._id, storage: !!org.object[0].storage }
88
86
  organizations.set(hostname, organization)
89
87
  }
90
-
91
88
  }
92
89
 
93
90
  let organization_id = organization._id
91
+
92
+ let active = crud.wsManager.organizations.get(organization_id)
93
+ if (active === false) {
94
+ balanceFalse = balanceFalse || 'This organizations account balance has fallen bellow 0: '
95
+ res.writeHead(404, { 'Content-Type': 'text/html', 'Account-Balance': 'false', 'storage': organization.storage });
96
+ return res.end(balanceFalse);
97
+ }
98
+
94
99
  res.setHeader('organization', organization_id)
100
+ res.setHeader('storage', organization.storage);
95
101
  res.setHeader('Access-Control-Allow-Origin', '*');
96
102
  res.setHeader('Access-Control-Allow-Methods', '');
97
103
  res.setHeader('Access-Control-Allow-Headers', 'Content-Type, Authorization');
@@ -126,13 +132,21 @@ class CoCreateFileSystem {
126
132
  data.organization_id = process.env.organization_id
127
133
 
128
134
  let file = await crud.send(data);
129
- if (file.storage === false && file.error)
130
- res.setHeader('storage', 'false')
131
- else
132
- res.setHeader('storage', 'true')
133
135
 
134
136
  const fileContent = req.headers['File-Content']
135
137
  if (fileContent && !pathname.startsWith('/superadmin')) {
138
+ crud.wsManager.emit("setBandwidth", {
139
+ type: 'in',
140
+ data: fileContent,
141
+ organization_id
142
+ });
143
+
144
+ crud.wsManager.emit("setBandwidth", {
145
+ type: 'out',
146
+ data: fileContent,
147
+ organization_id
148
+ });
149
+
136
150
  res.writeHead(200, { 'Content-Type': req.headers['Content-Type'] });
137
151
  return res.end(fileContent);
138
152
  }
@@ -147,6 +161,13 @@ class CoCreateFileSystem {
147
161
  pageNotFound = default404 || `${pathname} could not be found for ${organization_id}`
148
162
  else
149
163
  pageNotFound = pageNotFound.object[0].src
164
+
165
+ crud.wsManager.emit("setBandwidth", {
166
+ type: 'out',
167
+ data: pageNotFound,
168
+ organization_id
169
+ });
170
+
150
171
  res.writeHead(404, { 'Content-Type': 'text/html' });
151
172
  return res.end(pageNotFound);
152
173
  }
@@ -162,6 +183,13 @@ class CoCreateFileSystem {
162
183
  pageForbidden = default403 || `${pathname} access not allowed for ${organization_id}`
163
184
  else
164
185
  pageForbidden = pageForbidden.object[0].src
186
+
187
+ crud.wsManager.emit("setBandwidth", {
188
+ type: 'out',
189
+ data: pageForbidden,
190
+ organization_id
191
+ });
192
+
165
193
  res.writeHead(403, { 'Content-Type': 'text/html' });
166
194
  return res.end(pageForbidden);
167
195
  }
@@ -192,6 +220,11 @@ class CoCreateFileSystem {
192
220
  else
193
221
  pageNotFound = pageNotFound.object[0].src
194
222
 
223
+ crud.wsManager.emit("setBandwidth", {
224
+ type: 'out',
225
+ data: pageNotFound,
226
+ organization_id
227
+ });
195
228
 
196
229
  res.writeHead(404, { 'Content-Type': 'text/html' });
197
230
  return res.end(pageNotFound);
@@ -212,6 +245,12 @@ class CoCreateFileSystem {
212
245
  if (file.modified)
213
246
  res.setHeader('Last-Modified', file.modified.on);
214
247
 
248
+ crud.wsManager.emit("setBandwidth", {
249
+ type: 'out',
250
+ data: src,
251
+ organization_id
252
+ });
253
+
215
254
  res.writeHead(200, { 'Content-Type': contentType });
216
255
  return res.end(src);
217
256
  } catch (error) {
package/webpack.config.js DELETED
@@ -1,90 +0,0 @@
1
- const path = require("path")
2
- const TerserPlugin = require("terser-webpack-plugin")
3
- const MiniCssExtractPlugin = require("mini-css-extract-plugin")
4
- const { CleanWebpackPlugin } = require("clean-webpack-plugin")
5
-
6
- module.exports = (env, argv) => {
7
- let isProduction = false
8
- if (argv.mode === 'production')
9
- isProduction = true
10
-
11
- const config = {
12
- entry: {
13
- "CoCreate-file-server": "./src/index.js",
14
- },
15
- output: {
16
- path: path.resolve(__dirname, "dist"),
17
- filename: isProduction ? "[name].min.js" : "[name].js",
18
- libraryTarget: "umd",
19
- libraryExport: "default",
20
- library: ["CoCreate", "file-server"],
21
- globalObject: "this",
22
- },
23
-
24
- plugins: [
25
- new CleanWebpackPlugin(),
26
- new MiniCssExtractPlugin({
27
- filename: "[name].css",
28
- }),
29
- ],
30
- // Default mode for Webpack is production.
31
- // Depending on mode Webpack will apply different things
32
- // on final bundle. For now we don't need production's JavaScript
33
- // minifying and other thing so let's set mode to development
34
- mode: isProduction ? "production" : "development",
35
- module: {
36
- rules: [
37
- {
38
- test: /.js$/,
39
- exclude: /(node_modules)/,
40
- use: {
41
- loader: "babel-loader",
42
- options: {
43
- plugins: ["@babel/plugin-transform-modules-commonjs"],
44
- },
45
- },
46
- },
47
- {
48
- test: /.css$/i,
49
- use: [
50
- { loader: "style-loader", options: { injectType: "linkTag" } },
51
- "file-loader",
52
- ],
53
- },
54
- ],
55
- },
56
-
57
- // add source map
58
- ...(isProduction ? {} : { devtool: "eval-source-map" }),
59
-
60
- optimization: {
61
- minimize: true,
62
- minimizer: [
63
- new TerserPlugin({
64
- extractComments: true,
65
- // cache: true,
66
- parallel: true,
67
- // sourceMap: true, // Must be set to true if using source-maps in production
68
- terserOptions: {
69
- // https://github.com/webpack-contrib/terser-webpack-plugin#terseroptions
70
- // extractComments: 'all',
71
- compress: {
72
- drop_console: true,
73
- },
74
- },
75
- }),
76
- ],
77
- splitChunks: {
78
- chunks: "all",
79
- minSize: 200,
80
- // maxSize: 99999,
81
- //minChunks: 1,
82
-
83
- cacheGroups: {
84
- defaultVendors: false,
85
- },
86
- },
87
- },
88
- }
89
- return config
90
- }