diff --git a/server/libs/domain/src/server-info/server-info.service.spec.ts b/server/libs/domain/src/server-info/server-info.service.spec.ts index 10afd539eb..f030a63a13 100644 --- a/server/libs/domain/src/server-info/server-info.service.spec.ts +++ b/server/libs/domain/src/server-info/server-info.service.spec.ts @@ -34,7 +34,7 @@ describe(ServerInfoService.name, () => { diskUseRaw: 300, }); - expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('./upload'); + expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library'); }); it('should return the disk space as KiB', async () => { @@ -50,7 +50,7 @@ describe(ServerInfoService.name, () => { diskUseRaw: 300000, }); - expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('./upload'); + expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library'); }); it('should return the disk space as MiB', async () => { @@ -66,7 +66,7 @@ describe(ServerInfoService.name, () => { diskUseRaw: 300000000, }); - expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('./upload'); + expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library'); }); it('should return the disk space as GiB', async () => { @@ -86,7 +86,7 @@ describe(ServerInfoService.name, () => { diskUseRaw: 300000000000, }); - expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('./upload'); + expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library'); }); it('should return the disk space as TiB', async () => { @@ -106,7 +106,7 @@ describe(ServerInfoService.name, () => { diskUseRaw: 300000000000000, }); - expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('./upload'); + expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library'); }); it('should return the disk space as PiB', async () => { @@ -126,7 +126,7 @@ describe(ServerInfoService.name, () => { diskUseRaw: 300000000000000000, }); - expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('./upload'); + expect(storageMock.checkDiskUsage).toHaveBeenCalledWith('upload/library'); }); }); diff --git a/server/libs/domain/src/server-info/server-info.service.ts b/server/libs/domain/src/server-info/server-info.service.ts index 5e49668204..9d36f1b66d 100644 --- a/server/libs/domain/src/server-info/server-info.service.ts +++ b/server/libs/domain/src/server-info/server-info.service.ts @@ -1,19 +1,22 @@ import { Inject, Injectable } from '@nestjs/common'; -import { APP_MEDIA_LOCATION, serverVersion } from '../domain.constant'; +import { serverVersion } from '../domain.constant'; import { asHumanReadable } from '../domain.util'; -import { IStorageRepository } from '../storage'; +import { IStorageRepository, StorageCore, StorageFolder } from '../storage'; import { IUserRepository, UserStatsQueryResponse } from '../user'; import { ServerInfoResponseDto, ServerPingResponse, ServerStatsResponseDto, UsageByUserDto } from './response-dto'; @Injectable() export class ServerInfoService { + private storageCore = new StorageCore(); + constructor( @Inject(IUserRepository) private userRepository: IUserRepository, @Inject(IStorageRepository) private storageRepository: IStorageRepository, ) {} async getInfo(): Promise { - const diskInfo = await this.storageRepository.checkDiskUsage(APP_MEDIA_LOCATION); + const libraryBase = this.storageCore.getBaseFolder(StorageFolder.LIBRARY); + const diskInfo = await this.storageRepository.checkDiskUsage(libraryBase); const usagePercentage = (((diskInfo.total - diskInfo.free) / diskInfo.total) * 100).toFixed(2); diff --git a/server/libs/domain/src/storage/storage.core.ts b/server/libs/domain/src/storage/storage.core.ts index a5d66f1b8e..ef90d433c0 100644 --- a/server/libs/domain/src/storage/storage.core.ts +++ b/server/libs/domain/src/storage/storage.core.ts @@ -14,10 +14,14 @@ export class StorageCore { folder: StorageFolder.ENCODED_VIDEO | StorageFolder.UPLOAD | StorageFolder.PROFILE | StorageFolder.THUMBNAILS, userId: string, ) { - return join(APP_MEDIA_LOCATION, folder, userId); + return join(this.getBaseFolder(folder), userId); } getLibraryFolder(user: { storageLabel: string | null; id: string }) { - return join(APP_MEDIA_LOCATION, StorageFolder.LIBRARY, user.storageLabel || user.id); + return join(this.getBaseFolder(StorageFolder.LIBRARY), user.storageLabel || user.id); + } + + getBaseFolder(folder: StorageFolder) { + return join(APP_MEDIA_LOCATION, folder); } }