@programisto/edrm-storage 1.0.7 → 1.0.9

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.
@@ -1,4 +1,5 @@
1
1
  import { EnduranceRouter } from '@programisto/endurance';
2
+ import { defaultConfig } from '../config/edrm-storage.config.js';
2
3
  import { EdrmStorageService } from '../services/edrm-storage.service.js';
3
4
  class EdrmStorageRouter extends EnduranceRouter {
4
5
  storageService;
@@ -174,8 +175,14 @@ class EdrmStorageRouter extends EnduranceRouter {
174
175
  this.get('/files/:fileId/download', userOptions, async (req, res) => {
175
176
  try {
176
177
  const { fileId } = req.params;
177
- const { filename, expiresIn = 3600 } = req.query;
178
- const result = await this.storageService.getDownloadUrl(fileId, filename, parseInt(expiresIn), req.entity?._id?.toString());
178
+ const { filename } = req.query;
179
+ const defaultExp = defaultConfig.general.downloadExpiresIn;
180
+ const rawExp = req.query.expiresIn;
181
+ const parsedExp = rawExp != null && String(rawExp).trim() !== ''
182
+ ? parseInt(String(rawExp), 10)
183
+ : defaultExp;
184
+ const expiresInSec = Number.isFinite(parsedExp) && parsedExp > 0 ? parsedExp : defaultExp;
185
+ const result = await this.storageService.getDownloadUrl(fileId, filename, expiresInSec, req.entity?._id?.toString());
179
186
  return res.json({
180
187
  success: true,
181
188
  data: result
@@ -127,7 +127,8 @@ export class EdrmStorageService {
127
127
  url: downloadResponse.url,
128
128
  expiresAt: downloadResponse.expiresAt,
129
129
  filename: downloadResponse.filename,
130
- contentType: downloadResponse.contentType
130
+ contentType: fileRecord.mimeType || downloadResponse.contentType,
131
+ size: fileRecord.size
131
132
  };
132
133
  }
133
134
  async deleteFile(fileId, portalEntityId) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@programisto/edrm-storage",
4
- "version": "1.0.7",
4
+ "version": "1.0.9",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },