@lenne.tech/nest-server 10.4.2 → 10.4.3
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/dist/core/modules/file/core-file.service.d.ts +3 -0
- package/dist/core/modules/file/core-file.service.js +27 -0
- package/dist/core/modules/file/core-file.service.js.map +1 -1
- package/dist/test/test.helper.d.ts +1 -0
- package/dist/test/test.helper.js +15 -2
- package/dist/test/test.helper.js.map +1 -1
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +6 -6
- package/src/config.env.ts +1 -1
- package/src/core/modules/file/core-file.service.ts +40 -1
- package/src/test/test.helper.ts +15 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lenne.tech/nest-server",
|
|
3
|
-
"version": "10.4.
|
|
3
|
+
"version": "10.4.3",
|
|
4
4
|
"description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"node",
|
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"class-transformer": "0.5.1",
|
|
83
83
|
"class-validator": "0.14.1",
|
|
84
84
|
"compression": "1.7.4",
|
|
85
|
-
"cookie-parser": "1.4.
|
|
85
|
+
"cookie-parser": "1.4.7",
|
|
86
86
|
"ejs": "3.1.10",
|
|
87
87
|
"graphql": "16.9.0",
|
|
88
88
|
"graphql-query-complexity": "1.0.0",
|
|
@@ -90,7 +90,7 @@
|
|
|
90
90
|
"graphql-upload": "15.0.2",
|
|
91
91
|
"js-sha256": "0.11.0",
|
|
92
92
|
"json-to-graphql-query": "2.3.0",
|
|
93
|
-
"light-my-request": "6.
|
|
93
|
+
"light-my-request": "6.1.0",
|
|
94
94
|
"lodash": "4.17.21",
|
|
95
95
|
"mongodb": "6.9.0",
|
|
96
96
|
"mongoose": "7.8.2",
|
|
@@ -114,16 +114,16 @@
|
|
|
114
114
|
"@nestjs/schematics": "10.1.4",
|
|
115
115
|
"@nestjs/testing": "10.4.4",
|
|
116
116
|
"@swc/cli": "0.4.0",
|
|
117
|
-
"@swc/core": "1.7.
|
|
117
|
+
"@swc/core": "1.7.35",
|
|
118
118
|
"@swc/jest": "0.2.36",
|
|
119
119
|
"@types/compression": "1.7.5",
|
|
120
120
|
"@types/cookie-parser": "1.4.7",
|
|
121
121
|
"@types/ejs": "3.1.5",
|
|
122
122
|
"@types/express": "4.17.21",
|
|
123
123
|
"@types/jest": "29.5.13",
|
|
124
|
-
"@types/lodash": "4.17.
|
|
124
|
+
"@types/lodash": "4.17.10",
|
|
125
125
|
"@types/multer": "1.4.12",
|
|
126
|
-
"@types/node": "20.16.
|
|
126
|
+
"@types/node": "20.16.11",
|
|
127
127
|
"@types/nodemailer": "6.4.16",
|
|
128
128
|
"@types/passport": "1.0.16",
|
|
129
129
|
"@types/supertest": "6.0.2",
|
package/src/config.env.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { IServerOptions } from './core/common/interfaces/server-options.interfac
|
|
|
9
9
|
*/
|
|
10
10
|
const config: { [env: string]: IServerOptions } = {
|
|
11
11
|
// ===========================================================================
|
|
12
|
-
//
|
|
12
|
+
// Development environment
|
|
13
13
|
// ===========================================================================
|
|
14
14
|
development: {
|
|
15
15
|
automaticObjectIdFiltering: true,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { MongoGridFSOptions, MongooseGridFS, createBucket } from '@lenne.tech/mongoose-gridfs';
|
|
2
2
|
import { NotFoundException } from '@nestjs/common';
|
|
3
3
|
import { GridFSBucket, GridFSBucketReadStream, GridFSBucketReadStreamOptions } from 'mongodb';
|
|
4
|
-
import { Connection, Types } from 'mongoose';
|
|
4
|
+
import mongoose, { Connection, Types } from 'mongoose';
|
|
5
5
|
|
|
6
6
|
import { FilterArgs } from '../../common/args/filter.args';
|
|
7
7
|
import { getObjectIds, getStringIds } from '../../common/helpers/db.helper';
|
|
@@ -66,6 +66,45 @@ export abstract class CoreFileService {
|
|
|
66
66
|
return await Promise.all(promises);
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Duplicate file by name
|
|
71
|
+
*/
|
|
72
|
+
async duplicateByName(name: string, newName: string): Promise<any> {
|
|
73
|
+
return new Promise(async (resolve) => {
|
|
74
|
+
resolve(this.files.openDownloadStreamByName(name).pipe(this.files.openUploadStream(newName)));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Duplicate file by ID
|
|
80
|
+
*/
|
|
81
|
+
async duplicateById(id: string): Promise<string> {
|
|
82
|
+
const objectId = getObjectIds(id);
|
|
83
|
+
const file = await this.getFileInfo(objectId);
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
const downloadStream = this.files.openDownloadStream(objectId);
|
|
86
|
+
|
|
87
|
+
const newFileId = new mongoose.Types.ObjectId();
|
|
88
|
+
const uploadStream = this.files.openUploadStreamWithId(newFileId, file.filename, {
|
|
89
|
+
contentType: file.contentType,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
downloadStream.pipe(uploadStream);
|
|
93
|
+
|
|
94
|
+
uploadStream.on('finish', () => {
|
|
95
|
+
resolve(getStringIds(newFileId));
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
uploadStream.on('error', (err: { message: any }) => {
|
|
99
|
+
reject(new Error(`File duplication failed: ${err.message}`));
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
downloadStream.on('error', (err: { message: any }) => {
|
|
103
|
+
reject(new Error(`File download failed: ${err.message}`));
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
69
108
|
/**
|
|
70
109
|
* Get file infos via filter
|
|
71
110
|
*/
|
package/src/test/test.helper.ts
CHANGED
|
@@ -509,6 +509,13 @@ export class TestHelper {
|
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
511
|
|
|
512
|
+
// Process REST payload
|
|
513
|
+
if (attachments && requestConfig.payload) {
|
|
514
|
+
for (const [key, value] of Object.entries(requestConfig.payload)) {
|
|
515
|
+
request.field(key, value);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
512
519
|
// Response
|
|
513
520
|
if (log) {
|
|
514
521
|
console.info(requestConfig);
|
|
@@ -580,8 +587,14 @@ export class TestHelper {
|
|
|
580
587
|
if (logError && response.statusCode !== statusCode && response.statusCode >= 400) {
|
|
581
588
|
if (response && response.error && response.error.text) {
|
|
582
589
|
const errors = JSON.parse(response.error.text).errors;
|
|
583
|
-
|
|
584
|
-
console.error(util.inspect(error, false, null, true));
|
|
590
|
+
if (!errors) {
|
|
591
|
+
console.error(util.inspect(response.error.text, false, null, true));
|
|
592
|
+
} else if (Array.isArray(errors)) {
|
|
593
|
+
for (const error of errors) {
|
|
594
|
+
console.error(util.inspect(error, false, null, true));
|
|
595
|
+
}
|
|
596
|
+
} else {
|
|
597
|
+
console.error(util.inspect(errors, false, null, true));
|
|
585
598
|
}
|
|
586
599
|
}
|
|
587
600
|
}
|