mirror of
				https://github.com/immich-app/immich.git
				synced 2025-11-04 03:39:37 -05:00 
			
		
		
		
	* Fix isImmichPath * prettier write * Fis isImmichPath code comment * Refactor isImmichPath function based on team suggestions * Test isImmichPath * fix: clean comments * Refactor isImmichPath test based on team suggestions * Clean code with lintern suggestions
This commit is contained in:
		
							parent
							
								
									34cbb18ecd
								
							
						
					
					
						commit
						6a4bc777a2
					
				
							
								
								
									
										29
									
								
								server/src/cores/storage.core.spec.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								server/src/cores/storage.core.spec.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,29 @@
 | 
				
			|||||||
 | 
					import { StorageCore } from 'src/cores/storage.core';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					jest.mock('src/constants', () => ({
 | 
				
			||||||
 | 
					  APP_MEDIA_LOCATION: '/photos',
 | 
				
			||||||
 | 
					}));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					describe('StorageCore', () => {
 | 
				
			||||||
 | 
					  describe('isImmichPath', () => {
 | 
				
			||||||
 | 
					    it('should return true for APP_MEDIA_LOCATION path', () => {
 | 
				
			||||||
 | 
					      const immichPath = '/photos';
 | 
				
			||||||
 | 
					      expect(StorageCore.isImmichPath(immichPath)).toBe(true);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('should return true for paths within the APP_MEDIA_LOCATION', () => {
 | 
				
			||||||
 | 
					      const immichPath = '/photos/new/';
 | 
				
			||||||
 | 
					      expect(StorageCore.isImmichPath(immichPath)).toBe(true);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('should return false for paths outside the APP_MEDIA_LOCATION and same starts', () => {
 | 
				
			||||||
 | 
					      const nonImmichPath = '/photos_new';
 | 
				
			||||||
 | 
					      expect(StorageCore.isImmichPath(nonImmichPath)).toBe(false);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('should return false for paths outside the APP_MEDIA_LOCATION', () => {
 | 
				
			||||||
 | 
					      const nonImmichPath = '/some/other/path';
 | 
				
			||||||
 | 
					      expect(StorageCore.isImmichPath(nonImmichPath)).toBe(false);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
 | 
					});
 | 
				
			||||||
@ -115,7 +115,13 @@ export class StorageCore {
 | 
				
			|||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static isImmichPath(path: string) {
 | 
					  static isImmichPath(path: string) {
 | 
				
			||||||
    return resolve(path).startsWith(resolve(APP_MEDIA_LOCATION));
 | 
					    const resolvedPath = resolve(path);
 | 
				
			||||||
 | 
					    const resolvedAppMediaLocation = resolve(APP_MEDIA_LOCATION);
 | 
				
			||||||
 | 
					    const normalizedPath = resolvedPath.endsWith('/') ? resolvedPath : resolvedPath + '/';
 | 
				
			||||||
 | 
					    const normalizedAppMediaLocation = resolvedAppMediaLocation.endsWith('/')
 | 
				
			||||||
 | 
					      ? resolvedAppMediaLocation
 | 
				
			||||||
 | 
					      : resolvedAppMediaLocation + '/';
 | 
				
			||||||
 | 
					    return normalizedPath.startsWith(normalizedAppMediaLocation);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  static isGeneratedAsset(path: string) {
 | 
					  static isGeneratedAsset(path: string) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user