feat(server): normalize extensions in storage template (#16667)

* normalize and lowercase extensions

* un const

* do not change ext before stripping off old one

* braces
This commit is contained in:
Matthew Momjian 2025-03-06 18:02:28 -05:00 committed by GitHub
parent feb65bf5a7
commit 5c82c485d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 30 additions and 3 deletions

View File

@ -240,7 +240,7 @@
"storage_template_hash_verification_enabled_description": "Enables hash verification, don't disable this unless you're certain of the implications",
"storage_template_migration": "Storage template migration",
"storage_template_migration_description": "Apply the current <link>{template}</link> to previously uploaded assets",
"storage_template_migration_info": "Template changes will only apply to new assets. To retroactively apply the template to previously uploaded assets, run the <link>{job}</link>.",
"storage_template_migration_info": "The storage template will convert all extensions to lowercase. Template changes will only apply to new assets. To retroactively apply the template to previously uploaded assets, run the <link>{job}</link>.",
"storage_template_migration_job": "Storage Template Migration Job",
"storage_template_more_details": "For more details about this feature, refer to the <template-link>Storage Template</template-link> and its <implications-link>implications</implications-link>",
"storage_template_onboarding_description": "When enabled, this feature will auto-organize files based on a user-defined template. Due to stability issues the feature has been turned off by default. For more information, please see the <link>documentation</link>.",

View File

@ -105,7 +105,7 @@ describe(StorageTemplateService.name, () => {
it('should migrate single moving picture', async () => {
mocks.user.get.mockResolvedValue(userStub.user1);
const newMotionPicturePath = `upload/library/${userStub.user1.id}/2022/2022-06-19/${assetStub.livePhotoStillAsset.id}.mp4`;
const newStillPicturePath = `upload/library/${userStub.user1.id}/2022/2022-06-19/${assetStub.livePhotoStillAsset.id}.jpeg`;
const newStillPicturePath = `upload/library/${userStub.user1.id}/2022/2022-06-19/${assetStub.livePhotoStillAsset.id}.jpg`;
mocks.asset.getByIds.mockImplementation((ids) => {
const assets = [assetStub.livePhotoStillAsset, assetStub.livePhotoMotionAsset];

View File

@ -226,10 +226,37 @@ export class StorageTemplateService extends BaseService {
try {
const source = asset.originalPath;
const extension = path.extname(source).split('.').pop() as string;
let extension = path.extname(source).split('.').pop() as string;
const sanitized = sanitize(path.basename(filename, `.${extension}`));
extension = extension?.toLowerCase();
const rootPath = StorageCore.getLibraryFolder({ id: asset.ownerId, storageLabel });
switch (extension) {
case 'jpeg':
case 'jpe': {
extension = 'jpg';
break;
}
case 'tif': {
extension = 'tiff';
break;
}
case '3gpp': {
extension = '3gp';
break;
}
case 'mpeg':
case 'mpe': {
extension = 'mpg';
break;
}
case 'm2ts':
case 'm2t': {
extension = 'mts';
break;
}
}
let albumName = null;
if (this.template.needsAlbum) {
const albums = await this.albumRepository.getByAssetId(asset.ownerId, asset.id);