mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-04 03:27:09 -05:00 
			
		
		
		
	feat(server) Add filetype variable to storage template (#1337)
* feat(server) Add filetype variable to storage template * Remove console.log * Added additional variable for full file type
This commit is contained in:
		
							parent
							
								
									1e1fd97b38
								
							
						
					
					
						commit
						0c582df962
					
				@ -1,5 +1,5 @@
 | 
				
			|||||||
import { APP_UPLOAD_LOCATION } from '@app/common';
 | 
					import { APP_UPLOAD_LOCATION } from '@app/common';
 | 
				
			||||||
import { AssetEntity, SystemConfig } from '@app/infra';
 | 
					import { AssetEntity, AssetType, SystemConfig } from '@app/infra';
 | 
				
			||||||
import { ImmichConfigService, INITIAL_SYSTEM_CONFIG } from '@app/immich-config';
 | 
					import { ImmichConfigService, INITIAL_SYSTEM_CONFIG } from '@app/immich-config';
 | 
				
			||||||
import { Inject, Injectable, Logger } from '@nestjs/common';
 | 
					import { Inject, Injectable, Logger } from '@nestjs/common';
 | 
				
			||||||
import { InjectRepository } from '@nestjs/typeorm';
 | 
					import { InjectRepository } from '@nestjs/typeorm';
 | 
				
			||||||
@ -128,19 +128,19 @@ export class StorageService {
 | 
				
			|||||||
  private validateStorageTemplate(templateString: string) {
 | 
					  private validateStorageTemplate(templateString: string) {
 | 
				
			||||||
    try {
 | 
					    try {
 | 
				
			||||||
      const template = this.compile(templateString);
 | 
					      const template = this.compile(templateString);
 | 
				
			||||||
 | 
					 | 
				
			||||||
      // test render an asset
 | 
					      // test render an asset
 | 
				
			||||||
      this.render(
 | 
					      this.render(
 | 
				
			||||||
        template,
 | 
					        template,
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
          createdAt: new Date().toISOString(),
 | 
					          createdAt: new Date().toISOString(),
 | 
				
			||||||
          originalPath: '/upload/test/IMG_123.jpg',
 | 
					          originalPath: '/upload/test/IMG_123.jpg',
 | 
				
			||||||
 | 
					          type: AssetType.IMAGE,
 | 
				
			||||||
        } as AssetEntity,
 | 
					        } as AssetEntity,
 | 
				
			||||||
        'IMG_123',
 | 
					        'IMG_123',
 | 
				
			||||||
        'jpg',
 | 
					        'jpg',
 | 
				
			||||||
      );
 | 
					      );
 | 
				
			||||||
    } catch (e) {
 | 
					    } catch (e) {
 | 
				
			||||||
      this.logger.warn(`Storage template validation failed: ${e}`);
 | 
					      this.logger.warn(`Storage template validation failed: ${JSON.stringify(e)}`);
 | 
				
			||||||
      throw new Error(`Invalid storage template: ${e}`);
 | 
					      throw new Error(`Invalid storage template: ${e}`);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@ -158,6 +158,9 @@ export class StorageService {
 | 
				
			|||||||
      ext,
 | 
					      ext,
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    const fileType = asset.type == AssetType.IMAGE ? 'IMG' : 'VID';
 | 
				
			||||||
 | 
					    const fileTypeFull = asset.type == AssetType.IMAGE ? 'IMAGE' : 'VIDEO';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const dt = luxon.DateTime.fromISO(new Date(asset.createdAt).toISOString());
 | 
					    const dt = luxon.DateTime.fromISO(new Date(asset.createdAt).toISOString());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const dateTokens = [
 | 
					    const dateTokens = [
 | 
				
			||||||
@ -173,6 +176,10 @@ export class StorageService {
 | 
				
			|||||||
      substitutions[token] = dt.toFormat(token);
 | 
					      substitutions[token] = dt.toFormat(token);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // Support file type token
 | 
				
			||||||
 | 
					    substitutions.filetype = fileType;
 | 
				
			||||||
 | 
					    substitutions.filetypefull = fileTypeFull;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return template(substitutions);
 | 
					    return template(substitutions);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -56,8 +56,10 @@
 | 
				
			|||||||
		});
 | 
							});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const substitutions: Record<string, string> = {
 | 
							const substitutions: Record<string, string> = {
 | 
				
			||||||
			filename: 'IMG_10041123',
 | 
								filename: 'IMAGE_56437',
 | 
				
			||||||
			ext: 'jpeg'
 | 
								ext: 'jpeg',
 | 
				
			||||||
 | 
								filetype: 'IMG',
 | 
				
			||||||
 | 
								filetypefull: 'IMAGE'
 | 
				
			||||||
		};
 | 
							};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		const dt = luxon.DateTime.fromISO(new Date('2022-09-04T20:03:05.250').toISOString());
 | 
							const dt = luxon.DateTime.fromISO(new Date('2022-09-04T20:03:05.250').toISOString());
 | 
				
			||||||
 | 
				
			|||||||
@ -17,5 +17,13 @@
 | 
				
			|||||||
				<li>{`{{ext}}`}</li>
 | 
									<li>{`{{ext}}`}</li>
 | 
				
			||||||
			</ul>
 | 
								</ul>
 | 
				
			||||||
		</div>
 | 
							</div>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
							<div>
 | 
				
			||||||
 | 
								<p class="text-immich-primary font-medium dark:text-immich-dark-primary">FILE TYPE</p>
 | 
				
			||||||
 | 
								<ul>
 | 
				
			||||||
 | 
									<li>{`{{filetype}}`} - VID or IMG</li>
 | 
				
			||||||
 | 
									<li>{`{{filetypefull}}`} - VIDEO or IMAGE</li>
 | 
				
			||||||
 | 
								</ul>
 | 
				
			||||||
 | 
							</div>
 | 
				
			||||||
	</div>
 | 
						</div>
 | 
				
			||||||
</div>
 | 
					</div>
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user