mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat: change default media location to /data (#20367)
* feat!: change default media location to /data * feat: dynamically detect media location
This commit is contained in:
parent
4cae15f28d
commit
58521c9efb
39 changed files with 316 additions and 209 deletions
|
|
@ -2,7 +2,6 @@ import { StorageCore } from 'src/cores/storage.core';
|
|||
import { vitest } from 'vitest';
|
||||
|
||||
vitest.mock('src/constants', () => ({
|
||||
APP_MEDIA_LOCATION: '/photos',
|
||||
ADDED_IN_PREFIX: 'This property was added in ',
|
||||
DEPRECATED_IN_PREFIX: 'This property was deprecated in ',
|
||||
IWorker: 'IWorker',
|
||||
|
|
@ -10,6 +9,10 @@ vitest.mock('src/constants', () => ({
|
|||
|
||||
describe('StorageCore', () => {
|
||||
describe('isImmichPath', () => {
|
||||
beforeAll(() => {
|
||||
StorageCore.setMediaLocation('/photos');
|
||||
});
|
||||
|
||||
it('should return true for APP_MEDIA_LOCATION path', () => {
|
||||
const immichPath = '/photos';
|
||||
expect(StorageCore.isImmichPath(immichPath)).toBe(true);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
import { randomUUID } from 'node:crypto';
|
||||
import { dirname, join, resolve } from 'node:path';
|
||||
import { APP_MEDIA_LOCATION } from 'src/constants';
|
||||
import { StorageAsset } from 'src/database';
|
||||
import { AssetFileType, AssetPathType, ImageFormat, PathType, PersonPathType, StorageFolder } from 'src/enum';
|
||||
import { AssetRepository } from 'src/repositories/asset.repository';
|
||||
|
|
@ -32,6 +31,8 @@ export type ThumbnailPathEntity = { id: string; ownerId: string };
|
|||
|
||||
let instance: StorageCore | null;
|
||||
|
||||
let mediaLocation: string | undefined;
|
||||
|
||||
export class StorageCore {
|
||||
private constructor(
|
||||
private assetRepository: AssetRepository,
|
||||
|
|
@ -74,6 +75,18 @@ export class StorageCore {
|
|||
instance = null;
|
||||
}
|
||||
|
||||
static getMediaLocation(): string {
|
||||
if (mediaLocation === undefined) {
|
||||
throw new Error('Media location is not set.');
|
||||
}
|
||||
|
||||
return mediaLocation;
|
||||
}
|
||||
|
||||
static setMediaLocation(location: string) {
|
||||
mediaLocation = location;
|
||||
}
|
||||
|
||||
static getFolderLocation(folder: StorageFolder, userId: string) {
|
||||
return join(StorageCore.getBaseFolder(folder), userId);
|
||||
}
|
||||
|
|
@ -83,7 +96,7 @@ export class StorageCore {
|
|||
}
|
||||
|
||||
static getBaseFolder(folder: StorageFolder) {
|
||||
return join(APP_MEDIA_LOCATION, folder);
|
||||
return join(StorageCore.getMediaLocation(), folder);
|
||||
}
|
||||
|
||||
static getPersonThumbnailPath(person: ThumbnailPathEntity) {
|
||||
|
|
@ -108,7 +121,7 @@ export class StorageCore {
|
|||
|
||||
static isImmichPath(path: string) {
|
||||
const resolvedPath = resolve(path);
|
||||
const resolvedAppMediaLocation = resolve(APP_MEDIA_LOCATION);
|
||||
const resolvedAppMediaLocation = StorageCore.getMediaLocation();
|
||||
const normalizedPath = resolvedPath.endsWith('/') ? resolvedPath : resolvedPath + '/';
|
||||
const normalizedAppMediaLocation = resolvedAppMediaLocation.endsWith('/')
|
||||
? resolvedAppMediaLocation
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue