spice-js 2.7.11 → 2.7.13

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.
@@ -791,7 +791,7 @@ class SpiceModel {
791
791
  if ((cached_results == null ? void 0 : cached_results.value) === undefined || (yield _this6.shouldForceRefresh(cached_results))) {
792
792
  results = yield _this6.database.multi_get(args.ids, {
793
793
  keep_type: true,
794
- columns: args.columns.length > 0 && args.columns != "" ? [...args.columns, 'type'] : []
794
+ columns: args.columns && args.columns.length > 0 && args.columns != "" ? [...args.columns, 'type'] : []
795
795
  });
796
796
 
797
797
  _this6.getCacheProviderObject(_this6.type).set(key, {
@@ -802,7 +802,7 @@ class SpiceModel {
802
802
  } else {
803
803
  results = yield _this6.database.multi_get(args.ids, {
804
804
  keep_type: true,
805
- columns: args.columns.length > 0 && args.columns != "" ? [...args.columns, 'type'] : []
805
+ columns: args.columns && args.columns.length > 0 && args.columns != "" ? [...args.columns, 'type'] : []
806
806
  });
807
807
  }
808
808
  }
@@ -196,7 +196,12 @@ class RestHelper {
196
196
  ctx.set("Content-Disposition", "attachment; filename=\"" + filename + "\"");
197
197
  ctx.type = "text/csv; charset=utf-8";
198
198
  ctx.status = 200;
199
- ctx.body = fs.createReadStream(filePath);
199
+ var csvStream = fs.createReadStream(filePath); // Delete file after stream is finished
200
+
201
+ csvStream.on('close', () => {
202
+ fs.promises.unlink(filePath).catch(() => {});
203
+ });
204
+ ctx.body = csvStream;
200
205
  return {
201
206
  v: void 0
202
207
  };
@@ -213,7 +218,12 @@ class RestHelper {
213
218
  ctx.set("Content-Disposition", "attachment; filename=\"" + filename + "\"");
214
219
  ctx.type = "application/json; charset=utf-8";
215
220
  ctx.status = 200;
216
- ctx.body = fs.createReadStream(filePath);
221
+ var jsonStream = fs.createReadStream(filePath); // Delete file after stream is finished
222
+
223
+ jsonStream.on('close', () => {
224
+ fs.promises.unlink(filePath).catch(() => {});
225
+ });
226
+ ctx.body = jsonStream;
217
227
  } catch (e) {
218
228
  console.error(e.stack);
219
229
  ctx.status = 400;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spice-js",
3
- "version": "2.7.11",
3
+ "version": "2.7.13",
4
4
  "description": "spice",
5
5
  "main": "build/index.js",
6
6
  "repository": {
@@ -684,7 +684,7 @@ export default class SpiceModel {
684
684
  cached_results?.value === undefined ||
685
685
  (await this.shouldForceRefresh(cached_results))
686
686
  ) {
687
- results = await this.database.multi_get(args.ids, {keep_type:true, columns:args.columns.length > 0 && args.columns != ""?[...args.columns, 'type']:[]});
687
+ results = await this.database.multi_get(args.ids, {keep_type:true, columns:args.columns && args.columns.length > 0 && args.columns != ""?[...args.columns, 'type']:[]});
688
688
  this.getCacheProviderObject(this.type).set(
689
689
  key,
690
690
  { value: results, time: new Date().getTime() },
@@ -692,7 +692,7 @@ export default class SpiceModel {
692
692
  );
693
693
  }
694
694
  } else {
695
- results = await this.database.multi_get(args.ids, {keep_type:true, columns:args.columns.length> 0 && args.columns != ""?[...args.columns, 'type']:[]});
695
+ results = await this.database.multi_get(args.ids, {keep_type:true, columns:args.columns && args.columns.length > 0 && args.columns != ""?[...args.columns, 'type']:[]});
696
696
  }
697
697
  }
698
698
  _.remove(results, (o) => o.type != this.type);
@@ -119,18 +119,22 @@ export default class RestHelper {
119
119
  a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" })
120
120
  );
121
121
 
122
- const csv = parse(flatRows, { fields, defaultValue: "", excelStrings: true });
123
-
122
+ const csv = parse(flatRows, { fields, defaultValue: "", excelStrings: true });
123
+
124
124
  makeDirectory(`./storage/exports/csv`);
125
125
  filename = `${RestHelper.makeid(9)}.csv`;
126
126
  filePath = path.resolve(`./storage/exports/csv/${filename}`);
127
127
  await fs.promises.writeFile(filePath, csv, "utf8");
128
-
129
-
128
+
130
129
  ctx.set("Content-Disposition", `attachment; filename="${filename}"`);
131
130
  ctx.type = "text/csv; charset=utf-8";
132
131
  ctx.status = 200;
133
- ctx.body = fs.createReadStream(filePath);
132
+ const csvStream = fs.createReadStream(filePath);
133
+ // Delete file after stream is finished
134
+ csvStream.on('close', () => {
135
+ fs.promises.unlink(filePath).catch(() => {});
136
+ });
137
+ ctx.body = csvStream;
134
138
  return;
135
139
  }
136
140
 
@@ -143,7 +147,12 @@ export default class RestHelper {
143
147
  ctx.set("Content-Disposition", `attachment; filename="${filename}"`);
144
148
  ctx.type = "application/json; charset=utf-8";
145
149
  ctx.status = 200;
146
- ctx.body = fs.createReadStream(filePath);
150
+ const jsonStream = fs.createReadStream(filePath);
151
+ // Delete file after stream is finished
152
+ jsonStream.on('close', () => {
153
+ fs.promises.unlink(filePath).catch(() => {});
154
+ });
155
+ ctx.body = jsonStream;
147
156
 
148
157
  } catch (e) {
149
158
  console.error(e.stack);