1
0
mirror of https://github.com/immich-app/immich.git synced 2024-12-25 10:43:13 +02: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:
Alex 2023-01-16 15:54:52 -06:00 committed by GitHub
parent 1e1fd97b38
commit 0c582df962
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 5 deletions

View File

@ -1,5 +1,5 @@
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 { Inject, Injectable, Logger } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
@ -128,19 +128,19 @@ export class StorageService {
private validateStorageTemplate(templateString: string) {
try {
const template = this.compile(templateString);
// test render an asset
this.render(
template,
{
createdAt: new Date().toISOString(),
originalPath: '/upload/test/IMG_123.jpg',
type: AssetType.IMAGE,
} as AssetEntity,
'IMG_123',
'jpg',
);
} 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}`);
}
}
@ -158,6 +158,9 @@ export class StorageService {
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 dateTokens = [
@ -173,6 +176,10 @@ export class StorageService {
substitutions[token] = dt.toFormat(token);
}
// Support file type token
substitutions.filetype = fileType;
substitutions.filetypefull = fileTypeFull;
return template(substitutions);
}

View File

@ -56,8 +56,10 @@
});
const substitutions: Record<string, string> = {
filename: 'IMG_10041123',
ext: 'jpeg'
filename: 'IMAGE_56437',
ext: 'jpeg',
filetype: 'IMG',
filetypefull: 'IMAGE'
};
const dt = luxon.DateTime.fromISO(new Date('2022-09-04T20:03:05.250').toISOString());

View File

@ -17,5 +17,13 @@
<li>{`{{ext}}`}</li>
</ul>
</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>