hola-server 0.2.9 → 0.3.2

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/db/entity.js CHANGED
@@ -524,6 +524,16 @@ class Entity {
524
524
 
525
525
  const results = await this.find(query, attrs);
526
526
  if (results && results.length == 1) {
527
+ if (this.meta.after_read) {
528
+ const { code, err } = await this.meta.after_read(_id, this, attr_names, results[0]);
529
+ if (err || code != SUCCESS) {
530
+ if (is_log_error()) {
531
+ log_error(LOG_ENTITY, "after_read error:" + JSON.stringify(err) + ", with code:" + code);
532
+ }
533
+ return { code: code, err: err };
534
+ }
535
+ }
536
+
527
537
  const converted = await this.convert_ref_attrs(results);
528
538
  if (converted && converted.length == 1) {
529
539
  if (is_log_debug()) {
package/db/gridfs.js CHANGED
@@ -77,6 +77,24 @@ class GridFS {
77
77
  });
78
78
  }
79
79
 
80
+ /**
81
+ *
82
+ * @param {mongodb bucket name} bucketname
83
+ * @param {the file name} filename
84
+ * @param {the dest file name} dest_file
85
+ */
86
+ async pipe_file(bucketname, filename, dest_filename) {
87
+ const bucket = new GridFSBucket(this.db, { chunkSizeBytes: 1024 * 1024, bucketName: bucketname });
88
+ const stream = bucket.openDownloadStreamByName(filename);
89
+ const write_stream = require("fs").createWriteStream(dest_filename);
90
+
91
+ return new Promise((resolve, reject) => {
92
+ stream.pipe(write_stream)
93
+ .on('error', err => reject(err))
94
+ .on('finish', item => resolve(item));
95
+ });
96
+ }
97
+
80
98
  /**
81
99
  * Delete the files by file name
82
100
  * @param {bucket name} bucketname
@@ -179,6 +197,17 @@ const read_file = async (collection, filename, response) => {
179
197
  await instance.read_file(collection, filename, response);
180
198
  }
181
199
 
200
+ /**
201
+ * pipe file from gridfs
202
+ * @param {collection name} collection
203
+ * @param {file name} filename
204
+ * @param {dest file name} dest_filename
205
+ */
206
+ const pipe_file = async (collection, filename, dest_filename) => {
207
+ const instance = await get_gridfs_instance();
208
+ await instance.pipe_file(collection, filename, dest_filename);
209
+ }
210
+
182
211
  /**
183
212
  * delete file from gridfs
184
213
  * @param {collection name} collection
@@ -189,4 +218,4 @@ const delete_file = async (collection, filename) => {
189
218
  await instance.delete_files(collection, filename);
190
219
  }
191
220
 
192
- module.exports = { set_file_fields, save_file_fields_to_db, save_file, read_file, delete_file };
221
+ module.exports = { set_file_fields, save_file_fields_to_db, save_file, read_file, pipe_file, delete_file };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hola-server",
3
- "version": "0.2.9",
3
+ "version": "0.3.2",
4
4
  "description": "a meta programming framework used to build nodejs restful api",
5
5
  "main": "index.js",
6
6
  "scripts": {