@tomei/media 0.11.0-dev.3 → 0.11.0-dev.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tomei/media",
3
- "version": "0.11.0-dev.3",
3
+ "version": "0.11.0-dev.5",
4
4
  "description": "NestJS package for media module",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -47,14 +47,10 @@ export abstract class BaseMedias extends ObjectBase {
47
47
  this.IsEncryptedYN = media.IsEncryptedYN;
48
48
  this.FileName = media.FileName;
49
49
  this.FileExtension = media.FileExtension;
50
- this.URL =
51
- media.URL && media.URL.includes('media')
52
- ? media.URL
53
- : this.createSaveLocation();
54
- this.FilePath =
55
- media.FilePath && media.IsExternalYN === 'Y'
56
- ? media.FilePath
57
- : this.createFilePath();
50
+ // If URL/FilePath are provided (from DB or external), use them
51
+ // Only generate paths if they're empty (new media being created)
52
+ this.URL = media.URL || this.createSaveLocation();
53
+ this.FilePath = media.FilePath || this.createFilePath();
58
54
  this.CreatedById = media.CreatedById;
59
55
  this.CreatedAt = media.CreatedAt;
60
56
  this.UpdatedById = media.UpdatedById;
@@ -67,13 +63,17 @@ export abstract class BaseMedias extends ObjectBase {
67
63
  let basePath: string;
68
64
  if (mediaFileStorageType === 'local') {
69
65
  basePath = process.env.MEDIA_LOCAL_STORAGE_PATH;
66
+ } else if (mediaFileStorageType === 's3') {
67
+ // For S3, use container name (this is just a placeholder, actual upload will set correct path)
68
+ basePath = process.env.AWS_S3_CONTAINER_NAME || 'media';
70
69
  } else {
70
+ // Azure or default
71
71
  basePath = process.env.MEDIA_AZUREBLOB_CONTAINER_NAME;
72
72
  }
73
73
 
74
74
  if (!basePath) {
75
75
  throw new BadRequestException(
76
- 'MEDIA_LOCAL_STORAGE_PATH and or MEDIA_AZUREBLOB_CONTAINER_NAME not found.',
76
+ 'Storage configuration not found. Set MEDIA_LOCAL_STORAGE_PATH, AWS_S3_CONTAINER_NAME, or MEDIA_AZUREBLOB_CONTAINER_NAME.',
77
77
  );
78
78
  }
79
79
  return basePath + `/${this.ObjectType}/${this.ObjectId}`;
@@ -1,13 +1,5 @@
1
1
  import { ComponentConfig } from '@tomei/config';
2
2
 
3
- //Centralized configuration for media module
4
- //Uses @tomei/config (ComponentConfig) with process.env fallback
5
- //
6
- //Usage:
7
- //1. In your bootstrap/main.ts, call ComponentConfig.loadAllConfig()
8
- //2. Use MediaConfig static methods to retrieve configuration values
9
- //
10
- //ComponentConfig keys should be defined in component-config.json with '@tomei/media' as the component name
11
3
  export class MediaConfig {
12
4
  private static readonly COMPONENT_NAME = '@tomei/media';
13
5
 
@@ -25,10 +17,12 @@ export class MediaConfig {
25
17
  configKey,
26
18
  );
27
19
  if (value !== undefined && value !== null) {
20
+ console.log(`MediaConfig: Using ComponentConfig for ${configKey}:`, value);
28
21
  return String(value);
29
22
  }
30
23
  } catch (error) {
31
24
  //ComponentConfig might not be loaded or key doesn't exist, fall through to process.env
25
+ console.log(`MediaConfig: ComponentConfig not available for ${configKey}, using env ${envKey}:`, process.env[envKey]);
32
26
  }
33
27
 
34
28
  //Fallback to process.env
package/src/medias.ts CHANGED
@@ -154,7 +154,10 @@ export class Medias extends BaseMedias {
154
154
  }
155
155
 
156
156
  // Upload new files
157
- await this.uploadFile(file);
157
+ const paths = await this.uploadFile(file);
158
+ // Use the actual path returned from the storage provider
159
+ this.URL = paths.filePath;
160
+ this.FilePath = `${paths.filePath}/${this.FileName}.${this.FileExtension}`;
158
161
  } catch (error) {
159
162
  throw error;
160
163
  }
@@ -175,7 +178,10 @@ export class Medias extends BaseMedias {
175
178
  isEncrypted: false,
176
179
  };
177
180
  }
178
- await this.uploadFile(file);
181
+ const paths = await this.uploadFile(file);
182
+ // Use the actual path returned from the storage provider
183
+ this.URL = paths.filePath;
184
+ this.FilePath = `${paths.filePath}/${this.FileName}.${this.FileExtension}`;
179
185
  } catch (error) {
180
186
  throw error;
181
187
  }