listpage-next-nest 0.0.248 → 0.0.250

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.
@@ -5,6 +5,7 @@ import { CustomDecorator } from '@nestjs/common';
5
5
  import { DynamicModule } from '@nestjs/common';
6
6
  import { ExceptionFilter } from '@nestjs/common';
7
7
  import { ExecutionContext } from '@nestjs/common';
8
+ import { GetObjectCommandOutput } from '@aws-sdk/client-s3';
8
9
  import { INestApplication } from '@nestjs/common';
9
10
  import { MiddlewareConsumer } from '@nestjs/common';
10
11
  import { NestInterceptor } from '@nestjs/common';
@@ -178,6 +179,7 @@ export declare interface MinioModuleOptions {
178
179
  secretAccessKey: string;
179
180
  bucketName: string;
180
181
  region?: string;
182
+ previewEndpoint?: string;
181
183
  }
182
184
 
183
185
  export declare class MinioService {
@@ -207,6 +209,7 @@ export declare class MinioService {
207
209
  parentId: string;
208
210
  }>;
209
211
  deleteObject(assetKey: string): Promise<void>;
212
+ downloadFile(key: string): Promise<GetObjectCommandOutput>;
210
213
  private formatBytes;
211
214
  }
212
215
 
package/dist/cjs/index.js CHANGED
@@ -979,11 +979,13 @@ class MinioService {
979
979
  'gltf'
980
980
  ].includes(ext || '')) type = 'model';
981
981
  const url = `${this.options.endpoint}/${this.options.bucketName}/${key}`;
982
+ const preview = `${this.options.previewEndpoint}/${this.options.prefix}/objects/download?prefix=${key}?preview=true`;
982
983
  const name = key.split('/').pop() || key;
983
984
  assets.push({
984
985
  id: key,
985
986
  name,
986
987
  url,
988
+ preview,
987
989
  type,
988
990
  width: 0,
989
991
  height: 0,
@@ -1039,7 +1041,7 @@ class MinioService {
1039
1041
  async uploadMulterFile(file, folderId) {
1040
1042
  const prefix = folderId || '';
1041
1043
  const cleanName = file.originalname.replace(/[^a-zA-Z0-9.-]/g, '_');
1042
- const key = `${prefix}${Date.now()}-${cleanName}`;
1044
+ const key = `${prefix}${cleanName}`;
1043
1045
  const s3 = this.getClient();
1044
1046
  const command = new client_s3_namespaceObject.PutObjectCommand({
1045
1047
  Bucket: this.options.bucketName,
@@ -1073,6 +1075,14 @@ class MinioService {
1073
1075
  });
1074
1076
  await s3.send(command);
1075
1077
  }
1078
+ async downloadFile(key) {
1079
+ const s3 = this.getClient();
1080
+ const command = new client_s3_namespaceObject.GetObjectCommand({
1081
+ Bucket: this.options.bucketName,
1082
+ Key: key
1083
+ });
1084
+ return await s3.send(command);
1085
+ }
1076
1086
  formatBytes(bytes, decimals = 2) {
1077
1087
  if (!+bytes) return '0 Bytes';
1078
1088
  const k = 1024;
@@ -1139,6 +1149,19 @@ function createMinioController(prefix) {
1139
1149
  ok: true
1140
1150
  };
1141
1151
  }
1152
+ async downloadFile(key, preview, res) {
1153
+ if (!key) throw new common_namespaceObject.BadRequestException('Object key is required');
1154
+ const response = await this.service.downloadFile(key);
1155
+ const fileName = key.split('/').pop() || 'download';
1156
+ const isPreview = 'true' === preview;
1157
+ res.set({
1158
+ 'Content-Type': response.ContentType || (isPreview ? 'image/jpeg' : 'application/octet-stream'),
1159
+ 'Content-Disposition': `${isPreview ? 'inline' : 'attachment'}; filename="${encodeURIComponent(fileName)}"`,
1160
+ 'Content-Length': response.ContentLength?.toString(),
1161
+ ETag: response.ETag
1162
+ });
1163
+ return new common_namespaceObject.StreamableFile(response.Body);
1164
+ }
1142
1165
  }
1143
1166
  minio_controller_ts_decorate([
1144
1167
  (0, common_namespaceObject.Inject)(MinioService),
@@ -1192,6 +1215,21 @@ function createMinioController(prefix) {
1192
1215
  ]),
1193
1216
  minio_controller_ts_metadata("design:returntype", Promise)
1194
1217
  ], MinioController.prototype, "removeObject", null);
1218
+ minio_controller_ts_decorate([
1219
+ (0, common_namespaceObject.Get)('objects/download'),
1220
+ minio_controller_ts_param(0, (0, common_namespaceObject.Query)('prefix')),
1221
+ minio_controller_ts_param(1, (0, common_namespaceObject.Query)('preview')),
1222
+ minio_controller_ts_param(2, (0, common_namespaceObject.Response)({
1223
+ passthrough: true
1224
+ })),
1225
+ minio_controller_ts_metadata("design:type", Function),
1226
+ minio_controller_ts_metadata("design:paramtypes", [
1227
+ String,
1228
+ String,
1229
+ "undefined" == typeof ExpressResponse ? Object : ExpressResponse
1230
+ ]),
1231
+ minio_controller_ts_metadata("design:returntype", Promise)
1232
+ ], MinioController.prototype, "downloadFile", null);
1195
1233
  MinioController = minio_controller_ts_decorate([
1196
1234
  (0, common_namespaceObject.Controller)(prefix)
1197
1235
  ], MinioController);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "listpage-next-nest",
3
- "version": "0.0.248",
3
+ "version": "0.0.250",
4
4
  "description": "A React component library for creating filter forms with Ant Design",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/esm/index.js",